Posts

Showing posts from August, 2013

如何用 python 撰寫其他語言的 parser, analyzer, indexer, annotator ?

Image
今天早上在 PTT 看到這篇文章, 挺有意思的, 這裡記錄一下. 雖然原 po 僅是要 parsing #IF #ELSEIF 這類的 marcos, 但這應該是指 lex-yacc 的parsing tools 吧! 查了一下, 若是針對 c code, 其實用 GNU GCC/ or Clang/LLVM 就可以列出了. ( 參考 ) 另外針對 clang  的 python api 也是 (參考 clang-python-binding ) 若是要用原生的 python 來做成, 大多是使用 PLY 的 parser, 像是 pycparser 或 minicparser . BTW, 另外也看到個問題是: 透過USB線相接的電腦 - 電視,  如何將電腦的滑鼠行為呈現在電視上? (用想的) 這問題似乎有幾個難度: 1) 電視將 USB 輸入端(電腦輸出) 視為滑鼠? 還是 2) 電視跟電腦端各有個程式透過 USB 在做通訊模擬滑鼠? 嗯嗯, 先這樣. 繼續跟 NS2 奮戰去... Orz

NS2 在WINDOWS上遇到的些小問題

今天總算有時間回頭來跑模擬了, 雖然系統都寫完了才來跑數據.... anyway, 下午到 lab 裝了一下 ns 2.34 (Debian 4.3.5) 與 ns 2.28 (windows 7/cygwin), debian 上安裝完全沒有問題, 但 Cygwin 上一直出現不同的錯誤, 最後我就放棄了. I hate Cygwin ... 這裡紀錄一下常遇到的錯誤. TCL 部分 [1] wrong # args: should be "proc name args body" [2] extra characters after close-brace 主要都是排版問題, 標準排版如下: proc PROCNAME {arg1 arg2} {    ...    ...    ... } ; 另外就是 x11 forwarding,  需要注意: 1) sshd  x11 forwarding 設定    => 修改 ssh.conf 2) putty x11 forwarding enable   => :> echo $DISPLAY 3) xming server 啟動

關於 heroku 在 windows 上的部署

其實之前就做過了, 只是沒能留下筆記, 只好再把流程紀錄一遍. (怎感覺自己一直再重複作業 n 把事情搞複雜... Orz) *另外用 heroku 的主要考量還是想先試試水溫 (也是沒有錢 Orz), 待有固定收入再搬到 linode 好了 [目標] 在 heroku 上部屬 python web application [參考]  https://devcenter.heroku.com/articles/python [需要工具] 1. python (v2.7) 2. pip, Virtualenv, flask 3. heroku account, heroku client application [這裡略過] [ Local workstation setup -- Windows ] 0.1. python 2.7 ( 官網 ) 0.2. pip 的安裝需要 setuptools 跟 pip 的同時安裝, 這裡有佛心 執行檔 連結. 0.3. Virtualenv 的安裝直接下 :> pip install virtualenv 即可. 0.4. VIRTUAL_ENV = 'virtual_env27' 建立 folder :> mkdir VIRTUAL_ENV 建立 virtual environment :> virtualenv VIRTUAL_ENV 0.5. 安裝framework flask, 直接下 :> pip install flask 即可. 0.6. 建立 放至專案的 folder :> cd VIRTUAL_ENV ; :> mkdir Projects ; :> cd Projects 1.0. 建立 第一個專案 helloheroku folder :> mkdir helloheroku ; :> cd helloheroku 1.1. 建立 第一支 flask 程式 app.py, 參考 flask 官網 1.2. 利用 heroku 提供的兩個工具 Procfile 與 foreman 作 local testing Procfile 內文: web: python app.py 執行

お寺や神社では神が質問するのを聞けます。

大家去過廟宇沒有?台灣人通常會到廟裡供奉牲品並祈求平安。廟裡通常都設有籤筒、為了解答人們心中的疑惑。另外、為了避免不能理解的場合、也會有專門的人講解籤中的意思。 皆さんは台湾のお寺や神社へ行ったことがありますか?台湾人はよくお菓子と果物と買いて、お寺を行きます。裏には心から神に話すの人とか、旅行する人とか、お寺の社員などとたくさんいます。しかし、心の中から問題をあれば、答えの木の桶がたくさん掛かっているのを見えると、神からもらった番号を探すと、答えのペーパーを取ります。また、自分に心配すれば、隣のお寺の社員に質問するようにしていますよね。台湾や日本やはかにもいろいろなお願い事の習慣があるんですね。

samba public share

時常會忘記一些設定方式,希望這次最後一次紀錄關於 samba  =_=||| samba 主要是 unix-like 平台透過 NFS 共享資源的一個服務器,在 WINDOWS 叫 CIFS。( Mac上也有自己協定就是) [ 安裝 ] >> sudo apt-get install samba samba-common-bin samba: 主程式 samba-common-bin: 提供 smbpasswd 等工具 [ 路徑 in RSPI ] Binary: /usr/bin/ Config:/ /etc/samba/ shell script: /etc/init.d/samba [ config ] [PATH_NAME]    comment = All Users    path = /YOUR/SHARED/PATH    valid users = SMB_USER_NAME    guest ok = no    read only = no    writeable = yes [ admin ] > smbpasswd -a [USER] [ Note ]   1) smb.config 上的 valid user 與 system user 不同, 需要另外新增並設置密碼.

10 rags-to-riches stories of all time

[ 原文 ] They say when life gives you lemons, make lemonade. These inspiring figures had less than a lemon to start out with – and are now known for their sheer tenacity as they climbed to the top. MensXP brings you the top 10 rags-to-riches success stories of all time. "When life gives you lemons, make lemonade!" 一開頭就用了句諺語,但 lemon 是指生活上的挫折,這句原意是鼓勵人們用樂觀的態度面對挫折。不過作者衍伸為這些人一開始甚至連做 lemonade 的 lemon 都沒有的白手起家,由於他們的不屈不撓而成就一番事業。 sheer - 純粹的、全面的 tenacity - 堅毅、不屈不撓 by the sheer force of one's will  完全憑靠意志(力) by the sheer force of expertise  完全憑靠專業知識(力) by the sheer force of tenacity 完全憑靠堅毅(力) 10. Chris Gardner This is the man whose life has inspired the Will Smith-starrer ‘The Pursuit of Happyness’. Physically abused by his  stepfather as a child and placed in a foster home, Gardner’s woes did not leave him even as he grew up to marry and be a father. As shown in the movie, Gardner struggled with homelessness while raising his kid. It was the strength of the lessons h

Association rule mining (2)

[*** 以下為個人理解,如有錯誤歡迎指證 ***] [***This article may contain mistakes and thus any correction is greatly appreciated***] 這裡補充一下關於 association rule mining 的一些知識。 association rule mining (以下簡稱ARM),又叫關聯規則挖掘,目的為發現當某個 item A  的出現,也會引發另一個 item B 的出現,我們稱為 A => B 為一個 association rule。 ARM 中定義了幾個條件: (1) Support:該 AR 在 databases中涵蓋的資料數目。 (2) Confidence : 該AR的預測強度。 (3) Frequent itemsets : 又稱作 large itemsets,為T中涵蓋的資料數目大於minimum support  的 itemsets。 任何滿足 minimum support 與 minimum confidence 的 rule,才能稱作 AR。 [--- AR 又可以分為三類 --- ] (1) 根據 attribute 分類 : item 有無、item數量。 Boolean AR: 關注item是否出現,如『bear =>biscuits (support=15%, confidence=80%)』 中找到的 bear 與 biscuits。 Quantitative AR: 關注 item 某個範圍下的結果,如 『age(t, "40...45") ^ income(t, "7w...10w") => insurance(x, cancer insurance)』中,從age 20~30且購買bear 3~8瓶的消費者中找到 member 的 rule。 (2) 根據 dimension 分類 : Single dimension AR: 如 『bear => biscuits』,皆為購買行為。 multi-dimensional AR: 『age(t, "40...45") ^ income(t, &

deterministic VS non-deterministic algorithm

[*** 以下為個人理解,如有錯誤歡迎指證 ***] [*** This article may contain mistakes and thus any correction is greatly appreciated ***] 今天在複習 apriori algorithm 時,由於書上說 association rule mining 的結果是唯一性的,讓我想到個問題:這個演算法是 deterministic 還是 non-deterministic ? 唯一性的直覺是 deterministic,只是當下無法說出 deterministic、non-deterministic、NP的定義,所以趕緊來複習一下。(慚愧...) [non- deterministic] (1) an algorithm exhibits different behaviors in different runs. (2) WIKI 的例子:若用從 1 input 到 1 outcome 的 1 1path 表示 deterministic algo.,則 non-deterministic algo. 表示 1 input 到 N outcomes 的 M paths 的其中一條. (3) 在 computational theory 中,我們所講的 algorithms 大多都是屬於 deterministic algo.。 (4) 似乎一些研究都是透過 deterministic algo 加上一些手法 ex. approximation、probabilistic random 來解決現實中 non-deterministic 的問題。 [NP] non-deterministic and polynomial *記得P = NP 問題已經在前一年被 Stamford 的學生證明了。 [參考] 1. wiki