2012年3月31日 星期六

python, django and mongodb 初心者參考資料

在 ubuntu 嘗試 python, django 與 mongodb 的組合建 web application

python 程式語言參考資料:
http://docs.python.org/reference/index.html#reference-index
http://docs.python.org/contents.html
http://code.google.com/intl/zh-TW/edu/languages/google-python-class/
http://pypi.python.org/pypi
http://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA

python web framework, django 參考資料:
https://docs.djangoproject.com/en/1.3/intro/tutorial01/
http://www.openfoundry.org/index.php?option=com_content&task=view&id=1330&Itemid=144
http://www.openfoundry.org/tech-column/1350
http://blog.wu-boy.com/2009/04/django-web-framework-django-%E5%88%9D%E9%9A%8E%E5%AD%B8%E7%BF%92%E5%BF%83%E5%BE%97/

https://code.djangoproject.com/wiki/UsingVimWithDjango

django-admin startproject firstproject
cd firstproject

./manage.py
列出 django 可控制參數

./manage.py startapp firstapp
產生新的 django application

修改 firstproject/settings.py 設定 database, install application,
修改 firstproject/urls.py 設定 web application url

修改 firstproject/firstapp/models.py 加入定義的 database schemas, 或
 mongoengine 的 Document,相當於 Ruby on Rails 的 model

修改 firstproject/firstapp/views.py 加入要支援的 url actions
(配合 firstproject/url.py),相當於 Ruby on Rails 的 controller

修改 firstproject/templates/*.html 顯示的 html temlate 相當於
Ruby on Rails 的 view

修改 firstproject/urls.py 加入要支援的 url regex 相當於 Ruby on Rails
的 routing 設定

firstproject/firstapp/manage.py runserver
如果沒錯誤就應該可以在預設的 http://127.0.0.1:8000/ 看到你的
django web applications

mongodb 的 python driver, mongoengine 應用在 django 的參考資料:
http://mongoengine.org/docs/v0.5/django.html

django 搭配 mongodb 的基本參考範例:
IBM developerWorks: Using MongoDB with Django

automation and deployment of django web application:
Fabric:
http://docs.fabfile.org/en/latest/index.html

http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/
提到 python-django-south (ubuntu package name of south) 可以管理
 database migrations,但仍不確定對 NoSQL schema less 的 mongodb 是否有用?


2012年3月29日 星期四

日舒 黴漿菌

如果久咳不癒”(一個月)、頓音型咳嗽,睡眠中咳到醒,發燒不退,可能是黴漿菌感染,醫生會開日舒,需要持續三到五天的服藥,另一個之前常見的抗生素是安滅菌。

耳鼻喉的上呼吸道感染如鼻竇炎、中耳炎,下呼吸道感染,如支氣管炎、肺炎則是使用安滅菌抗生素治療,可以殺的細菌有很多樣可以參考

gsk 的安滅菌 pdf 說明檔案。常見副作用是腹瀉、噁心。

2012年3月24日 星期六

Linux 支援 ARM big.LITTLE 架構的方式

摘譯 http://lwn.net/Articles/481055/

這篇文章中提出了兩種支援 ARM 新雙核架構 Coretex-A15 & Cortex-A7 的可能實作方式。原本 ARM big.LITTLE 期望達到可以使用 Coretex-A15 的高效能與 Coretex-A7 的低功耗,達到兩種市場通吃的多核 cpu cluster 系統。

Linux scheduler 原本預期的多核系統,都是假設每顆核心的工作效能相等,因此要在 Linux 支援 ARM big.LITTLE 的異質多核,勢必需要改變原有的 Linux kernel,才可能決定何時將哪一個 kernel task 交由 Coretex-A15 或 Coretex-A7 執行?以享受到 ARM big.LITTLE 的高效能與省電的雙效果。

針對 Linux 整合 ARM big.LITTLE 架構的可能性,文中提出兩種可實作方式。

第一種是 ARM 的參考實作使用了 Coretex-A15 與 Coretex-A7 的虛擬化功能,讓作業系統 ARM big.LITTLE 的多核心硬體只有一組 Coretex-A15 cluster (4 核)的虛擬核心。

對於 Linux scheduler 來說因為仍可以安全的套用多核心的硬體都是同等效能與耗電量,如此 hypervisor 可以在作業系統不知情的狀態下,將整個執行狀態從某一個 cluster suspend,再搬移到另一個 cluster resume 繼續執行。對作業系統來說差異是會發現速度的改變(看是在 big Coretex-A15 或是 LITTLE Coretex-A7 執行)。

優點是對已經支援 Coretex-A15 多核的作業系統可無痛轉換,但缺點是 hypervisor 需要多考慮 Coretex-A15 與 Coretex-A7 的 cache 等系統實作細節的差異。另一個衍生問題是每次 hypervisor 轉換 cluster 的 performance penalty 是否造成另一種資源浪費?

第二種是利用 Linux Kernel 原有的 cpu driver cpufreq 的架構,將不同的 Coretex-A15 與Coretex-A7 工作頻率排列組合後,當作一個虛擬的 cpu freq 設定。這方法的好處是上層 user space 控制 kernel cpu 工作頻率的操作介面不用改變。

2012年3月19日 星期一

閱讀 Blind_signature 維基百科條目


Blind Signature

一開始是看到 godfat 的 G+ 的連結,連到 gslin 的 blogspot blind signature

維基百科的類比方式是,把一封秘密的信件放到信封中,簽名的人對著內夾覆寫紙
在內的信封直接簽 (因此簽名者不知道信件內容,但確實達到驗名証身的效果),因此
不止信封,連信件內容也有簽名,主要適用在需要隱私又要能確保無偽造可驗証的
系統。

兩大應用分別是:
1. 匿名投票,又需要能驗全體投票內容,
2. 數位錢包。

其中用到的數學原理是 blind RSA Signatures,原訊息 m 加上 blinded factor r 後變 m',
m' 給簽名者簽完得到 s', 原信件作者可以再透過 blinded factor r**(-1) 跟 s' 取得
原訊息 m 的簽名 s. (see wikipedia section)

但維基百科也提到 RSA 的 blind Signature 同時也可能被攻擊者用來騙簽名者解一段
簽名者 public key 加密過的私密訊息,主因是 1. blind (簽名者不知道是簽啥) 2. RSA
的 private key 簽名其實相當於解開用 public key 加密的內容,因此使用 RSA 簽名的
話,要記得 RSA 簽名跟加解密絕對不能使用同一組公開/私密金鑰。

https://plus.google.com/113906251313439000579/posts/iHQ6j2ktYH8
http://blog.gslin.org/archives/2012/03/18/2852/blind-signature/

https://en.wikipedia.org/wiki/Blind_signature
http://crypto.stanford.edu/pbc/notes/crypto/voting.xhtml

digital cash 電子錢包
https://en.wikipedia.org/wiki/Ecash

voting protocol 可驗証的投票協定
https://en.wikipedia.org/wiki/End-to-end_auditable_voting_systems

zero knowledge proof 不知道內容下驗証訊息為真的方式
https://en.wikipedia.org/wiki/Zero-knowledge_proof


2012年3月16日 星期五

add new ssh key/host settings for github access

主要是照 github 的 Set Up Git help, Linux part
(不知道為什麼這個網頁載很久...有時還會 timeout XD)

1. ssh-keygen ...輸入 id_rsa_github 或自己取名以免蓋掉你原本的 ssh key pairs
2.  ssh -i .ssh/id_rsa_github -T git@github.com 確定可以 ssh (no shell, else..0wned XD)
3.  setup github username and api token for github services
    git config --global github.user your-github-username
    git config --global github.token your-github-api-token

4. ~/.ssh/config 加入針對 github 的 ssh key

    Host github.com
        IdentityFile ~/.ssh/id_rsa_github
        SendEnv LANG LC_*
        HashKnownHosts yes
        GSSAPIAuthentication yes
        GSSAPIDelegateCredentials no

接下來再照 github 的 create a repo....網頁就可以開始你自己的 github open sharing
之旅了,只是要記得免錢的服務都是要公開的...

change vimdiff colors in railscasts.vim colorscheme

在使用 railscasts.vim 一段時間後,當用到 vimdiff 時,常常因為 railscasts.vim 中的
DiffAdd, DiffDelete 設定(DiffText, DiffChange則未定義) 顏色不易分辨而作罷,甚至
有時候就回到 diff -u 的黑白 -+ 世界比較單純。

但在看過 Change vimdiff color 一文後才知道原來只要改 DiffAdd, DiffDelete, DiffText,
DiffChange 四個選項,就可以讓原本 railscasts.vim 的 colorscheme 跟 vimdiff 使用
更容易分辨的 256 色的 xterm 環境設定,我調整後的四個選項設定如下:

DiffAdd 指相對於另一邊檔案新增的部份

DiffDelete 指相對於另一邊檔案刪除的部份
DiffChange 指兩邊檔案文字有差異的文字區塊
DiffText 指兩邊檔案文字差異的文字內容



highlight DiffAdd cterm=bold ctermbg=245 ctermfg=white
highlight DiffChange cterm=bold ctermbg=100 ctermfg=black
highlight DiffText cterm=bold ctermbg=140 ctermfg=white
highlight DiffDelete cterm=bold ctermbg=180 ctermfg=black


https://github.com/sjh/config_files/blob/master/vim/.vim/colors/railscasts.vim

用起來效果如下圖:











當然你可以再改成自己喜歡的配色,而 xterm 256 色(0黑~255白)的對照表可以參
考以下網站:
 http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim

guifg 跟 guibg 的部份因為我沒用到所以還沒調整。