Downtime

Kalunite.net and all sub-sites may be down for a few days from January 24th onwards while I migrate everything to a dedicated server in Hong Kong. The new server shall shift the access speed in the favour of visitors from the Asia-Pacific region, possibly at the expense of visitors from North America. Check back in a week or two and hopefully everything will be up and running smoothly again by then.

Short咗

星期日行街行到腳仔軟。先係朝早同屋企人响荃灣兆和街嘅合發茶餐廳喫早餐,跟住我同家姐疙咗去如心廣場睇吓落成咗係乜樣。點知原來咩都冇,得間酒店開咗。隔離荃新天地又係未裝修完。結果唯有走去荃灣廣場行Jusco。不過一入廣場門口,就俾Wanko雞乸咁大隻字嘅「二折」牌嗍咗埋去。就咁樣就開咗市,家姐即刻搵到聖誕禮物俾阿媽同係Montreal嘅死黨同學。跟住再上幾層,喺間DVD/唱碟鋪搵埋老竇嘅禮物。Jusco嗰度反而乜都冇買就走咗。

第一回合完,就哽係食嘢補充能量。上次喺綠楊食越南河,發然仲有好多檔可以試。所以今日又番去綠楊,試另一檔唔知”Euro”乜鬼嘅(家姐溫馨提示:「係EuroGoGo呀。」)。啲意粉都OK,係嗰兩支奇異菓汁同橙汁甜咗少少。

補給完,我地就先分道揚鑣:家姐去銅鑼灣會合企鵝姐,開始佢嘅第二回合;我就去展開我嘅旺角探險。點解去旺角?因為我隻踎屎死咗。讀者一定諗:『踎屎死咗關旺角咩事呀?』。咁我就話你知啦。話說PCCW寄咗封信嚟話多謝我申請寬頻,所以送無綫踎屎,要去旺角挪。不過我點會淨係為咗隻踎屎去旺角丫。前世未迫過咩。其實我主要仲想搵OS X Leopard Family Pack,買番隻模型鉗,同撞吓仲搵唔搵到MG版F91。模形鉗喺烟廠街嗰邊好易搵。有個店員同我講有田宮兩款一貴一平,仲話貴啲嘅唔會咁易剪崩。我話「唔係啊嘛?剪膠咋啵。」所以最後去咗Modern買把最平嘅(50蚊)。隻F91我差啲搵唔到,得番一間有一千零一隻。原來因為唔好賣,好多鋪都冇再入貨。Leopard搵到我傻。出街前我就明知唔熟旺角,去中原地圖睇過信和中心同旺角電腦中心大概係咩位置。點知…去到旺角兜到我傻,嗰度啲遊客資訊牌又退晒色,都睇唔到啲街線,淨係睇到街名。Sino同MKCC又攪笑到冇牌嘅。攪到我問咗幾次啊sir先搵到MKCC。最後我見MKCC兩間有賣Apple嘅都斷Leopard嘅貨,知道冇機,就連Sino都放棄搵就去咗銅鑼灣join家姐同企鵝姐。去到銅鑼灣先發現佢地係搵我去破財擋災。家姐買咗對平平地嘅太陽眼鏡唔駛一個鐘就買咗兩件幾形嘅黑色casual恤衫自己著同兩條呔送比Montreal嘅朋友;咁就900蚊。跟住去睇吓有咩形戒指補番老竇唔見咗嗰隻。不過最後冇買,淨係睇咗款,因為我地唔肯定老竇手指咩嘥屎,刻咗名嘅話又冇得換;要等我地噠老竇其它戒指嚟度吓先。企鵝姐見我地攪咁耐,就游咗去第二檔睇衫,仲執到筍嘢。

之後就去咗SOGO睇玩具。原來我真係大鄉里,依家先知Sylvanian Family系列咁誇張嘅。酒店,水車,菓汁檔,你諗到就有。一傾之下,先知道企鵝姐玩得仲pro。佢嫌Sylvanian Family本身嗰幾款屋太細,所以用Hello Kitty嘅一款大屋代替。真係orz。我仲好奇想睇吓SOGO有咩Gundam貨,一睇之下先知佢食水深;隻F91我喺旺角買先168蚊,喺SOGO要259蚊。

行到攰,又到食嘢時間。去咗檔佈置得幾有越南feel嘅餐廳。叫咗牛肉河,燒豬肉檬,炸春卷,仲有招牌炸雞翼。每人70蚊左右埋單。

跟住家姐順便係藥房買牙刷,然後就分手番屋企。

番到屋企,由於眞係太攰,發生咗啲好hard plastic嘅事…

我好心急咁打開合F91睇說明書,見到呢幅嘢:

當時腦入邊嘅反應係『死嘞。唔記得買較剪添。』

One thing about Mac OS X that annoys me.

Keyboard input methods – this is one thing that has been bugging me since my switch to Mac OS X.

Actually it is more like 3 problems.

The first one is the way I have to cycle through input methods using Cmd+Space and Alt+Cmd+Space. I know 4 languages (Chinese, English, French, and Japanese) and as a result use 7 keyboard layouts/input methods daily (English, French, Simplified Chinese Pinyin, Traditional Chinese Pinyin, Cantonese Pinyin, Hiragana, Katakana). Cycling through the keyboard layouts and input methods is becoming tedious. I still prefer the Windows way, where I can assign a keyboard combination (e.g. Alt+Shift+1) to each keyboard layout and input method.

The second problem is the lack of official support for non-West-European input in the X11 environment. All attempts to build, install, and use UIM or SCIM have been unsuccessful.

Finally, the Traditional Chinese Pinyin input method seems to be a bit quirky. Sometimes it tends to feed out the wrong character. For instance, typing “zhang1” gives me “章” among the candidate characters, but if I select that character, the input method sometimes feeds the “杖” character instead.

Apple, please tackle these problems in the near future. I believe it will do you good in expanding your market in East Asia.

引越しました

今日新大久保からひばりヶ丘に引っ越しました。すごく暑い日でした。さらに荷物が沢山すぎるので、二回往復しました。シャッツは完全に汗に浸っていった。

新しい家はハウスシェアです。今部屋が足りないから、この三週間は友達と同じ部屋に住んでいる。後ドイツルームメートは故郷へ帰るので、そのときもう一つの部屋がある。

Today I moved from Shin-Ookubo to Hibarigaoka. It was really hot today. Furthermore, because we had too much stuff to move, we had to do another round trip. My shirt got all soaked in sweat.

The new home is a house share. Since there is not enough rooms right now, I’ll be sharing a room with my friend for 3 weeks. After that, the German roommate is moving back to her hometown and we will have another room.

東京に到着!

四日前に東京に着いた。ここは本当にでかい都市です。東京の市区だけでは全香港と同じぐらい大きさかも知れない。まあ、その感じです。

そして。。。昨日の朝は鼻血が出た。少し吃驚した。「大丈夫かなー。まだ三日でしたぞ」っとおもった。

もし文法が間違えば、私を改めて下さい。

I arrived in Tokyo 4 days ago. This is a really huge city. Perhaps just the urban area of Tokyo is about the same size as all of Hong Kong. Well, that’s the feeling I get anyway.

And then… yesterday morning I had a nosebleed. I was a bit surprised. I thought “Woh, am I ok? It’s only been 3 days!”

The Real Origin of the Canadian “eh?”

Here is my take on the origin of the Canadian “eh?”

The French keyboard layout.

When you want to type in French, the easiest way is to switch to the French keyboard layout, instead of using the Alt + 0XXX codes for the accented vowels and the c-cédille. However, once you switch to the French keyboard layout, some other keys, such as the forward slash (/), become harder to find, so we Canadians in the French speaking provinces often switch back and forth between the English and the French layouts. Sometimes, though, we forget to switch back from the French layout to the English layout. And this is what happens when you ask a question in English, while typing with the French keyboard layout:

“So you want to go to China Town tonightÉ”

You see that “É” at the end of the sentence? That’s what happens when you try to type out the question mark (Shift + /). In the French keyboard layout, that key combination gives you the e accent aigu instead of the question mark.

The sentence ends up being read as “So you want to go to China Town tonight, eh?”

And that’s how the Canadian “eh?” was born. 🙂

Facebookers Against Irrelevant Facebook Groups

Yesterday I finally caved in to peer pressure and joined Facebook. Immediately, I find myself disappointed by its Groups feature. Frankly, it’s nothing more than a huge mess, with a really bad signal-to-noise ratio. Many irresponsible kiddies create groups that are irrelevant and off-topic with respect to the group types. Why shall anybody suffer browsing through 300+ irrelevant groups just to find the proper ones about Ajax and Ruby on Rails? Stop the injustice!

If you feel the same as I do, you are welcome to take part in the protest and join the Facebook group I have created: Facebookers Against Irrelevant Facebook Groups.

How you can help the cause immediately:

  • Right now the group is missing a proper logo. When you join, feel free to use your creative talent and contribute by uploading a logo of your own creation.
  • Digg this story, or submit it to your favourite community news/bookmarking site. Please pay attention to proper categorisation.
  • Invite your Facebook friends.

Hopefully the group can grow into a large enough number to get the attention of the Facebook administrators.

Date and Time in PHP 5 and MySQL 5

Time for a little technical post.

Date and time manipulation are one of the most common components in web applications. This is true for a few reasons:

  1. Web applications can have users coming from anywhere around the globe, under many different timezones.
  2. Chances are that you receive date and time information when the user does something. For instance, a user sends an e-mail and there is a timestamp in the message header.
  3. Chances are that you want to do something about the timestamp. For instance, sorting e-mails according to the timestamp before showing them to the user.

Unfortunately, the PHP date and time manipulation functions are anything but properly documented by the PHP documentation team. This causes a lot of grief and frustration among novice PHP programmers. Here, I will talk about how to handle dates and times in a PHP 5 + MySQL 5 setup.

Always store dates and times in the UTC timezone.

This is a good idea for 3 reasons:

  1. The UTC time reference is the most precise and least debatable there is on Earth because it is based on atomic time and takes the Earth’s rotation speed into account for compensation. Furthermore, it has never been, is not, and will never be subject to the daylight saving rule.
  2. The UTC is already the preferred reference timezone among application developers. The Unix Epoch, for instance, starts on midnight of January 1st, 1970, UTC time. Therefore, storing dates and times in UTC will allow easier interoperability with other applications right off the bat.
    1. A consequence of the above is that robust conversion routines to and from UTC is likely to be available in any programming language you pick (including PHP).
  3. You never know when you may need to move or deploy your web application to a host on a different timezone, therefore you don’t want to rely on the server’s timezone for storing and converting dates and times.

Dealing with date and time in PHP 5

Let’s face it, the php.net documentation sucks. One of the issues I see in it is that it fails to adapt to the OOP paradigm. It’s a shame that OOP has been introduced to PHP 4 and 5, and yet the documentation is still largely function-oriented. PHP 5 comes with a class library, but most people whom I have talked with do not know how to use it because the classes are not well documented. As such, most PHP 5 projects are still largely procedural. My goal here is to bring you a little bit of enlightenment by explaining how to use those classes.

  1. First, you need to create an object to represent the timezone. This step is not strictly necessary, but is recommended because in a globally connected world, a time value by itself is meaningless. The DateTime constructor can optionally take it as an argument, which is the way I recommend you to use it.
    $timezonename = 'America/Montreal'; 
    $mytimezone = new DateTimeZone($timezonename);

    Note that $timezonename can be any timezone name supported in the Olson timezone database (a.k.a. zoneinfo) or any of the few extra ones. You can see the full list in Appendix I of the php.net documentation.

  2. Only then do you create the DateTime object.
    $datetimestring = '2007-03-13 23:10:00';
    $mydatetime =
      new DateTime('2007-03-13 23:10:00', $mytimezone);

    The exact acceptable format of $datetimestring is the same as the GNU Date Input Formats, in case you have not found out from the php.net documentation already.

  3. Now, let’s try outputting it as a string. The bad news is that you should not do echo $mydatetime; The good news is that you can decide what string representation to take by using the DateTime::format() method.
    $mydatetimeformat = 'Y-m-d H:i:s e'; 
    /**
     * 'Y' for year, 'm' for month, 'd' for date,
     * 'H' for hours, 'i' for minutes, 's' for seconds,
     * and 'e' for the timezone name
     */
    echo $mydatetime->format($mydatetimeformat), 
      $mydatetime->format('I')?' DST':'';
  4. Perhaps you would like to see the date and time in another timezone? No problem, PHP has that covered.
    $mytimezone2 = new DateTimeZone('Asia/Tokyo'); 
    $mydatetime->setTimezone($mytimezone2); 
    echo $mydatetime->format($mydatetimeformat), 
      $mydatetime->format('I')?' DST':''; 

Word of caution

The constructor method of DateTime is supposed to return false on failure, so you may be under the impression that you can rely on it to validate date and time strings. For instance:

$montrealtimezone = new DateTimeZone('America/Montreal'); 
$bogustime =
  new DateTime('2007-03-11 02:30:00', $montrealtimezone);

The above snippet is supposed to result in $bogustime holding the value false because ’02:30:00′ is not a valid time on that date due to Daylight Saving Time entering into effect. Unfortunately, the constructor does not catch the mistake and will return you a DateTime object representing March 11th, 2007, two-thirty in the morning, Montreal Daylight Saving Time. It is a bug that I recently discovered in PHP 5.2.0 and submitted to the php bug database. It does not seem to be fixed as of this writing, where the latest stable released version of PHP is 5.2.1. You can check the status of the bug here: http://bugs.php.net/?id=40340.

Edit:
A comment by Eric has prompted me to clarify that the above bug is NOT caused by an outdated zoneinfo database. You can test it by trying to instantiate a similarly bogus date of a past year, while having the most up-to-date zoneinfo database installed.