星期五, 4月 28, 2006

[亂逛]快和星一樣笨

今天看到這則新聞,看完以後只有幾個感想:
1. 爛標題:快和星一樣笨,我很難聯想到"星"是指新加坡。看完以後,才發現原來說的是歷史教材,或許是說新加坡的歷史教材較差,但是不懂歷史等於笨?
2. 甚麼是"誰對民主政治毫無貢獻"的標準答案?一個爛題目再加上一個爛解答...

我輸了...Orz...

Yahoo!News1146216958992

[.Net]資料繫結與巡覽

資料的繫結基本上都是靠 Controls.DataBindings,所以
text1.DataBindings.Add( new Binding("Text", ds, "customers.custNo") );

就可以把 text1 這個控制項的 Text 屬性繫結到 ds.Tables["customers"] 的 custNo 欄位上。

如果想要有一些處理與變化,那麼可以透過 Binding.Format 與 Binding.Parse:
Binding b=new Binding("Text", ds, "customers.custOrder.OrderAmount");
b.Parse+=new ConvertEventHandler( currencyStringToDecimal); // currencyStringToDecimal 是自訂的
b.Format+=new ConvertEventHandler( DecimalToCurrencyString ); // DecimalToCurrencyString 也是...
text3.DataBindings.Add(b);

這表示在轉換控制項屬性到資料來源的時候,會透過這兩個事件作變化。
Parse 表示控制項到資料來源,而 Format 正好相反。

都繫結上了以後呢?我們可以透過 BindingManagerBase 來作巡覽。
BinderManagerBase bm = BindingContext[ dataset, "tablename" ];

此時可用 bm.Position 取得位置,bm.Current 取得當前的物件(如果資料來源是 datatable,那就是 DataRowView;若是陣列,那就是所指向的元素)
bm.Position+1 就是下一筆,反之則是上一筆。到了最後一筆的時候,bm.Position+1 以後仍然會是一樣。

那麼,位置移動的時候會觸發甚麼事件?PositionChanged。所以我們可以撰寫自己的處理事件,
PositionChanged+=new EventHandler( this.fmMain_PositionChanged )


不僅僅是 TextBox 可以作,只要有提供 DataBindings 屬性的控制項都可以。
把 Button 的 Text 屬性 Bind 到某資料來源的某欄,而 Enable 屬性又 Bind 到 某欄時,那麼當移動資料來源位置的時候,就可以讓 Button 的相關狀態自動改變了。
這讓我想到似乎可以作一些 state machine 的東西...

星期二, 4月 25, 2006

[.Net]IDeserializationCallback.OnDeserialization()

在 deserialization 之後,需要做的一些處理可以寫在這裡。
.Net framework documentation 裡面的例子是以 Circle 類別作例子,圓的面積不 serialize,而是在 deserialize 之後再計算出來。

星期五, 4月 21, 2006

[Note]霍元甲

這部電影應該可以拍的更深沉,我想或許該拍的都拍了吧,只是沒剪出來。
這是蠻可惜的。

覺得裏面挺不錯的幾句話:
  • 人心裡不好受,就得哭,哭完了,你還得上路。
  • 人呀,要時常洗洗自己,這樣才能清爽地走在世上。
  • 秧苗也是有生命的,它們之間不能靠得太近,近了就會妨礙生長,就像我們人,生活中要懂得互相尊重,這樣大家才能活得平安快樂。
  • 茶品的上下高低,並不是由茶來對我們說,倒是由人來決定的,不同的人有不同的選擇。
  • 喝茶是一種心情,如果你心情中了,茶的高低還有這麼重要嗎?
  • 最可怕的競技在自己內心?

NAnt (2)

After read previous post, I guess you will feel that nant is wonderful. Because the code is very less. Perfect!
But for Q, it is not.

Q heard that .Net had ported to Linux, So he want to use NAnt to build his project in linux.
Q installed mono, then installed NAnt.

The installation of NAnt in linux is easy, just unzip it, rename it to nant and put it in /opt. (/opt/nant.)
Q copied whole project to Linux home directory, and modify the following line in the build file
<property name="nant.settings.currentframework" value="net-1.1"/>

To
<property name="nant.settings.currentframework" value="mono-1.0"/>

This line tell NAnt should switch compile environment to mono before building.

Then enter the following line:
$mono /opt/nant/bin/NAnt.exe

And NAnt said,
Invalid element <solution>. Unknown task or datatype


Q was sliently crying to accept this fact, he know he should learn more for coding build file.




A NAnt build actually is a XML file, the basic element is project, project contains target and property, and target contains tasks.
Here is an empty build file:
<?xml version="1.0"?>
<project name="dnsedu" default="build">
  <property name="nant.settings.currentframework" value="net-1.1"/>
  <target name="build" description="Default build target" depends="dnsedu">
  </target>
</project>

There are lots of tasks provided by NAnt.
You can refer to the official site: Task Reference
Beside basic commands: csc, vbc, cl, al, ilasm, resgen, NAnt also provide these tasks: copy, cvs, mail, nunit ... and etc.
I think these tasks are enough to code a powerful build file.

Now let's rewrite the build file in previous post, and we will use the 2 tasks: csc, mkdir. (I suppose that you use c#)
<project name="your_project" default="build">
  <property name="nant.settings.currentframework" value="mono-1.0"/>
  <property name="debug" value="false"/>
  <target name="build">
    <mkdir dir="bin" unless="${directory::exists('bin')}" />
    <csc target="winexe" output="bin/your_project.exe" debug="${debug}">
      <sources>
        <include name="*.cs"/>
      </sources>
      <references>
        <include name="System.Drawing.dll" />
        <include name="System.Data.dll" />
        <include name="System.Windows.Forms.dll"/>
      </references>
      <resources>
        <include name="*.resx"/>
      </resources>
    </csc>
  </target>
</project>

mkdir task: Here I use unless attribute, it means "if not". So this line means if specified directory is not existed, make it. If you want to know more, you can refer to Function Reference.

In csc tasks, you need to specify the target, output and debug information.
Inside csc tasks, you need to specify references, sources and resources.
That's easy, right?

These are the basic things, next time let's talk about Web Application.

[Lyrics]Ah Ah / 四季

為甚麼原住民的歌聲永遠那麼嘹亮動聽有力道?
aLin 的這首 Ah Ah 就很 powerful。

Ah Ah
作詞:Anna Tsuchiya
作曲:paul Rein
編曲:周顯哲
主唱:aLin

All the girl, wish to be sexy
Preny red dresses & high hells
Put lip stick on and make me high
How gorgeous I am

I really love myself
Let's just be sype cute girls
I don't need expensive things
You want me but you can't have it

lady come on join the party 'Dance Dance'
Show me how you're 'Movinq'
that have a crush on you
Baby you're enslaved by my cheam 'No No'
I don't mind 'Ah Ah'
Nobody can stop me

Most of the girls wanna have fun
Going to clubs in the night time
My mom was always angry at me
But when she was young, she was hot

I really love myself
Let's just be super cute girls
I don't need expensive things
You want me but you can't have it

They give me diamond ring 'Bling Bling'
But they're nothing 'To Me'
Cause I'm muc much more
Yes, you can't buy me 'No No'
Different from'The Others'
Nobody can stop me


四季Four seasons
中文詞:Alin
作曲:Mad Soul Child
編曲:林於賢
主唱:aLin

明明是春天我卻感到絕望
夏天來臨了我還是看不見陽光
秋天的落葉將往事都埋藏
準備好冬天將你的一切都遺忘

我的愛情 已折斷了翅膀
無法繼續飛翔 在風裡飄飄蕩蕩
等待天亮 好好大哭一場
再讓眼淚風乾 在微笑中釋放

走過四季 是你給我的力量
當我覺得孤單沮喪害怕還依然能堅強
不管四季 如此無情的交替 我已不寂寞
因為你和我曾多麼快樂

你走了以後日子是否無恙
是不是有誰代替我陪在你身旁
你住的城市陽光多麼燦爛
可曾想起我正一個人面對孤單

我的愛情 已折斷了翅膀
無法繼續飛翔 在風裡飄飄蕩蕩
等待天亮 好好大哭一場
再讓眼淚風乾 在微笑中釋放

走過四季 是你給我的力量
當我覺得孤單沮喪害怕還依然能堅強
不管四季 如此無情的交替 我已不寂寞
因為你和我曾多麼快樂

如果沒有你 現在我會在哪裡
過著怎樣的生活 會不會也寂寞

走過四季 是你給我的力量
當我覺得孤單沮喪害怕還依然能堅強
不管四季 如此無情的交替 我已不寂寞
祈禱這世界 祝福我們所有一切
因為你和我曾多麼快樂

星期四, 4月 20, 2006

NAnt (1)

Before .Net 2.0, if you don't use IDE to build project, and you want to use a simple command to build project, you have 3 options:
  1. write your own batch file
  2. Makefile
  3. NAnt

After .Net 2.0, you have another option: msbuild.

NAnt series articles are focused on NAnt, but why NAnt ? Why use NAnt??
Because I want.

Cross platform? Makefile, msbuild (mono had ported and named xbuild) can do this too.
Simple? I think Makefile is simpler than NAnt.
Functionality? msbuild is powerful too.
So I say, "Because I want.".

Ant is a very important tool on java platform, so NAnt team port Ant to .Net and name "NAnt", it means .Net Ant.
The official site is at http://nant.sourceforge.net
After you download and unzip the zip file, you can use it, no more special installation steps, even Linux.
I suppose you put the unziped files in c:\tools, and named "nant".

No more nonsense words. Let's start the first sample.
I think that lots of people are used to develop with Visual Studio.Net.

So, create a windows form project and make sure it can be built. (Or you can try your project.)
Then create a text file in project directory, and named "your_project.build" (yes, "your_project.build" can be replaced.)
Put the following text:
<?xml version="1.0"?>
<project name="your_project" default="build">
<property name="nant.settings.currentframework" value="net-1.1"/>
<target name="build">
<solution configuration="release" solutionfile="your_project.sln" />
</target>
</project>


Save the file, then enter command prompt, type
c:\tools\nant\bin\nant


That's all.
Why is this sample so simple? Because NAnt can parse Visual Studio solution file after 0.85.2296.
Just use the task: solution, and NAnt will parse the solution file and build.
But unfortunately, NAnt don't support Visual Studio .Net 2005 yet, even the latest version.

星期四, 4月 13, 2006

[Lyrics]我愛台妹

昨天才聽到這首歌,聽完之後只有一個感覺:這真是太屌啦!!
直接列為練習歌曲,下次去KTV點唱。

以下參考自:認真的台妹最美麗,愛台妹才是真男人

歌名:我愛台妹
作詞:姚中仁/張震嶽
作曲:姚中仁/張震嶽
演唱:Mc Hot Dog、張震嶽

我的阿妹妹 快來和我跳阿哥哥 Go 我知道你看到是我 妳不會說No
我不是油頭葉教授 我的homiez都叫我熱狗 4 sure
女孩 就是喜歡妳台台 等等去家裡home pa要不要來
只怕你掛的太快 明天要去廟裡收驚拜拜 How High ?! We can kiss the sky!
人生海海 我們不會只是stand one night 『one night in 墾丁..我留下許多情..』
你是我的可口可樂 幫我解渴 看我穿著就知道我玩饒舌
不要說我壞話 因為我有順風耳 如果是你肚子大我帶你去看順風婦產科

我愛台妹 台妹愛我 對我來說 林志玲算什麼?!
我愛台妹 台妹愛我 對我來說 侯佩岑算什麼…..

我不愛中國小姐 我愛台妹 萬萬歲 妳的檳榔2粒要100 好貴 有沒有含睡
如果能夠和妳共枕眠 更多更多的奶粉錢 我願意為妳貢獻 我不是愛現
請妳噴上一點點銷魂的香水 換上妳最性感的高跟鞋 人群之中 妳最亮眼
台妹來了 我是否和妳一拍即合 跟我去很多的不良場合
大家看到我都對我喊yes sir 因為我是公認最屌的rapper
台妹們 麻煩和我拍拖 我不是凱子 可是付錢我也不會囉唆
純情是什麼 我不懂 我的想法很邪惡 張震嶽他懂

我愛台妹 台妹愛我 對我來說 林志玲算什麼?!
我愛台妹 台妹愛我 對我來說 侯佩岑算什麼…..

為了妳 我可能要投資一家檳榔攤 為了妳 家裡可能要有鋼管
為了妳 我要常常下去台南 為了妳 流氓會來找我麻煩
對於帶著一點風塵味的女生 我的腎上腺素毫不考慮亮起紅燈
畢竟妳不是天使 我也不是聖人 時尚的野獸 那就請你滾 我受夠
你是馬戲團訓練有素的animal 所有男模 女模 你在屌什麼
我就不信你現在還有處女膜 都是凱子搓
我喜歡台妹說話的口音 有時候挾帶幾句口白三字經
愛神的箭 你要射向哪裡 這裡 張震嶽 free9熱狗 這裡 等你

我愛台妹 台妹愛我 對我來說 林志玲算什麼?!
我愛台妹 台妹愛我 對我來說 侯佩岑算什麼…..
我愛台妹 台妹愛我 對我來說 林志玲算什麼?!
我愛台妹 台妹愛我 對我來說 侯佩岑算什麼…..

把手放在空中甩 我叫你什麼都不用管
讓我看妳把手放在空中甩 把手放在空中甩
台妹 手放在空中甩 叫你什麼都不用管
叫你把手放在空中甩 叫你什麼都不用 Ya
台客 手放在空中甩 把手放在空中甩
我讓你感受 這個節奏 身體跟著擺動
這是free9 張震嶽 熱狗 要你跟著我們怒吼
一切都是假象 不是你們想像
我愛台妹 我愛台北 就像這樣

星期三, 4月 12, 2006

[Lyrics]我愛夏天

今天閒逛的時候,發現張國璽要去開飛機了...看這邊...
跟著來串聯祝福他吧~~
串聯祝福送Mojo!!

我永遠都會記得這首專屬於夏天的歌,還有最適合這首歌的主唱...

歌名:我愛夏天
主唱:脫拉庫
作詞:張國璽
作曲:張國璽

我 我愛夏天
有 漂亮美眉
我 我愛夏天
因為 她們穿的養眼
每到夏天我要去海邊 海邊有個漂亮高雄妹
只打電話不常見面我好想念 不知她會在哪個海邊

(1、2、3、4)
我 我愛夏天
有 漂亮美眉
我 我愛夏天
因為 她們穿的養眼
每到夏天我要去海邊(去海邊) 海邊有個漂亮高雄妹(高雄妹)
只打電話不常見面我好想念 不知她會在哪個海邊

我 我愛夏天
有 漂亮美眉
我 我愛夏天
因為 她們穿的養眼
每到夏天我要去海邊(去海邊) 海邊有個漂亮高雄妹(高雄妹)
只打電話不常見面我好想念 不知她會在哪個海邊

每到夏天我要去海邊(去海邊) 海邊有個漂亮高雄妹(高雄妹)
只打電話不常見面我好想念 不知她會在哪個海邊

星期二, 4月 11, 2006

[Linux]Firewall: lokkit 的設定

進入 console mode 之後,輸入 setup
選到 Firewall configuration (或直接輸入 lokkit)
再選 customize,至此即可設定允許哪些協定進入你 linux 防火牆。

到 Allow incoming 那邊,將協定勾選(按空白鍵勾選,Tab鍵切換)。
如果沒有列出來的,你可能要在 Other Ports 那欄自行輸入。
格式大致是這樣:
protocol_name:[tcp|udp]

拿我家裏的 server 來說,除了勾選 HTTP、SSH 之外,我還自行輸入了
pop3:tcp https:tcp netbios-ssn:tcp microsoft-ds:tcp netbios-ns:udp netbios-dgm:udp

不知道有哪些 protocol 的話,可以用 netstat -a 自己去看。
我也是嘗試之後,才發現 Other ports 那欄的輸入格式可以參考 netstat -a 的結果。

星期四, 4月 06, 2006

[.Net]Some mono news

MonoDevelop Releaes 0.10 版啦~
這次提供了 GUI designer 了喔,也可以作 Refactoring ~~
另外還有我小小的貢獻:zh_TW 的翻譯 :-p
詳情可以看 Release notes for MonoDevelop 0.10.

看了Tracking Performance in Mono才知道,原來已經有個大學從 2004 年開始就在進行追蹤 Mono 效能,並且提供了詳細的報告呢。
報告的網址:Regression Tests - MONO Regression Benchmarking

星期一, 4月 03, 2006

[.Net]TheServerside.Net 訪談 Miguel De Icaza

Q and A with Miguel "Mono Man" De Icaza
這是一篇訪談,對象是Mono專案的 leader,裡面提到很多關於 Mono 的現況與未來發展.

稍微整理一下我看到的:
  1. 1.2 beta 1 將會在四月釋出,最主要要完成的是 Windows form 1.1 的部份.
  2. vb.net compiler, 實做狀況不佳,因為 Linuxer 都對 c# 比較可接受,但是你可以先在 windows 編譯好 il (assembly)再拿到 mono 上用.
  3. 有討論到關於 object pascal / iron python / ruby 的一些事情.
  4. 對 .Net 2.0 的支援, c# 2.0 compiler 都已經完備了, 目前少的是 2.0 的類別庫. 在1.2之後,他們會排定開發順序.

星期日, 4月 02, 2006

[Cook]豆腐布丁

在國興衛視台看一萬元生活時記下來的,作法很簡單,不過卻還沒做過,因為很懶得拿果汁機出來。

作法:豆腐以果汁機加水打碎,再加適量的蛋與糖攪拌均勻,放到電鍋裡去蒸即可。