I wish I have a little bit more virtual memory so I can convert virtual money to real one.
ad$ense or ad$pam?
Apr 2
iPhone is a fancy toy with a lot of power but Apple deliberately locks a lot of the potential power. One thing I like to do on an iPhone is to be able to read CHM files. As a weekend project, I setup the tool chain for iPhone following the instructions. Then, I grabbed the source code of chmlib. With some minor modification, I was able to compile the chmlib as an iPhone binary library. That was very encouraging.
This provides a convenient way to make iPhone as a CHM reader. In the chmlib source code distribution, there is an example program that runs as a http-server that serves the content of a CHM as standard web page. The “mobileSafari” has no problem to render the results, but the fonts are usually too small to read and the text is typically rendered too wide such that a lot horizontal scrolling becomes annoyingly necessary.
I decided to combine some python code with the chm_http server from the chmlib source code. I modified the source code of chm_http so it can call python code to modify the HTML code in the CHM file, replacing the original CSS with new setting for reading on small screen. Furthermore, I found it was tedious to start the chm_http from a terminal every time when you want to read a different book. I wrote another small python script that can scan a directory and find all CHM files in the directory to output an index html page. At the end, I was able to use the mobileSafari pointing to the index page and select the book I want to read. The “chm_http” server would start automatically to get the book I like to read.
If you are interested in reading CHM on your iPhone. Get this iphoneCHM.tgz (the file would be upload soon). Copy the “chm_http2“, “rewriteHTML.py“, and “CHMServer” to “/usr/local/bin/” in your iPhone. Change the permission of these files such that you can run all of them. Put some chm files in /var/root/Media/CHM_Ebooks/. Open a terminal in the iPhone or ssh into the iPhone to run “CHMServer”. After that, ask the Safari to open this URL http://127.0.0.1:8000. You should see the links to the CHM files. You can now click on any of them and enjoy a nice reading time.
Tomorrow
Jul 22
Tomorrow, a new day with new challenges! What a great feeling for entering the next stage of my career! Although I have to make a tough decision, it is indeed time to move on. I am really feeling the excitement of a new environment and a new career path now.
用 python+OV 寫中文輸入法
Jul 18
前一陣子看到 lukhnos 在寫一個能讓 OV 用 Ruby 來寫 filter 的模組,一時心血來潮想看看如何用 python 來寫 OV 的 filter 的模組。花了點時間研究了一下如何在 C/C++ 中內藏 python。 雖說用 python 來寫程式作研究也有好一陣子,也曾經用過 SWIG 來控制用 C/C++ 寫的物理模擬程式, 在 C/C++ 中呼叫 python 倒是第一次實做。花了點時間寫了個 prototype,在 lukhnos 的協助下,搞定了一個讓 OV 可以用 python 寫 filter 的模組 (在 OV 的 svn repository: Modules/OVOFPythonBased/ 中)。
OV 的 filter 主要是呼叫一個叫 process 的 method。傳到 process 中的只是一個字串,所以實做 OV 的 filter 並不是太難。發展的過程中,大多數的時間花在看 python 的 C API 文件,熟悉如何在 C/C++ 中建立 python 的物件及將參數傳給 python 的 method。
讓 OV 的 filter 機制可以用 modern 的 python 或是 ruby 實做只是第一步。Dynamic language 的方便已經讓發展新的 filter 的工作大大的簡化。所以下一個就是看看能不能讓 OV 用 Python 或是 Ruby 來寫輸入法。在未來實驗類似酷音等比較複雜的自然語言處理的輸入法模組的時候,如果可以用 Python 或是 Ruby 來寫輸入法應該會有很大的助益。
寫 python based OV filter 時, 只需要定義好對應到 process 的 python method/function 就好了,python 的部份是完全的被動,python 的 code 並不需要管 C/C++ 的 class 與 instance,只需要實做一個叫 process 的函數就可以了。 但寫 OV 的輸入法模組的時候,有幾個 OV 的物件必須要傳到 Python 中,而且 Python 也最要能夠 subclass OV 中的 class 來保持 OV API 介面的一致。基本上要做下面幾件事:
(1) 用 SWIG 來把 OV 的 class 轉成 Python 的 class。
(2) 定義對應到 Python class 的 OV C/C++ class。
(3) 在 (2) 中最重要的一件事就是要把將 OV C/C++ 中 instance pointer 轉成 Python 可以認得的物件。
在這三項工作裡,最容易的部份是 (1)。基本上只要把 Framework/Headers/OpenVanilla.h 剪貼到 SWIG 的 interface 檔中就好,唯一要注意的地方是要讓 SWIG 知道要將 C++ 的 class 轉成 python 的 class。這要用到 SWIG 中的 directors 。請見 SWIG 的相關文件 與 Modules/OVIMPython/ 中的 OVIMPython.i。
接下來要就是要讓 OV C/C++ 知道 Python 的存在,主要要去 subclass 兩個 OV C/C++ 的 class, OVInputMethodContext 和 OVInputMethod, 讓 OV 的 loader 可以呼叫對應的 python 物件。請見 Modules/OVIMPython/OVIMPythonBased.cpp 中的 OVIMPythonBasedContext 與 OVIMPythonBased class。 這兩個 wrap classes 作的事情很簡單,就是實做 C++ method 來呼叫對應的 Python instance method。但是之前的一個障礙就是 OVInputMethodContext 及 OVInputMethod 中的 method 的參數裡大多是指向 C++ 的 instance 的 pointers。要怎麼把這些對應的 instance 變成 python 物件在傳給 python 倒是一個比較不容易的問題。也牽涉到 SWIG 怎麼把 C++ 物件映射到 python 物件的細節。
也許在 SWIG 有對應的解法,但我並沒有從 SWIG 的文件中看到顯而易見的方法來解決這個問題。後來是在研究 SWIG 產生的 python module 的檔案中找到 hint。對每一個要 wrap 的 C++ class,SWIG 會產生兩個對應的 python class。例如如果在 C++ 中有如下的宣告:
class OVKeyCode : public OVBase {
public:
virtual int code()=0;
};
SWIG 會建立下面兩個 python class:
class OVKeyCode(OVBase): ...
和
class OVKeyCodePtr(OVKeyCode): ...
其中 OVKeyCodePtr 的 constructer ( __init__() in python ) 可以用 SWIG 中的表示 C/C++ pointer 的 python pointer object 建立對應的 python object。所以接下來要作的就是要把 C/C++ 的 pointer 轉成 python 中 pointer object。而 SWIG 的作法只是把 C/C++ 中的 pointer 的 address 和 type 換成特殊格式的字串,在 SWIG 所產生的 C/C++ 的 wrap 檔中有一個特別的函式 (char *SWIG_PackData(char *c, void *ptr, int sz) ) 就是把 C/C++ 的 pointer 換成字串,所以我們就可以用這個函式將 C/C++ 的 pointer 轉成對應的 python 字串然後透過 SWIG 產生的 aClassPtr 來產生 python 中的 aClass 的 instance,而這個 python instance 的 implementation 就是對應的 C/C++ implementation。
這樣的 mapping 實在有點太複雜而不直覺。還沒有真的詳讀 SWIG 的文件,不知道有沒有比較優雅的方式來作同樣的事。雖說如此,對要用 python 寫輸入法的人可以完全不去理 wrapper 本身及兩個語言的物件對應的複雜性,專注在用 python 來寫輸入法。 在lukhnos 稍早寫的用Python + OpenVanilla寫輸入法中有用 python 的 OV 輸入法的 minimum example。
我想這只是第一步,我自己來試著了解 embedding python 的小小練習。如果有空的話,再看看如何真的用 python 在 OV 裡作些有趣的事。
The following code create circular references in python:
>>> aRef = [] >>> aRef.append(aRef) >>> print aRef [[...]]
This creates a list object referred by a variable named “aRef”. the first element in the list object is a reference to itself. In this case, the “del aRef” dereference aRef to the list object. However, the reference count of the list object does not decrease to zero and the list object is not garbage collected, since the list object still refers to itself. In this case, the garbage collector in Python will periodically check if such circular references exist and the interpreter will collect them. The following is an example to manually collect the space used by circular referenced objects.
>>> import gc >>> gc.collect() 0 >>> del aRef >>> gc.collect() 1 >>> gc.collect() 0
Maker Faire 2007
Jun 24
I went to Maker Faire yesterday. I have been a Make magazine subscriber since its debut and I like to hack and make things. Although I have been working some project for my work (in systems biology) last year very hard to a degree that I did not feel to do anything anymore. Since the project is near the end and I am in a position trying to seek new opportunities in my life, it might be a good time to revive some hacker/maker sprit in my heart. So, I could not miss the second Maker Faire,.
My families and I arrived the faire around 10 o’clock. We first spent some time on the Robot Pavilion to see quite a few different interesting robot. Some of them are quite extraordinary, e.g., robots driven by steam engine, self-balancing robot, and home-made Segway, etc.
Although there was a schedule for different presentation and demonstration, with a less than two years old toddler, we were just doing random walk in the faire ground afterward.
The largest Maker demonstration was at ___. Half of the hall was for “Maker” and half of the hall was for “Crafter”. Joy was joking about that most women can stay in the crafter part and most of men can stay in the maker part and this made the “Maker/Crafter Faire” as a great event for family. One can found some of those projects in Make demonstrated in the maker part. There was also a DIY lab to make a “Ybox” provided by Yahoo as sponsor. It was interesting to see that Yahoo seemed putting more effort for this “Maker” event. Compared to Yahoo, Google only put a few computers demonstrating Sketcher. On the other hand, Microsoft did demonstrate some of their cool lab technologies. I talked to a engineer showing me their new web mash-up tools, popfly. It seemed quite interesting, but I had yet to tried it out by myself. Well, at least, my daughter liked their “ducks”.
In the main Make demonstration, what I found quite interesting was the 3D Metal sculptures by Bathsheba. This was my first time to see the results of a 3D printer using metal as the material. It just is amazing to see new technology combining the beauty of math and science. Although I had seen some of the mathematical surfaces on a computer screen, it was just more exciting to see them as “real things”. It was very tempting to buy one of the sculptures and I would probably eventually order one sometime. Or, make one myself for myself in the future. I think I can do it by joining the TechShop and I can use their 3D ABS printer to construct some 3D sculptures too.
There were also all kind of bikes and human powered machines and quite a few DIY activities for kids and adults. Well, my one-and-half years old daughter, Emily was still too small for most of those activities but she seemed like the faire a lot. Oh, she liked the Wii remote controlled RC cars. Ha, this might be a good excuse to buy a Wii, for her and for me (to hack).
Later on, I found the booth Sun demonstrating their Java-power embedding system developing gadget “Sunspot”. The “Sunspot” seemed a cute and powerful little machine for all sorts of purposes, but it was a little bit expansive.
Overall, my families and I had a fun and inspiring day. All I hope is that I will be able to get time to develop some cool projects myself in the near future.
What are interesting:
IMG_3502.JPG
3D Metal sculptures by Bathsheba — exploring how math, science and sculpture meet (web site). ProMetal is the company which make the sculptures by a technology that can “print” metal layer by layer.
TechShop — A club which the members can use their machines for prototyping and DIY. The membership costs $100 per month. I find it is very attractive. If I decide to make something cool, no doubt I will get a membership and learn to use all cool machines they have. They have a 3D ABS printer (from Scicon?) that can be used for fast prototype.
Lots of robots.
Sunspot
Popfly
Moto labs
STL file format for 3D sculpture/prototype.
Pick the nose!!
IMG_3511.JPG
Yahoo, Ybox.tv
puzzle maker
some pictures
Tokyo Tower at Night
Apr 22

The night view of Tokyo on the fifty-fifth floor in the Mori Tower.
六本木某大樓五十五層的東京夜景。
Viacom vs. google
Mar 27
Well, actually, I just want to test video embedding. This clip is pretty
funny anyway.
Quickhull is an algorithm that is similar to the quicksort using a divide and conquer strategy to find the convex hull for scattered points. The green line in the plot is the initial base line and gray lines are the intermediate base line. The final convex hull is shown in red.
source code: qh.js
<

My one day trip to Lugradio, San Francsico, 2008
Apr 12
Posted by Jason Chin in comment, misc | No Comments
從 PingYeh 那聽到有 Lugradio 這週末在 San Francisco 舉行, 一時興起,決定和老婆女兒告假一天去看看熱鬧。
雖然我在 1993 還是 1994 安裝過 Linux with kernel version 0.97 後,有幾年是非 Linux 不用的人,參加 Linux / open source 社群的活動倒是第一次。台灣的 open source 活動開始熱絡的時候,我人已不再台灣,而人在米國的時候,因為學業和懶的關係也沒有看看過有沒有甚嘛好玩的活動可以參加。所以對我來說,這一次湊熱鬧的感覺是很新鮮的。
我約十一點多到達會場,當場交了米金大洋十塊錢,註了冊,拿了名牌和有贊助商的小禮品的小袋子就進到會場裡逛逛。會場是在 San Francisco Metreon 戲院的頂樓的 CITY VIEW,從前到 Metron 時從來沒聽過有這麼個地方可以辦活動又還有不錯的 city view 的地方。同一時間內,會場會有三場演講進行,你可以選擇比較有興趣的來聽。不想聽的話,就可以逛逛廠商地展示。我隨意聽了幾個演講:其中有 Second Life 的人來說他們 open source 的策略,有 Bungee Connect 的人示範他們的發展平台,有 VMWare 的人展示 Virtual Machine 的 Streaming,也有 Humanized 的 Aza Raskin 討論使用者介面等等。 大部分都還滿有趣,但並沒有在很多技術上比較有深度的討論,大多的討論都在比較形而上的層次。但這樣也好。而從其他聽眾的提問看來,很多參與的人很重視 open source 的發展。
在其他廠商展示方面,我跑去收集了不少 linux 廠商提供的 live CD。而在眾多的廠商展示裡,對我來說最有趣的卻是兩個硬體的廠商。其一是 TI 可以跑 Linux 的單晶片電腦 beagleboard 。看來等 TI 六月出了這東西,我可能會受不了灑點錢買來玩玩。
另外一個有趣的是我終於看到傳說中的 OLPC,的確是很可愛讓人會不住把玩的東西。可惜這有趣的 laptop 只能看看而已。
今天最後一個演講到五點,本來要 skip 晚上的 party,已打算要回家了。在離開會場前,一個對 amateur biotech 有很大興趣的軟體工程師在得知我在一家 biotech 公司工作後,興高采烈的和我討論有沒有甚麼可以在家裡做的 biotech 的計畫,聊了一個小時後才放我回家。
明天 Lugradio 還有一整天的活動,不過我有其他事要做,不能去了。但今天的一日行倒是收穫不少。意外地得了不少在工作上或是家中得不到得 inspiration 和平常不容易看到的 San Francisco City View!!
