Category Archives

146 Articles

Python局部變量的坑

0   10397 轉為簡體

最近碰到這麼個問題,有這麼個函數,用來將HTML轉義字符變回原來的字符:

其中unichr用來將一個整數轉換成Unicode字符,僅在Python2中存在。Python3中,chr可以同時處理ASCII字符和Unicode字符。所以我們在Python3環境中將unichr映射到chr上。

運行這段代碼會在第8行報錯:NameError: free variable ‘unichr’ referenced before assignment in enclosing scope。而且只有Python2會報錯,Python3不會。

 

首先從問題上看,報錯的原因是在閉包replc里unichr沒有定義。

但是Python2明明是有unichr這個內置函數的,為啥就變成未定義呢?

Read More

ngx_http_geoip_module開啟utf8支持

0   7145 轉為簡體

cidr.me中使用這個模塊時,返回了類似這樣的輸出:

Canada, Quebec, Montr�al

發現有人提過PATCH。於是去喵了一眼源碼,發現有一個文檔里沒有提到的隱藏參數。

可以使用

這樣來啟用utf8。默認是iso-8859-1,或者叫latin-1。

MySQL默認也是latin-1。大概因為是單字節的,所以大家都愛默認用它;可是除了肉眼可見的字符,別的控制符除了會在終端里用以外並沒有什麼卵用。

還有libzip里默認用的是CP437,是DOS版的單字節編碼。因為大概只有中文版的windows自帶的壓縮功能會生成GB18030編碼的zip文件,所以還魔改過一個中國特色的libzip

 

Sphinx 2.2.11和2.3.2的mmseg分詞補丁(基於Coreseek)

0   9744 轉為簡體

English Version

補丁包括了nzinfo在coreseek中貢獻的mmseg補丁,以及我提交的日語假名補丁(詳見這篇博客)。詳細更改見這裡

打上補丁之後,可以使用mmseg來做分詞器。如果是對大篇幅的文章做索引,推薦使用mmseg處理結巴分詞的詞庫來生成一個比較靠譜的詞庫。

Sphinx 2.11.1:Github下載 本地下載

Sphinx 2.3.2:Github下載 本地下載

Read More

cloudflare-partner-cli: using CNAME on cloudflare

中文版本

This is a CLI program that let you set CNAME to use Cloudflare using the partner program.

Both Python2.x and Python3.x is supported. No extra library is needed.

To use Chinese menu, set environment variable LANG to use UTF-8 (for example, zh_CN.UTF-8).

Usage

  1. Apply for partner program at https://www.cloudflare.com/partners/.
  2. Clone this repository or download script.
  3. Run python ./cloudflare-partner-cli.py.
  4. Enter your host_key. You can get it here.
  5. Enter the account you use to manage domains (your personal account, not partner login account). User key is stored in .cfhost.
  6. Follow the instructions on screen.

Note

  • Value of resolve_to has to be DNS record (for example: google.com) instead of IP address.

cloudflare-partner-cli: 使用CNAME方式接入Cloudflare

0   11578 轉為簡體

English Version

使用Cloudflare partner功能用CNAME方式接入cloudflare。

你可以使用Python2.x或者Python3.x。無需安裝任何依賴。

如需使用中文菜單,請將環境變量的LANG設置為使用UTF-8 (比如zh_CN.UTF-8)。

使用方法

  1. 申請Cloudflare partner計劃 https://www.cloudflare.com/partners/ 。
  2. clone本項目或者直接下載腳本
  3. 運行 python ./cloudflare-partner-cli.py
  4. 輸入 host_key。可以從這裡獲得。
  5. 輸入要用來管理域名的賬號 (你的個人賬號,不是partner賬號)。賬戶信息保存在.cfhost文件中。
  6. 按照屏幕提示操作。

注意

  • 源站地址必須為DNS記錄,如google.com,不能填寫IP地址。