交通游戏OpenTTD

我总是对这种城市建设、交通规划一类的游戏欲罢不能,以前在Linux上一直只是玩Lincity,后来发现了纯交通类的simutrans,最近升级到Ubuntu10.04以后,终于可以玩这个六年磨一剑,精雕细琢的OpenTTD了。

Chindhattan Springs Transport, 19th Dec 1953

可以建造各种客运货运的汽车站、火车站,机场,码头等等,可以建设道路、铁路,可以购买公交车、卡车、火车头、火车车厢等等。可惜我玩了大半天还不知道怎么盈利。。。

Douban provider for Alexandria

Alexandra is a desktop book collection manager on gnome written in ruby. With an extensible architecture, Alexandria uses different sources to retrieve book’s data, including Amazon and many local sites.

Douban.com is considered to be most applicable data source for books published in Chinese. So I write this provider according to Alexandria’s SPI. Now it’s possible to add Chinese books and manage reading lists.

alexandria

Now the code can be found in Alexandria’s bug tracker:
http://rubyforge.org/tracker/index.php?func=detail&aid=28160&group_id=205&atid=865

However, the patch file of book_providers.rb in that list is for svn trunk head version only. To use it with currently stable version of Ubuntu, first, make sure you have Alexandria version 0.6.5-0ubuntu1 and libjson-ruby1.8 installed.

Download douban.rb from rubyforge:
http://rubyforge.org/tracker/download.php/205/865/28160/4923/douban.rb
Copy the file to /usr/lib/ruby/1.8/alexandria/book_providers/ with super user privileges.
Use this patch to /usr/lib/ruby/1.8/alexandria/book_providers.rb

310a311,323
<     begin
<       begin
<         require 'json'
<       rescue LoadError
<         require 'rubygems'
<         require 'json'
<       end
<       require 'alexandria/book_providers/douban'
<     rescue LoadError =< ex
<       log.error{ex}
<       log.warn {'Fail to load douban as provider'}
<     end
<

Feel free to report issue here.

搞定gwibber

升级10.04之后,gwibber2.29开始使用pycurl来处理IO。结果一条更新都拿不下来,为此搜到很多相关、不相关的bug。最后终于自己找到问题,原来是pycurl.setopt方法传入字符串如果是unicode就会报typeerror。而通过gwibber配置界面输入的所有字符都是unicode编码,于是问题也就简单了。做个处理,在 /usr/lib/python2.6/dist-packages/gwibber/microblog/network.py 第18到21行:

    self.curl.setopt(pycurl.URL, str(url).encode('ascii'))

    if username and password:
      self.curl.setopt(pycurl.USERPWD, ("%s:%s" % (username, password)).encode('ascii'))

另外,使用StatusNet的Twitter兼容API来做Twitter API代理,需要把代理的目录名设置为api,因为/api这个路径是写死在gwibber代码里的。通过界面输入的,只是代理的domain。

说实在的gwibber还是挺烂的。

https://bugs.launchpad.net/bugs/542501

https://bugs.launchpad.net/bugs/543860

使用gnome-dictionary和dictd

最近琢磨字典多一些,以前一直不知道gnome自带的gnome-dictionary如何使用,因为默认的字典源里都没有中文字典,而且离线更是无法使用。其实不然,字典服务可以自架,并且可以使用自己的字典。

在自己的机器上架设dictionary server,以ubuntu为例:

安装dictd / dict
sudo apt-get install dictd dict

前者是字典服务器,后者是字典服务客户端。还可以从仓库里安装已经打包好的字典,如
sudo apt-get install dict-stardic
是一个英汉字典

dictd安装好后会默认自启动,也可以通过
sudo service dictd start
来控制dictd的启动、重启和关闭。

通过dict测试服务的状况
dict -D
命令会列出可用的数据库(即字典)

在gnome-dictionary中添加字典源 Edit->Preference->Source->Add
Name: 自定义的字典名
Transport: Dictionary Source
Hostname: 127.0.0.1
Port: 2628

Close之后可以到主界面打开侧边栏,在Dictionary Source中双击选定此字典,在Aailable Dictionaries里双击选中目标字典,于是就可以在gnome-dictionary里使用本地的字典服务了。

接下来安装自己的字典。stardict的网站上有很多中文字典,上面也都标示了授权协议。要在dictd里使用这些字典,需要进行一个简单的格式转换。安装一个工具
sudo apt-get install dictconv

它的使用方法:
dictconv -o OUTPUT_FILE INPUT_FILE

在input_file指定stardict的.ifo文件,在output_file指定要生成的dictd的.index文件。这个转换非常耗时,需要有足够的耐心。这个操作将会生成.index和.dict文件。对.dict文件进行压缩:
dictzip OUT.dict

转换完成后,编辑/var/lib/dictd/db.list文件,在其中添加一个database定义
database YOUR_DB_NAME{
data PATH_TO_DICT_DZ
index PATH_TO_INDEX
}

其中PATH_TO_DICT_DZ是上一步的.dz文件,PATH_TO_INDEX是到上一步生成的.index文件的路径。编辑完成后,重启dictd服务
sudo service dictd restart

使用dict -D可以查看启用的字典。

建议备份/var/lib/dictd/db.list文件,因为每次从apt-get安装字典后,这个文件都会被覆盖。

dictd服务也可以在fantasdic里访问。