Category Archives

146 Articles

Python局部变量的坑

0   10276 转为繁体

最近碰到这么个问题,有这么个函数,用来将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   7114 转为繁体

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   9649 转为繁体

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   11405 转为繁体

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地址。