2014年9月27日 星期六

活動:Tainan.py x MOSUT x FP 2014 9 月聚會

會眾正在專心聽 wen 分享!


淺談 Debian 套件打包

講者為好久不見的  wen
wen 透過分享自己嘗試打包的經驗,想要吊出 hychen 過來蒞臨指導 XD
不過很可惜 hychen 有事情沒有到場 Orz






C & CPU

講者為現居台北特地過來分享的 fea
這場分享的強度 ... 呃 ... 非常非常的強大(本魯已陣亡)
硬派男子漢請自取(誠如 fea 所言,其實某些角度來講這算軟)





OO x Python

標題詐欺!講者是我!
內容其實是講一點點你很有可能沒聽過的 OO 的故事,以及工商服務 Python





另外由於此次聚會是第一次  x FP
所以演講過程我有提到一些有趣的資料(但是我講得不有趣 Orz)

On the criteria to be used in decomposing systems into modules
重量級歷史名作,不單對 OO ,對 FP 也有重大影響

Why Functional Programming Matters (中文翻譯)
從未真正學習過 FP 的我,看完這篇才覺得有入門的感覺

The Early History of Smalltalk
對 OO 歷史有興趣可以一讀,讀完請至 MOSUT 社群分享
以下為摘錄的一小段話:

For the first time I thought of the whole as the entire computer and wondered why anyone would want to divide it up into weaker things called data structures and procedures.Why not divide it up into little computers, as time sharing was starting to? But not in dozens. Why not thousands of them, each simulating a useful structure?

我本來很想對 FP 能有摘要性的介紹,無奈對其道行實在太淺
後來仔細想想,本次聚會我連對 OO 摘要性的介紹都做不到
只能挖出一點歷史,看能不能讓大家想想 OO 在幹嘛 ....
等等,我認識台南有在寫 FP 的 hychen / sam 怎麼都沒有來 XD?

SICP Metacircular Evaluator

- 用 scheme 來寫出一個 scheme


講者為超久不見的 descent
近期他正在研究 SICP,寫了一系列的文章放在他的 部落格 上
由於時間有限,本次聚會他只有講完 part1...


對 SICP 課程有興趣可到此 MIT OCW 的 網頁 瞧瞧


工商服務

- 自由軟體開發與社群發展

本次聚會成大資工的楊老師亦到場參加
並且宣傳了他在系上開設的課程


成大有這個課真好啊~



事實上,這次聚會前一天
我心甘情願地到該課程去介紹 MOSUT 與 Tainan.py 的聚會
呃 ... 如果您是在學學生,不妨可以瞧瞧這份投影片












2014年8月28日 星期四

活動:Taipei.py 2014 8 月聚會

自由交流時間
對!您沒看錯,Taipei.py 的聚會場地有三螢幕投影


恰巧路過台北幾天,於是便興高采烈地參加 Taipei.py 的活動
竟然還看到 kuku 也剛好路過,非常有 Tainan.py 的感覺 XD


把 R 和 Python 串起來

講者今年四月其實也有到台南推廣 R 語言!
大致上這是一場 Py 皮 R 骨,大量運用 C++ 的技術分享 XDDD

講者:Wush Wu



TimSort

是的!講者是高中生,講的是 TimSort
這也是 python & java 有使用到的 sorting algorithm

講者:rilak 投影片

補充:wiki 、 作者自己的介紹



SPA with Python Django and CoffeeScript

講者為 KELP,本場演講主要是介紹實作簡易 error report server 時用到的技術堆疊
話說當講者 Live Demo 打開編輯器時,我差點跪下了  Orz

Photo from Taipei.py
其實書寫體真的比較好看,可是對於英文閱讀苦手的我來說,看到會哭 ...
另外,對齊也的確是問題 ...
補充:這是講者的 github 專案


pytest 還有他的快樂夥伴

講者是  ... 我





原本只想快點帶過,結果多嘴講了 30 分鐘  XDDD


補充:如果想了解更多 pytest 可以參考 這篇文章

2014年8月23日 星期六

活動:Tainan.py x MOSUT 2014 8 月聚會

會眾非常開心的參與這次的活動!


近幾次 Tainan.py x MOSUT 聚會參加人數皆達 30 人以上
本月聚會則因上午 jserv 糾團,晚上又剛好是若渴計畫
您若全程參與,則將達成 12+ hours 的技術聚會饗宴(特訓)



GNU Radio

為了紀念(?)823 砲戰,此次講者 Albert Huang 特地南下
演講內容由淺入深,會眾亦積極參與,發問不斷電 ...
(事實上,後來 Sam 在演講時也有向 Albert 發問 XDDD)


reactjs

為了參加大食團,此次講者 Ly 路過台南
向各位介紹了 facebook 的 open source project: reactjs
身為很久以前曾寫過很爛的 angularjs 的後端魯蛇
我只能說 reactjs 真是有意思!

觀看投影片
補充:virtual dom


在物聯網跟穿戴式裝置正夯的時代,身為App Developer不能不了解的BLE

為了研究創業,此次講者 Sam 住在台南
向大家進行一個很全面的演講, 從技術堆疊、相關應用到 Live demo 所有願望一次滿足!



淺入淺出 pytest 還有他的快樂夥伴們

為了有更多 Python 的講題,此次我自投題目 Orz
pytest 是我個人認為較為 pythonic 的 testing framework
由於易理解且容易上手,能讓寫 testing 的門檻降低許多 ...


本「向大師學習系列」投影片使用 Prezi 製作

補充:
本次 Tainan.py 後,我恰好路過 Taipei.py
有對此講題重做一次介紹, 錄影在此 (約 30 分)



2014年7月31日 星期四

筆記:小型 Web Crawler/Automator 個人工具箱

許多 (browser) automation 的工具都用「鬼」命名 XDDDD
phantomjs, slimerjs, casperjs, ghost.py ...
圖片來自:手滑背單字 的懶惰鬼


#以下為我撰寫小型 web crawler / automator 時常使用的工具與思路


觀察 & 分析

釐清要什麼以後,宜先人工操作網頁,並透過以下方式進行初步觀察:
  • chrome 開發人員工具 => network => 勾選 preserve log => 進行操作
    • 觀察 http 封包的發送
  • chrome 開發人員工具 => 點選左上角搜尋圖示 => 直接點擊欲觀察的網頁元素
    • 在該網頁元素的程式碼部分,可以使用右鍵直接取得 xpath / csspath 的資訊
  • 使用 visual event 觀察頁面上 javascript event 與 UI 的 binding 情況


個人工具箱

我慣用的工具有:(程式執行成本由低到高)
  • requests 函式庫,從 http 的層級解決問題
    • 執行效率最佳
    • 雖然位於底層,但最後不一定會是最繁雜的 solution
      • 可無視許多 application UI 的操作邏輯
    • 若上層的 application 過於複雜,會難以找出合法 http request 的格式
      • 要處理的參數過多會導致需要花費很多時間測試
      • 參數值越依賴 application  的運算,越難生成
      • 隨著頁面跳轉、ajax 呼叫 ... 複雜度會上升
      • 需要自行維持  headers / cookies 的值 ... 手動模仿部分瀏覽器行為
  • mechanize / twill / mechanicalSoup 之類的函式庫,用精簡版的瀏覽器解決問題
    • 執行效率次佳
    • 部分瀏覽器的功能已經被實作,能帶來很大的方便
      • 但是不能執行 javascript ,使得適用範圍小很多
    • 函式庫會附帶一些便捷的 API ,協助填寫表單、點擊連結 ...
    • 適合拿來跑簡單的 functional testing
      • 至少可以不用擔心如何維持瀏覽器的狀態
      • 拿來測 API 也並無不可
  • 使用 phantomjs 等等內嵌 webkit 的工具,透過無視窗介面的瀏覽器解決問題
    • 執行效率欠佳
    • 能執行 javascript ,可高度模擬使用真實瀏覽器的情境
    • 有廣大的社群以此為基礎,開發相關的 testing / automation ... tools
      • casperjs 是高階,極為好用的封裝
        • resurrectio 提供了 chrome plugin,可以人工錄製欲自動化的步驟以後,自動生成以 casperjs 寫的測試程式碼
          • 還在開發初期,頗有機會測試程式碼會出錯,需要人工修改
      • ghost.py 是 python 版本仿 casperjs 的函式庫
        • 依賴 pySlide or pyQT ... 安裝得花功夫
        • 能夠使用的 API 仍比 casperjs 少很多,文件亦不足
        • 優點為:使用 python 寫出的程式碼架構,可讀性比 js 版本高非常多
  • 使用 selenium 驅動瀏覽器,直接人工錄製欲自動化的步驟或進而匯出程式碼
    • 執行效率欠佳,且大都需要視窗環境
      • 驅動真實瀏覽器時,會顯示出視窗,好處是較容易除錯
      • 亦可驅動以 phantomjs 為核心的 ghostdriver,不需顯示出視窗
    • Selenium 的 Python 及各語言 binding,能夠讓開發者在習慣的環境下開發程式
    • 直接使用錄製功能時,記錄下來的動作不一定具備正確重現性
      • 亦即播放時仍可能出錯


使用策略、心得

對於簡單的網頁,特別是無須登入那種,requests 可以說是最佳解
甚至直接使用 pyquery 就能快速完成 crawling + parsing 的工作

但是對於較複雜的網頁,常常會陷入 requests vs. casperjs 的抉擇
當評估用 requests 實作要太多時間,而能接受較慢的執行速度時
casperjs 算是一個比較快速的解法

換言之,以下可能是不錯的使用策略:
  • 需要執行頻率高的 crawling 時,推薦用 requests 
  • 需要執行頻率低或有複雜 application 操作的 automation 時,推薦用 casperjs


實務上,要使用 requests 自幹時
千萬記得到 google / github 找找看有沒有人有做過同樣的事情
即便語言不同,只要能夠看懂 http 相關的操作
也很容易可以寫出自己的版本


反之,即便要走 casperjs 路線
也並不代表會一路順遂,因為仍然有一定的學習成本
  • 高階的 resurrectio 能夠自動產生 casperjs  的  code ,但是不一定 work
  • casperjs 有乍看醜醜,但是其實蠻完善的文件(建議讀完他)
  • 分享幾個使用上的經驗:
    • 網頁會有 popup 視窗的行為,要特別注意
    • 使用 evaluate API 之前,盡可能看看其他 API 是否有提供包好的功能
    • 可以關掉讀取圖片的功能,大幅加速程式速度
    • 我個人會透過擷取圖片功能,事後看各個步驟的執行結果

原本我以為若使用casperjs ,就可以在幾個小時之內馬上完成工作
結果一邊撞 javascript / casperjs 的牆,一邊讀文件後
最後還是花費了超過一天才完成工作 ...
當然,熟悉這個工具以後,會認為付出是划算的


歡迎補完

本文沒有探討 parsing 或是  crawling 的深入議題,僅只是介紹寫寫小 scripts 時的工具
若有朋友知道有什麼好物,請推薦給我啊啊啊!





2014年7月26日 星期六

活動:Tainan.py x MOSUT 2014 7 月聚會



Tainan.py x MOSUT 2014 7 月聚會 - kuku

Tainan.py x MOSUT 2014 7 月聚會 - jserv



因為走錯路而遲到,在緊張的心情下(人好多)
我拿出輸出 VGA 有點接觸不良的 ipad 開始了這次的聚會 ... Orz


開場:新 Logo + 把玩 supervisord + Python 報報

(此次開場試用  evernote 簡報功能,開場簡報下載)

活動開始後我先投稿做好許久,但是忘了拿出來的 MOSUT Logo ...
原圖下載 (svg)designed by nao


接著怕整場活動 Python 太少
所以快速介紹一下一個用 python 寫的好用程序管理工具:supervisord
接下來我進行簡短的 Python 工商服務後,就是講者的分享時間了!



跟大師學習:講講瀏覽器渲染 - 當內容遇上裝置



等等,第一位上場的講者難道不是 kuku 嗎?
怎麼投影片是第二位講者 jim Huang (jserv) 的?


是的,這就是 kuku 的「跟大師學習」系列演講,詳情請見下圖:

圖片來自 仁傑

以下為 Isrlab 對當天分享的補充:
昨天 Tainan.py X MOSUT,我們分享了最近研究的課題,主標題是 "向大師學習 - 講講瀏覽器渲染",副標題是 "當數位內容遇上裝置"。
這是一個有趣的年代,數位內容的生產者必須多方考慮眾多裝置差異及各家瀏覽器的渲染能力,我們正在嘗試幫數位內容的開發工具,加一些獨家功能,像是 Flash 編譯器的修改;也考慮深度挖掘瀏覽器的優化可能性,像是 Firefox Gecko 層的擴展。
分享給前端工程師,瀏覽器工程師,系統工程師。

kuku 使用的第二份投影片:Rendering Performance Case Studies (強力推薦一看)



一定會扯到 Python 的「情感運算學習網」上線

第二位講者小均這次為我們介紹 情感運算學習網
並且 demo 一個 辨識情感的小程式 (by python)
( jserv 已玩過改過,且說明其辨識能力不佳)


身為「我要征服台南牛肉湯」的作者,小均「順便」分享一下最近做的研究:

點此觀看研究報告
偷渡一下牛肉湯回報:
民生路那間無名牛肉湯,老闆每天都是自己到善化屠宰場選肉再拿回店面 ... 推!


Build A Lightweight Hypervisor for Realtime Linux

伴隨著隔壁在換招牌的陣陣轟聲
jserv 帥(爆)氣登場,為我們介紹 realtime linux:




工商服務


PyConAPAC 後,各地 Python 社群蓬勃揪團,依開台順序排序:


More info: 


Python 台灣使用者群組 


Or


Python Taiwan @ Facebook 
https://www.facebook.com/groups/pythontw/




筆記:把玩 supervisord


本文是從 evernote 筆記中轉存出來的文章,分享於 Tainan.py x MOSUT 2014.07 




# 看完了 wen 分享的文章以後 …




# 也來試看看用 python 寫的 [老字號] supervisor 吧 (推薦用來管理自己的 process)






# 安裝(盡量在 virtualenv 之外裝) 
pip install supervisor --pre


# 建立 config sample file

echo_supervisord_conf  >  /etc/supervisord.conf


# 修改 config file

[program:foo]
command=/bin/cat


# 建議啟動時讀取自己的 config file

supervisord -c supervisord.conf


# 使用 supervisorctl 來管理自己的 process (使用範例)

[tainanpy etc]$ supervisorctl

backup                           RUNNING    pid 26703, uptime 26 days, 18:18:33
main                               RUNNING    pid 26702, uptime 26 days, 18:18:33
sentry-web                    RUNNING    pid 26701, uptime 26 days, 18:18:33



supervisor> ?

default commands (type help <topic>):
=====================================
add    clear  fg        open  quit    remove  restart   start   stop  update
avail  exit   maintail  pid   reload  reread  shutdown  status  tail  version



supervisor> restart sentry-web

sentry-web: stopped
sentry-web: started



supervisor> status main

main                             RUNNING    pid 26702, uptime 26 days, 18:19:42
supervisor>


# 其實啟動時可以帶很多參數,config 檔支援 *更多* 設置方式


-c FILE, --configuration=FILE
  The path to a supervisord configuration file.
-n, --nodaemon Run supervisord in the foreground.
-h, --help Show supervisord command help.
-u USER, --user=USER
  UNIX username or numeric user id. If supervisord is started as the root user, setuid to this user as soon as possible during startup.
-m OCTAL, --umask=OCTAL
  Octal number (e.g. 022) representing the umask that should be used by supervisord after it starts.
-d PATH, --directory=PATH
  When supervisord is run as a daemon, cd to this directory before daemonizing.
-l FILE, --logfile=FILE
  Filename path to use as the supervisord activity log.
-y BYTES, --logfile_maxbytes=BYTES
  Max size of the supervisord activity log file before a rotation occurs. The value is suffix-multiplied, e.g “1” is one byte, “1MB” is 1 megabyte, “1GB” is 1 gigabyte.
-y NUM, --logfile_backups=NUM
  Number of backup copies of the supervisord activity log to keep around. Each logfile will be of size logfile_maxbytes.
-e LEVEL, --loglevel=LEVEL
  The logging level at which supervisor should write to the activity log. Valid levels are trace, debug, info, warn, error, and critical.
-j FILE, --pidfile=FILE
  The filename to which supervisord should write its pid file.
-i STRING, --identifier=STRING
  Arbitrary string identifier exposed by various client UIs for this instance of supervisor.
-q PATH, --childlogdir=PATH
  A path to a directory (it must already exist) where supervisor will write its AUTO -mode child process logs.
-k, --nocleanup
  Prevent supervisord from performing cleanup (removal of old AUTO process log files) at startup.
-a NUM, --minfds=NUM
  The minimum number of file descriptors that must be available to the supervisord process before it will start successfully.
-t, --strip_ansi
  Strip ANSI escape sequences from all child log process.
-v, --version Print the supervisord version number out to stdout and exit.
--profile_options=LIST
  Comma-separated options list for profiling. Causes supervisord to run under a profiler, and output results based on the options, which is a comma-separated list of the following: cumulative, calls, callers. E.g. cumulative,callers.
--minprocs=NUM The minimum number of OS process slots that must be available to the supervisord process before it will start successfully.
supervisorctl Command-Line Options

-c, --configuration
  Configuration file path (default /etc/supervisord.conf)
-h, --help Print usage message and exit
-i, --interactive
  Start an interactive shell after executing commands
-s, --serverurl URL
  URL on which supervisord server is listening (default “http://localhost:9001”).
-u, --username Username to use for authentication with server
-p, --password Password to use for authentication with server
-r, --history-file
  Keep a readline history (if readline is available) 





autorestart
May be one of false, unexpected, or true. If false, the process will never be autorestarted. Ifunexpected, the process will be restart when the program exits with an exit code that is not one of the exit codes associated with this process’ configuration (see exitcodes). If true, the process will be unconditionally restarted when it exits, without regard to its exit code.
Default: unexpected
Required: No.
Introduced: 3.0


# 官網


Try it !


(文件 Host 在 Readthedocs <- 三月份若渴:來分享的外國朋友創辦的服務)





2014年6月28日 星期六

活動:Tainan.py x MOSUT 2014 6 月聚會

歡迎參加本月的 Tainan.py !



恰逢 wen 正在研讀 regular expression,這次聚會日期未定就收到他的投稿 XD
本演講算是 wen 的筆記與心得,投影片本身非常有參考價值


相關補充:

  • Sam 在公司內部介紹過的 regular expression 投影片
  • float 有補充 online tools,我喜歡這一個: Debuggex
  • Arnan 分享了良葛葛的文章: Regex 的強大與哀愁
  • pyMOTW 對 re 的 介紹 (很好的 cook book)
最後再補充「PythonVerbalExpressions」:(寫法可以變成下述方式)
# Create an example of how to test for correctly formed URLs
verbal_expression = VerEx()
tester = (verbal_expression.
            start_of_line().
            find('http').
            maybe('s').
            find('://').
            maybe('www.').
            anything_but(' ').
            end_of_line()
)

# Create an example URL
test_url = "https://www.google.com"

# Test if the URL is valid
if tester.match(test_url):
    print "Valid URL"

#Print the generated regex
print tester.source() # => ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$



第二場演講是 kuku 投稿的「蟒蛇大戰,Bj4」
(最近可能由於 hychen 的關係,大家講話都很 Bj4)
講題涵蓋 psyco, Unladen-swallow, PyPy, Pymoyhoa, Pyston, Numba, Nitrous, Cython, Shed-skin ...
這種題目很明顯是資深愛好者才有辦法講的 ... Orz

相關資料:
  • hackpad 上的 筆記 (來自 bj4 聚會)
  • 投影片 (待補)




本次 聚 餐會的主角




由於日前台南黑客松的活動甫結束,索性邀請參加過的朋友過來一起分享心得
我分享了「用路人小幫手x回報大改造」目前這個專案的情況如下:
  • 台南路平、路證 API
    • 暫時為關掉狀態,有持續維護開發的打算
    • 需要找人一起運用「工人智慧」完善路平專案的資料
  • 回報 API
    • 開放中,也會持續開發
  • Android App
    • 由原開發者小宋作為個人興趣的專案邊學習邊開發
    • github repo
  • iOS App
    • 徵求有興趣的開發者與我們聯絡
    • (開發者 Awei Kuo 有與我們聯絡)



Kiang 則分享了自己做的「台南市議員觀測中心」
  • http://k.olc.tw/tncc/
  • 透過視覺化/整理過資料的介面,議員的所作所為更加能夠被民眾檢視
Kiang 亦表達想要參選台南市議員的意願
意圖透過「公開透明」化的方式來參政
有興趣的朋友可以到他的 個人網站 看看!



活動最後收到智程投稿推 MOOC 學習坑的閃電秀:

好多好棒的課程?不一起學習嗎? FB 互相推坑社團


不嘴砲,在台南累積待了八年的我,不猶豫地的捐了 2k 給 Kiang
希望 Kiang 能夠達到自己給自己設立的參選門檻:20萬的捐款
(他會將捐款結餘再捐給 開放文化基金會)