五月一号

今天值得说的事情挺多的。首先,Ubuntu 10.04发布以后,Sun JDK 被放到了partner 仓库里,要使用Sun JDK,添加这个仓库: sudo apt-add-repository “deb http://archive.canonical.com/ lucid partner” 这是悲剧的开始,早晨七点四十起床,添加了这个仓库,把机器上的Sun JDK升级到6u20,为此到了八点三十五才出门。现在没有自行车不比从前了,等公交加上下来走到公司最后九点零六分打上卡。进了办公室一看大家整整齐齐地坐着了,这才听到悲剧:三薪工作日不能迟到,否则只算半天。就为了6分钟,一天半的工资没了。这事现在想起来我都郁闷,发自内心的郁闷啊。 在上班的公交车上恰好收到邮件,是rubyforge的更新,昨天提交的patch已经被接受了,放进了svn仓库,会随Alexandria的0.6.6版本发布。项目的负责人修改了代码,把我那些\t都换成了空格。另外,豆瓣的API接口是json格式的,解析需要依赖libjson-ruby1.8这个库,这段代码被负责人修改了,真的很神奇,原来json可以就这样被转换成yaml def json2yaml(json)     # insert spaces after : and , except within strings     yaml = json.gsub(/(\:|\,)([^A-Za-z\/\\])/) do |match|         "#{$1} #{$2}"     end     yaml.gsub!(/\\\//, ‘/’) # unescape forward slashes     [...]

Posted in: 当时 by Sunng 3 Comments ,

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 [...]

Posted in: 广告 by Sunng No Comments , , ,

Patch for Fantasdic Google Source

I found fantasdic a great powerful dictionary tool with friendly UI and supports multiply sources. Unfortunately, this project seems to be no longer maintained. The latest version is 1.0-beta7. The google translate source was created in 2007. As the google translate service page changed, this module doesn’t work any more, so I just picked up [...]

Posted in: 广告 by Sunng No Comments , ,

Using Yan in Ruby Web Application

I will show you the usage of Yan captcha service. In this tutorial, it’s based on a simple ruby web application of the Sinatra web framework. Before we start to use the service, it is necesary to get Yan running. Download the code from the project page, then build and run it with maven: mvn [...]

Posted in: 把戏 by Sunng 10 Comments , , ,

GeoHash

今天偶然看到一个Ruby的GeoHash库,功能非常简单,就是将经纬度坐标哈希成字符串,并且,利用这个字符串可以粗略地比较两点的距离。这个库的代码host在GitHub上,要安装,需要将github加入gem: sudo gem sources -a http://gems.github.com sudo gem install davotroy-geohash 用法,irb: irb(main):001:0> require ‘rubygems’ => true irb(main):002:0> require ‘geohash’ => true irb(main):003:0> GeoHash.encode(32.168, 118.54) => “wtsr12n0nj” irb(main):004:0> GeoHash.decode(‘wtsr12n0nj’) => [32.168, 118.54] 代码可以从github上获得 git clone git://github.com/davetroy/geohash.git GeoHash的核心部分用C实现,仔细看一下可以发现是一个四叉树的结构: [codesyntax lang="c"] #define BASE32 “0123456789bcdefghjkmnpqrstuvwxyz” static void encode_geohash(double latitude, double longitude, int precision, char *geohash) { int is_even=1, i=0; [...]

Posted in: 手艺 by Sunng 1 Comment ,