交通游戏OpenTTD

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

Chindhattan Springs Transport, 19th Dec 1953

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

My First Hello World Web App Using Compojure

Compojure是一个用Clojure写成的类似Sinatra的Web框架。Leiningen是一个新的Clojure构建工具,它用Maven来处理依赖管理,而通过封装Lancet(基于Ant)来实现build-in的task。

以上是背景介绍。以下是HelloWorld。

创建一个目录作为工程目录

mkdir compojure-app
cd compojure-app

像创建build.xml和pom.xml一样创建project.clj

(defproject info.sunng/compojure-app "0.0.1"
        :description "A demo app running on compojure framework"
        :dependencies [[org.clojure/clojure "1.1.0"]
                        [org.clojure/clojure-contrib "1.1.0"]
                        [compojure "0.3.2"]]
        :dev-dependencies [[leiningen/lein-swank "1.1.0"]]
        :main info.sunng.compojureapp.helloworld)

首行定义了项目的groupId, artifactId和version,其后的是maven风格的依赖定义,最后我们还定义了程序的主类。

这个helloworld只有一个文件,被放在src/info/sunng/compojureapp/目录下

(ns info.sunng.compojureapp.helloworld (:gen-class) (:use compojure))

(defroutes example-routes
    (GET "/" "Hello W0rld")
    (ANY "*" [404 "Page Not Found"]))

(defn -main []
    (run-server {:port 8080} "/*" (servlet example-routes)))

中间就是Sinatra风格的URL映射定义,最后在主类中通过一个run-server方法以嵌入式的方式运行一个jetty

回到工程目录,执行构建

lein deps
lein compile
lein uberjar

通过uberjar可以将依赖通通打入一个jar包中,接着就可以通过
java -jar compojure-app-standalone.jar
启动你的Web程序了,很酷吧

除了这种方式,还可以通过
lein swank
启动一个swank server(project.clj中定义了dev-dependency),再用Emacs的SLIME交互式地运行程序。

参考

Reset default cursor theme and web browser after installing kubuntu

If you installed kubuntu parallel to ubuntu, you might find that the default browser is set to konqueror and cursor theme is oxygen which cannot modified by “gnome-default-applications-properties” and “gnome-appearance-properties”.

To fix this, use Debian update-alternatives tool:
update-alternatives –config x-www-browser
update-alternatives –config x-cursor-theme

All configurable options are listed at /var/lib/dkpg/alternatives

搞定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

List your installed virtualbox virtual marchines using vbox python xpcom api

I’m sorry for the long title. Due to lack of documentation, it’s not easy to use python xpcom api from virtualbox sdk. The code below is just a sample that lists your installed virtual machines. It works on linux with VirtualBox OSE 2.0.8. Hope useful to you.

import vboxapi
vmsg = vboxapi.VirtualBoxManager(None, None)
vbox = vmsg.vbox
vmsg.mgr.getSessionObject(vbox)
machs = vbox.getMachines()
names = map(lambda x: (x.name,x.id), machs)
print names

Output:

[(u'Ubuntu', u'aac3fd46-4f1e-4f6e-8abe-b1a5516abf8c'), (u'Windows', u'fa73952e-f0a6-4bf0-af20-259513d73bc1'), (u'OpenSolaris', u'a951542c-3178-4a6b-8087-f1b0314e283a'), (u'LinuxMint', u'8191f256-1b76-4ce7-a202-93730dae1b33'), (u'Fedora', u'ca250f45-d752-4baf-9281-fb0847dc8287'), (u'Freebsd', u'8322b62a-aed5-4f04-9815-9fadfeba9fe1'), (u'ArchLinux', u'efc1167a-4e06-4c14-aeb0-bfb303c8f5f7'), (u'openSUSE', u'02e18816-311d-420b-99b3-6b4b4cccf7b7'), (u'CentOS', u'ccf0421c-85c4-4123-8722-57abc494c633')]