早上翻譯了這篇:雞尾酒排序,翻譯的不是很好~以後再求改進吧。
順手再寫了 c# 的版本。
public static void cocktailSort( int[] theList )
{
int bottom = 0;
int top = theList.Length-1;
bool swapped = true;
while( swapped == true )
{
swapped = false;
for( int i=bottom; i<top; i++ )
{
if( theList[i] > theList[i+1] )
{
int tmp = theList[i+1];
theList[i+1]=theList[i];
theList[i]=tmp;
swapped = true;
}
}
top = top-1;
for( int i=top; i>bottom; i– )
{
if( theList[i]<theList[i-1] )
{
int tmp = theList[i-1];
theList[i-1]=theList[i];
theList[i]=tmp;
swapped = true;
}
}
bottom = bottom+1;
}
}
FireFox 2.0 RC1
把公司的 FireFox 改用 2.0RC1,Extension 詳列如下:
- 2.0 仍可使用者:
- DOM Inspector
- Talkback
- Adblock Filterset.G Updater
- CustomizeGoogle
- IE Tab
- Image Zoom
- PDF Download
- Web Developer
- FlashGot
- 新同文堂
- Download Statusbar
- Adblock Plus
- ColorZilla
- Google Toolbar for Firefox
- Google Browser Sync
- 不相容 2.x:
- del.icio.us
- Fasterfox
- Hypertext DOM Browser
- Furl Tools
- Copy URL +
- Greasemonkey
- CSSViewer
- Screen grab!
- gmif
- Tabbrowser Preferences
目前一切順利,不過少了一些如 del.icio.us、furl.net、Copy URL+等等的方便工具,還真是麻煩~
VFP 與 Regular Expression
VFP 本身並不支援 Regular Expression,幸好,有人非常熱心,以 C/C++ 有名的 Boost library 為基礎,製作了給 VFP 用的 Regular Expression Library。
License 基本上是遵循 boost library 的 LGPL license,所以你可以直接使用 binary code (也就是 .fll)在商業用途上。
為甚麼要 Regular Expression?因為他可以很方便地以簡單的語法表示出一段文字的規則。
以文章裡面的範例來看,你會發現他真的好用~
*!* 驗證 email 信箱格式
lcExpression = “^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$”
?RegExp(“john@isp.com”,lcExpression)
?RegExp(“john@.isp.com”,lcExpression)
*!* 驗證金額
lcExpression = “^(\$)?(([1-9]\d{0,2}(\,\d{3})*)|([1-9]\d*)|(0))(\.\d{2})?$”
?RegExp(“$1,244,311.81”,lcExpression) && Match
?RegExp(“$1,24,4311.81”,lcExpression) && No Match
*!* 驗證電話號碼
lcExpression = “^[2-9]\d{2}-\d{3}-\d{4}$”
?RegExp(“507-562-0020”,lcExpression) && Match
?RegExp(“507-56-0020”,lcExpression) && No Match
基本規則說明可以直接參考洪朝貴先生發佈的文章。
參考資料:
My poor thinking about PMP
Sangria
調酒最麻煩的就是湊材料,說真的,我很懶得去湊這些材料~
以前對這真的很有興趣,只是從來都沒去湊這些材料,只弄過一些比較簡單、比較容易取得材料的調酒~
這個雞尾酒的作法摘錄自小玲&阿秀 的部落格:冰涼夏日雞尾酒(Sangria),那邊也提供有照片喔。
White Sangria材料:
乾白酒(Spanish dry white wine)1瓶、白萊姆酒(white rum)1/4杯、Grand Marnier 1/4杯(可加可不加)、柳丁1個(對切、再切成薄片)、萊姆(lime)1個(切成1/4、再切成薄片)、哈密瓜丁或香瓜丁2杯、檸檬萊姆蘇打水(natural lemon-lime soda)3杯。
Red Sangria材料:
乾紅酒(Spanish dry red wine)1瓶、砂糖1/2杯、白蘭地(brandy)1/2杯、Grand Marnier或Cointreau 1/2杯、柳丁或檸檬或萊姆2-3個(對切、再切成厚片)、青蘋果1個(切成1/4、去核、再切成厚片)、檸檬蘇打水3杯(natural lemon-lime soda)。
作法:
1. 把除了蘇打水以外的所有材料加入一個玻璃酒壺(pitcher),放入冰箱冷藏至少5小時或隔夜,等到要飲用之前才拌入蘇打水。
2. 把調好的Sangria倒入冰過的玻璃杯,並加入少許柳丁片、檸檬片、水果丁,就可以盛上桌了。
分娩緊急應變計畫
一直都要擬這份計畫,可是一直不知道怎麼擬比較好。
後來想到,Use Case 就很適合啊~
但是整個寫完以後,心情有點小沈重,因為 Use Case 必須考慮到最糟的狀況(最小事後保證),這部份不太敢去想,不過我還是寫出來了。
寫完以後,心裡一直祈禱,一切都會很平安的。
*簡介:老婆要生產時所要採取的措施
*參予者:醫生、護士、老婆、我、計程車
*觸發事件:
1.有出血狀況
2.破水
3.規則性陣痛
*最小事後保證:媽媽平安
*成功事後保證:孩子安全生出來,母子均安
*成功情節:
1.老婆通知我
2.老婆或我打電話叫計程車
3.老婆或我通知醫生
4.攜帶待產時所需物品,計程車將我們送往醫院
5.醫生進行診斷及狀況判斷
6.醫生、護士、老婆進產房,醫生決定我可進去陪產
7.寶寶順利誕生
*替代流程(擴充情節):
1.1 分隔兩地時,以電話通知。
1.2 時間允許的話,老婆先行清潔身體。(孕婦的期望)
2.1 無法叫到計程車時,撥打 119,步驟 4 的計程車即以救護車代替。
3.1 無法通知到醫生,請岳母幫忙通知(岳母認識醫生)
3.2 無法通知到醫生,逕行通知醫院,請醫院代為聯絡。
4.1 物品未攜帶,可請母親稍晚幫忙帶到醫院。
4.2 物品未攜帶,直接在醫院附近購買。
6.1 我無法進入產房,在產房外等待。
7.1 生產不順利,改以剖腹。
7.2 最糟的情況,以老婆性命為重。
WinMerge Filter
無意中看到這篇:WinMerge檔案濾鏡的使用方法,於是動手幫WinMerge加了這個濾鏡,這下子,比對檔案的時候可是快多了!
怎麼新增?
[Tools][Filters],再選 New,WinMerge會開出記事本,把下面內容貼上,存檔。
怎麼使用?
比對時,Filter選為剛剛加入的 cpp_with_cvs 或是自己輸入 [F]cpp_with_cvs,進行compare 即可。
## This is a directory/file filter template for WinMerge name: cpp_with_cvs desc: For company usage. ## Select if filter is inclusive or exclusive ## Inclusive (loose) filter lets through all items not matching rules ## Exclusive filter lets through only items that match to rule ## include or exclude def: include ## Filters for filenames begin with f: ## Filters for directories begin with d: ## (Inline comments begin with " ##" and extend to the end of the line) f: \.bak$ ## 備份檔 f: \\~*$ ## 備份檔 f: \\#*$ ## WinCVS 的備份檔 f: \.map$ ## .map, .rom, .axf 都是編譯的產出物 f: \.rom$ f: \.axf$ f: \ChangeLog$ ## ChangeLog 也不要 d: \\CVS$ ## CVS下的檔案不用比對 d: \\\.OBJ_RELEASE$ ## 這兩個都是編譯時的產出 d: \\\.OBJ_DEBUG$
SharpDevelop2 + IronPython + PythonBinding
現在你可以用 SharpDevelop2 開發 IronPython 應用程式了。
1.首先下載PythonBinding,目前最新的版本是 0.5Beta。
2.解開,這裡我是將解開後的檔案放到 c:\tools\pythonbinding
3.打開 SharpDevelop2
4.[Tools][AddInManager],選 Install AddIn
5.指向剛剛 c:\tools\pythonbinding\PythonBinding.AddIn,接著按下 Close。
6.關閉 SharpDevleop2,重新啟動。
接下來,你可以 New Solution,就會看到 Python 的部份
所以請新增一個 console application,這裡我命名為 hellopython。
這個新的專案裡面已經有個 Program.py 了,他只簡單的印出 “Hello world”。
這時候很直覺的按下綠色的三角形,也就是執行,SharpDevelop2 會很直接的告訴你有問題。
The “IronPythonCompilerTask” was not given a value for the required parameter “Mainfile”. (MSB4044)
你需要修改一下專案的屬性:以滑鼠右鍵點選左邊的專案,然後選 Property,依照下圖將 Start Object 修改為 Program.py
再次按下執行,SharpDevelop2 很順利地 build 完成,但卻仍然無法執行,SharpDevelop2 會這麼告訴你:
Exception System.ArgumentException was thrown in debuggee:
The path is not of a legal form.
NormalizePathFast()
GetFullPathInternal()
GetFullPath()
ExecuteCompiled()
Main()
可是我以 console 模式去執行編譯出來的 HelloPython.exe,卻可以執行。
後來仔細看了一下工具列,原來按下紅色的驚嘆號就可以順利執行了。
我想應該是 SharpDevelop2 還不支援 IronPython 的除錯模式的關係。
此外,目前也還不支援 Auto completion(自動完成),我想這部份應該很快就會被 release 出來了吧。
參考資料:
用 python urllib 擷取網頁
就是用 urllib 來作。
下面的程式有點笨,應該可以寫的更好。
import urllib page=urllib.urlopen("http://www.google.com.tw") while 1: line=page.readline() if line: print line else: break
參考資料:
用 python 來複製 n 個相同的檔案
為了要將某個檔案複製出 500 份,寫了一個簡短的 python script。
很簡單,卻花了我不少時間查可用的 function。
range() 的行為跟我預期的有些不一樣,range(2,500)實際上是 2~499,並不會真正到 500。
所以 2~500 必須寫成 range(2,501) 才行。
import os import shutil n=501 for i in range(2,n): filename='%04d.mp3' % i shutil.copyfile( '0001.mp3', filename )