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.
補給完，我地就先分道揚鑣：家姐去銅鑼灣會合企鵝姐，開始佢嘅第二回合；我就去展開我嘅旺角探險。點解去旺角？因為我隻踎屎死咗。讀者一定諗：『踎屎死咗關旺角咩事呀？』。咁我就話你知啦。話說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蚊。
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!”
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. 🙂
It’s been decided. I’m leaving Montréal and getting a job in Japan.
Update: the sale is over. Thanks for all of the inquiries.
Some of you may have used the PopupGallery available at Yellow Swordfish. In the last few days I made changes to it so that the hover gallery automatically becomes pageable if there are too many pictures to be fitted on the page. You can see an example at my test site. The modified plugin package is available here.
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.
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:
- Web applications can have users coming from anywhere around the globe, under many different timezones.
- 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.
- 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:
- 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.
- 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.
- 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).
- 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.
- 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);
$timezonenamecan 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.
- 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
$datetimestringis the same as the GNU Date Input Formats, in case you have not found out from the php.net documentation already.
- 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
$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':'';
- 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.
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.