2009年10月8日星期四

How does Rake search for rakefiles?

Most of my understandings of rake come from the analogue to make. I thought, like make, rake requires a rakefile located in the current path where I issue the command if no rakefile explicitly specified in the arguments. However, I accidentally typed rake in subdirectory vm under the root path of the source code without a rakefile available yesterday when I was playing with Rubinius. It compiled!

Later when I tried to find the details on how the virtual machine was built I can't find anything in the root rakefile except for a line of comment saying "See vm.rake for more information". It was easy to locate the file but how was it loaded?

From the behaviors I could guess that rake would recursively search the up a level of directory for a rakefile if none exists in the current one, and rakefiles located in the rakelib directory would be somehow automatically imported, but I wanted some concrete documentation to prove my guess. I was astonished after some googling that it seemed that everyone knew the answers but no one ever wrote about it.

Therefore, the last weapon I could use was RTFSC. Fortunately the source code of Rake is pretty straightforward. The searching and importing logic is basically
  1. chdir to .. if there is no rakefile existing in the current dir;
  2. when finding a rakefile record its directory to location and load it;
  3. import all of .rake files located under location/rakelib if exist.
Wish this post could provide a little help to any rookies like me that are also seeking for the answers to this questions!

2009年6月24日星期三

玩儿转PSP

漫长乏味的班车时间越来越难度过,阅读和游戏是一剂良药。我的图书大多是电子书(特别是PDF),在没有入手网本之前,手头的设备很难满足阅读需要。即使是我的N800在看PDF格式时仍然嫌屏幕不够大。更别说手机游戏实在没有多少玩儿头。这是我想起了闲置已久的PSP。

这次的任务是升级小P + 安装PDF阅读器。

升级固件相对比较容易。小P原来的版本是3.71 M33,懂行的人一看就知道这是个Homebrew的固件。没办法,这就是中国的现实。经过一轮搜索我发现目前最高版本应该是5.00 M33-6。一直担心升级导致的一系列问题,包括选错固件、升级失败等等,不过让我找到了一个很详尽的升级指导,除了说明还包括需要软件的链接,非常方便。任务完成!

PSP上的PDF阅读器好像只有一个,Bookr。但是这个软件已经很久没有更新,最新的0.7.1工作在固件1.5版本上,我从官方网站上下载的版本根本不能在我的小P上运行。另一轮搜索显示应该安装一个1.5版内核的扩展。糟糕的是这种方法只适用于PSP 1000系列,我的小P是2000系列。

又有人提到可以用TimeMachine,它可以从存储卡上加载老版本内核。可惜,安装TimeMachine超级麻烦,还涉及到什么Pandora Battery,我不得不放弃这个方法。

峰回路转,意外发现Bookr也有很多非官方的升级,尝试一下果然可用。思路一开,最后一轮搜索,这里原来有很多版本,选取下载量最大的v8.1,加上官方网站上的CJK字体,任务完成!

这次玩儿转PSP,让我领略了Homebrew的厉害,也让我对PSP的开发产生了兴趣。哪天咱也Homebrew一个。

2008年7月31日星期四

死而复生

前段时间弄到一个老掉牙的Toshiba Portégé R100笔记本,想试试装个Ubuntu看看效果如何。到手发现没有光驱也没有软驱,老机器也不支持USB启动,这叫我如何是好。

因为机器本身还有Windows可以启动,就利用Grub for DOS启动一个Linux内核,再通过网络安装。本来很顺利的,我却犯了一个低级错误。安装界面到了Base System安装完毕,问我要按照哪个子系统,我选了Ubuntu Desktop,然后安装界面就停一个什么6%不动了。我猜应该是在下载各个软件包,但是当时时间已晚,我想关机睡觉,心想反正Base System已经有了,图形环境可以以后再装,就强行中断了安装。可重启一看傻了眼,原来Grub没有装,这下机器完全起不来了。

找不到合适的软驱、光驱,就想把硬盘拆出来在别的机器上装系统。打开一看,这个硬盘是CF II接口的,我的台式机没法用。在网上google了半天发现有CF II转IDE的转换卡,还真在百脑汇买到了。一试,不好用,又去店里换了一个,在Windows上能用,可在我的Linux台式机上还是不好使。前后两个礼拜时间,全是无用功。

就在这时,我台式机的硬盘坏掉了。

又花了了大约两个礼拜时间买新硬盘、恢复数据,我的台式机终于恢复,但是心有余悸,一直不敢也懒得再碰这台老旧笔记本,而且也没有想出什么办法去救活它,直到前天。

前天忽然想起机器上有一个内置的SD读卡器,就按照这里的办法做了一个能启动的卡。昨天晚上开机打开BIOS一看,还是不能启动,SIGH!

这是忽然发现启动选项里有LAN,也就是PXE,我可以利用台式机做一个网络启动的环境啊!再来一阵Googling,找到这里,发现PXE环境其实很容易配置。唯一一个小麻烦就是我的无线路由已经提供了DHCP服务,所以得先把它关掉,改在我的台式机上临时建一个临时DHCP服务器,而且得把临时DHCP的设置设成和原来无线路由的设置一致,这样才不会影响外网的连接。笔记本一成功启动,就可以回复原来的环境了。

终于昨晚这台笔记本起死回生,现在可以跑Hardy了。

2008年5月19日星期一

Hard Drive Broken

One of the hard drive on my desktop, which contains my entire home directory was broken a couple of hours ago. My huge amount of digital collection has gone! To me, it's another disaster in addition to the gigantic earthquake.

2008年4月27日星期日

Upgrade to Hardy

Took the whole weekend to upgrade my Gutsy to Hardy. It seemed that an upgrading is much more painful than a clean install, especially when I have many software packages installed in addition to the system default.

The pain was partially due to the slow downloading speed and two accidental power failures in my apartment. Nevertheless I found Ubuntu upgrading system is pretty robust. It knew there was a failed upgrade happened. And I can still select to upgrade again and again. To speed up the process, I changed to download a Hardy alternative install CD image with BitTorrent, and used it the do the upgrading.

Switching system repositories leaded to orphanage of the quite a lot software packages. An ideal situation I'd like to see would be all of them can be automatically removed. Of course, at least some were dependencies of the applications I explicitly chose to install, but I still couldn't imagine there were so many of orphaned packages left. Some of them even conflicted with new software packages. For examples, the new Deskbar applet was affected. It kept reporting failures until I removed all of the orphaned packages. Firefox is another case of such. The old Firefox 2 was installed as a system dependency. However, it was kept in parallel with the new Firefox 3 beta in my Hardy. I don't know whether it was on purpose or an error. Anyway it was not big headache, and only took some time to adjust by hand.

The biggest problem now is that, after upgrading, Grub becomes very slow to boot up. I used to have similar problem with the old version only when there was a system failure. As what I understand, the file system was left dirty when the system failed. Grub needed to take some time to search and load especially in my ReiserFS system. But when the system was up, the file system would be cleaned. However, now it happened every time, even my system was normally shut down. I did some googling and rewrote the MBR, but it still didn't help. There is also some information indicating that it's a problem between Grub and ReiserFS. I am not sure of it, but I've already decided to switch to ext3 ASAP, although it's an another uneasy task.

2008年2月2日星期六

+0和-0

最近开始关注Rubinius。这是一个Ruby的虚拟机实现,它追求的目标是要用Ruby来实现Ruby,所以很吸引大家的眼球。目前,Rubinius还处于比较原始的阶段,还不能跑Rails之类的应用。

Rubinius的开发模式也很有趣。开发者首先是写了一大堆spec,再修改代码使这些spec通过,基本上是TDD的路子。现在不少工作都是在完善这些spec,而不是完善功能本身。因为Ruby本身并没有明确定义的语言规范,所以这些spec首先得在MRI上通过后,再用于Rubinius。开发者甚至想把完善后的spec最为Ruby的语言规范和标准,用于其他Ruby实现的开发。

今天我就跑了跑目前已经稳定的spec,结果String#to_f失败了。仔细看了一下,(1.0 / "-0".to_f).to_s.should == "-Infinity"这句失败了,结果是“Infinity”,而不是希望的“-Infinity”。再细看下去是"-0".to_f返回的是“0.0”,而在MRI里则返回“-0.0”。Rubinius的String#to_f和MRI一样也是用C语言实现的,基本上就是调用strtod函数。我又在我的PowerBook上试了一样,是对的。所以问题应该出在strtod函数上。

通过Google Code Search搜了一把,发现很多软件,包括MRI,都提供自己的strtod的实现,看来就是为了解决这个正0和负0的返回值问题。它们提供的实现应该是BSD的实现,苹果的Mac OS X也是从BSD发展而来,所以能通过。这应该是我第一次直面这种兼容性问题。

后记

今天发现这个Bug确实是strtod()的问题,具体可以看这里。Revision 1.25已经修改了这个错误,Lighthouse里也发现了这个问题。看来我的Gutsy是解决不了这个问题了,只有等升级到Hardy(>glibc 2.6.1)了。

2007年9月23日星期日

在Ubuntu 7.04里轻松美化汉字

说来这个方法真的很简单,奇怪倒是我居然刚刚才发现。

一直认为Ubuntu默认的汉字字体不好,所以导致汉字显示出来大大小小,而且不同字体混在一起。前两天浏览/etc/fonts目录才发现其实系统已经安装了“文鼎PL细上海宋Uni”和“文鼎PL中楷Uni”,仅仅是因为fontconfig搜索路径没有设置对,导致汉字显示效果不好。所以只要把这两个字体在搜索路径的位置提前,让它们成为汉字显示的第一选择即可。于是,在/etc/fonts下创建一个新文件local.conf,内容如下:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>DejaVu Serif</family>
<family>Times New Roman</family>
<family>Thorndale AMT</family>
<family>Luxi Serif</family>
<family>Nimbus Roman No9 L</family>
<family>Times</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>DejaVu Sans</family>
<family>Verdana</family>
<family>Arial</family>
<family>Albany AMT</family>
<family>Luxi Sans</family>
<family>Nimbus Sans L</family>
<family>Helvetica</family>
<family>AR PL ShanHeiSun Uni</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>DejaVu Sans Mono</family>
<family>Andale Mono</family>
<family>Courier New</family>
<family>Cumberland AMT</family>
<family>Luxi Mono</family>
<family>Nimbus Mono L</family>
<family>Courier</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
</fontconfig>

上面大部分内容都是抄/etc/fonts/conf.avail/60-latin.conf的,只是加了红色的三行,问题就搞掂了。