Vimana

Vimana 在 ubuntu 裡所需要的套件大致有這些:libdatetime-perl libexporter-lite-perl libjson-perl libmouse-perl libyaml-perl libapp-cli-perl libfile-type-perl libarchive-zip-perl
HTTP::Lite 則找不到適當的 deb,所以執行 perl Makefile.PL 時,會問說要不要從 CPAN 安裝,這時候要選 y。

==> Auto-install the 1 mandatory module(s) from CPAN? [y] y

接著 make 的時候,就會開始安裝 HTTP::Lite,同時編譯 Vimana。
最後輸入 sudo make install,就會開始安裝 Vimana。
如果你跟我一樣遇到 make 時,沒反應的話,不妨中斷他,然後輸入 sudo cpan HTTP::Lite 先手動用 cpan 安裝 HTTP::Lite,再重新 perl Makfeile.PL、make、sudo make install 就可以把 Vimana 安裝好了。
安裝 Vimana 以後,首先得用 vimana update 更新套件資料,接著就可以用 vimana install 來進行安裝了。

bash裡的進制轉換

之前朋友問說為什麼 010 不是 10? 我告訴他這是因為這樣的數字會被認定為八進位,像很多語言(如C語言)也有一樣的慣例。後來他就問說該怎麼在 bash 裡轉換,後來我找了一下,才知道要用 bc 來轉換。

#!/bin/bash
# program name: forloop.sh
ss=`echo "ibase=10;$1"|bc`
ee=`echo "ibase=10;$2"|bc`
for((var=$ss; var<=$ee; var++ ))
do
echo $var
done

上面的程式演示了 bc 的用法,所以你輸入 ./forloop.sh 001 011 的話,就會印出 1~11,而不是 1~9。
你可以試著把 ss 跟 ee 換為 ss=$1、ee=$2,然後再執行 ./forloop.sh 001 011 看看,會很清楚地發現差異點。

svndiff 0.2

託 A 同事的福,找到了前一版 svndiff 潛在的問題-不加參數時,zenity 顯示出來的檔案比預定的要少。原因是餵給 zenity 的資料錯誤,應該要在實際的資料前多加一行空白,所以我在 awk 裡改用 printf 來輸出。
[bash]
#!/bin/sh
if [ -z $1 ]; then
FILES=`svn status | awk ‘/^[MCA]/{printf “\n%s\n”,$2;}’ | zenity –list –width=600 –height=400 –separator=\ –checklist –title “The files which modified/conflict” –text ‘Please select files’ –column ” –column ‘Files’`
else
FILES=$@
fi
for FILE in $FILES; do
svn diff –diff-cmd /usr/bin/meld $FILE
done
exit 0
[/bash]

Reactions in state

IBM Rational Rhapsody 裡的 Reactions in state 其實就是 UML User Guide – State machine 一章裡講的 Internal transitions。我覺得 Internal transitions 一詞比較清楚,一看就明白是什麼意思。
意即進入 State 以後,可以收到 event,但不會轉移到其他的 state,執行完以後,仍然還在原來的 state,這邊要注意的是,原 state entry/exit 裡的程序不會再被觸發。
舉例來說,假設有個 display state,entry 會執行 display(); reactions in state 裡定義了 evRepaint 時,會執行 repaint()。那麼,在進入 display state 時,display() 會被執行,如果此時收到 evRepaint,repaint() 會被執行,但 display() 不會再執行一次。

svndiff

想不到 svn 要用 –diff-cmd 才能指定用哪個 diff,因為不想每次打 svn diff –diff-cmd 這麼長的指令,就寫成了 script。既然要寫成 script,那乾脆再簡化,如果不帶參數,就自動帶出所有有更動/衝突的檔案,讓我來挑選哪些要比對。

#!/bin/sh
# Dependencies: zentiy subversion awk meld
if [ -z $1 ]; then
FILES=`svn status | awk '/^[MC]/{print $2;}' | zenity --list --width=600 --height=400 --separator=\  --checklist --title "The files which modified/conflict" --text 'Please select files' --column '' --column 'Files'`
else
FILES=$@
fi
for FILE in $FILES; do
svn diff --diff-cmd /usr/bin/meld $FILE
done
exit 0

quilt

今天終於試用了 quilt,這是一個可以管理 patch 的工具,最早由 Andrew Morton 的一些 script 而來。
專案本來就有寫一些 script 來作 apply 的工作,只是,在想要倒回去或向前的時候,會變得非常麻煩!用 quilt 的話,可以方便的向前或向後。
因為已經有 patch 了,所以施作的方法很簡單,先 import,再 push。

quilt import patch01
quilt push
quilt import patch02
quilt push

之後就可以用 pop 往回推,或用 push 繼續往前了。
小記:坦白說,本來想放棄直接用 git 來作的…因為剛好在看 ProGit,覺得 git 或許會更適用也不一定,不過只是想簡單地往前或往後測試 patch,用 quilt 應該就夠了。
參考資料:

jquery 與 iframe

假設 iframe 的 id 是 f,裡面有個按鈕 id 是 btn,那麼要存取 iframe 裡的元素,可以這樣寫:
[javascript]
// http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/
alert( $(‘#f’).contents().find(‘#btn’).html() );
[/javascript]
再假設父頁面裡有個 id 是 ta 的 text,iframe 裡要存取父頁面裡的元素,有兩種寫法:
[javascript]
// 方法一 (http://webdevel.blogspot.com/2007/03/iframes-and-jquery-working-with-iframes.html)
alert( parent.$(“#ta”).val() );
// 方法二 (http://groups.google.com/group/jquery-en/browse_thread/thread/5997ef4a60a123af?pli=1)
alert( $(“#ta”, parent.document.body).val() );
[/javascript]
不過,在碰到 cross domain 的情況時,就會行不通了。拜 Google 大神 的時候,大神有提到一些解,但我嫌麻煩就沒再去試了…

參考資料:

buildbot

在Ubuntu上安裝Buildbot是很簡單的事情:sudo apt-get install buildbot。

比較麻煩的是設定,大致瀏覽了一下 Manual,還是不知道怎麼設定,轉而找 Google 大神,Mousebender 的這篇Installing buildbot,就很簡單易懂。但由於這篇提供的設定是 2006 年的,現在的設定稍稍有改變,c[‘bots’] 必須修正為 c[‘slaves’],後面會提到。

依據 Architecture,Buildbot必須要有 master 跟 slave,master 負責提供 web 介面跟叫 slave 做事,而 slave 就只聽命令做事,所以設定的時候就要分別設定 master 跟 slave。

master 的設定,得先使用 buildbot create-master [目錄名] 來建立,這會幫你建立一個目錄,並提供你設定檔的範本(master.cfg.sample)。第一步就是要把 master.cfg.sample 改為 master.cfg,然後修改 master.cfg。要調整的基本上有這幾個:

  • c[‘schedulers’],要排程的時間。
  • f1.addStep(),這決定怎麼編譯。
  • c[‘slaves’]、c[‘slavePortnum’],slave的名稱、密碼以及要 listen 的 port,待會建立 slave 時會用到。
  • c[‘projectName’],你專案的名稱。
  • c[‘projectURL’],你專案的網址。

接著要建立 slave,這邊用 master.cfg.sample 來舉例,也就是假設你剛剛沒改 c[‘slaves’]、c[‘slavePortnum’] 的內容,所以這邊用 buildbot create-slave [目錄名] localhost:9989 bot1name bot1passwd 來建立 slave,接著把 slave 目錄下的 Makefile.sample 改為 Makefile 即可。

啟動的時候,要先啟動 slave 再啟動 master,啟動的指令都是 buildbot start [目錄名],例如 buildbot start myproject-master、buildbot start myproject-slave。

這樣就大功告成,你可以打開 http://localhost:8010 來看 build 的進度了。

下面是我的設定檔:

# -*- python -*-
c = BuildmasterConfig = {}
####### BUILDSLAVES
from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave("myproject-slave", "password", max_builds=1)]
c['slavePortnum'] = 9989
####### CHANGESOURCES
from buildbot.changes.pb import PBChangeSource
c['change_source'] = PBChangeSource()
####### SCHEDULERS
from buildbot.scheduler import Scheduler, Periodic
c['schedulers'] = [
Periodic("every_12_hours", ["buildbot-full"], 12*60*60 )
]
####### BUILDERS
from buildbot.process import factory
from buildbot.steps.source import CVS
from buildbot.steps.shell import Compile, ShellCommand
from buildbot.steps.python_twisted import Trial
f1 = factory.BuildFactory()
f1.addStep(ShellCommand(command=["/home/user1/build/build.sh"]))
f1.addStep(Compile())
b1 = {'name': "buildbot-full",
'slavename': 'myproject-slave',
'builddir': "full",
'factory': f1,
}
c['builders'] = [b1]
####### STATUS TARGETS
c['status'] = []
from buildbot.status import html
c['status'].append(html.WebStatus(http_port=8010))
####### PROJECT IDENTITY
c['projectName'] = "myproject"
c['projectURL'] = "http://myproject-server"
c['buildbotURL'] = "http://localhost:8010/"

無法移除的 Powershell v1.0

如果你也跟我一樣,因為要安裝 Powershell v2.0 而無法移除 Powershell v1.0 的話,可以研讀 Powershell team 貼的這篇:Windows PowerShell Blog : Behind PowerShell Installer (for Windows XP / Windows Server 2003):,了解一下 Powershell 安裝程式做了什麼。不過這篇字太多了,我其實是參考這篇:BUGBUG: poor title » Blog Archive » How to uninstall Powershell v1.0 from Windows Server 2003 R2 來移除的,除了 pwrshsip.dll 無法刪掉之外,基本上不刪掉也沒關係。接著就可以上 Powershell v2.0 CTP3 了。
為什麼要上 Powershell v2.0 CTP3 呢?這是因為 SQL Server 2008 Management Studio Express 的緣故。真是太機車了…

Ubiquity 0.5 + findbook

Ubiquity 升級到 0.5 了,Parser API 也升級到了 2,語法有改變,所以參考轉換指南修正了一下之前的 findbook:

CmdUtils.CreateCommand({
names: ["findbook"],
contributors: ["elleryq"],
license: "MPL",
description: "讓買書變成更簡單的決定!",
arguments: [ {role: 'object', nountype: noun_arb_text, label: '書名關鍵字'} ],
icon: "http://findbook.tw/favicon.ico",
execute: function(args) {
Utils.openUrlInBrowser( "http://findbook.tw/search?keyword_type=keyword&q=" + encodeURIComponent(args.object.text) );
}
});

如果你想入門的話,這份文件可以作為參考:Labs/Ubiquity/Ubiquity Source Tip Author Tutorial。
另外,在Ubiquity Command Editor頁面裡也有 command APIs,告訴你有哪些 API 可用。