Category Archives

147 Articles

使用Redis协议来调试ngx.shared

0   9888 转为繁体

有时候用ngx.shared的时候想看一下到底存进去的值是什么,或者想列一下满足条件的键,或者想批量操作,所以这个项目就是用来解决这个问题的。

除了支持ngx.shared提供的操作以外,学习Redis增加了PING(测试连通性),KEYS(列出符合条件的键)和EVAL(在服务器上执行Lua脚本)。

已上传到opm,可以通过

opm install fffonion/lua-resty-shdict-server

一键安装。

由于目前stream和http子系统是两个独立的Lua VM,因此不能通过全局变量来共享数据。另外两个子系统的shdict是分别定义的,因此也不能互撸。所以如果想用这个模块来在redis-cli里撸http子系统下定义的shdict,需要这个补丁

示例配置:

然后

 

Python局部变量的坑

0   11321 转为繁体

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

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

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.