Real-life SpongeBob

Posted by Ikhwan on August 23, 2006

Wow, somebody found a real-life SpongeBob! But I doubt that this is the same as the one seen on TV, because I can’t see any square pants.

p.s: from an email forwarded by a friend.

2.5 Dibundarkan Jadi 3 atau 2?

Posted by Ikhwan on August 21, 2006

Masa sekolah rendah dulu mesti korang semua pernah belajar tentang membundar atau membulatkan nombor (rounding). “1kHz (bukan nama sebenar), kamu bundarkan nombor 2.9 ni kepada integer yang hampir!”, kata Cikgu Asmah yang garang itu. Dalam kes ini, aku sepatutnya menjawab 3. Senang je, cuma tengok sama ada nombor perpuluhan tu lebih atau kurang dari 5. Kalau 2.4, jadi 2. Kalau 2.7, jadi 3. Tapi kalau 2.5? Ini betul-betul atas pagar ni? Mestilah jawapannya 3, macam Cikgu Asmah cakap. Tapi sebenarnya, ia boleh jadi sama ada 3 atau 2, bergantung kepada jenis pembundaran atau “rounding” yang digunakan. Dua jenis yang biasa digunakan ialah Arithmetic Rounding dan Banker’s Rounding.

Arithmetic Rounding (a.k.a 4/5 Rounding, or Round to Larger)

Ini jenis yang Cikgu Asmah dah ajar seperti di atas. Kalau perpuluhan 5, pilihlah nombor yang lebih besar. Cuma persoalannya di sini, kalau nombor tu negatif, macam -2.5? Kalau diikutkan, bundarkan kepada nombor lebih besar maka dia akan jadi -2 (sebab -2 lebih besar dari -3). Cara ini dipanggil Symmetric Rounding. Tapi kalau kita abaikan tanda negatif tu, maka -2.5 jadi -3. Macam ini boleh juga, ia dinamakan Asymmetric Rounding, atau Away From Zero Rounding. Quiz: rasa-rasanya kenapa masing-masing dinamakan symmetric dan asymmetric?

Banker’s Rounding (a.k.a To Even, or Round to Nearest)

Dalam jenis ini, nombor sentiasa di bundarkan kepada nombor genap yg terhampir. Kalau 1.5, jadi 2. Kalau 2.5, pun jadi 2. Seterusnya, 3.5 jadi 4. Dan 4.5 jadi 4 juga. Kenapa pelik sangat? Macam “bias” dan berat sebelah je. Kenapa genap asyik menang. Lihat contoh:

..nombor-nombor sebenar
1.46 + 1.45 = 2.91

..kalau guna Arithmetic Rounding:
1.5 + 1.5 = 3.0

..kalau guna Banker’s Rounding:
1.5 + 1.4 = 2.9

Kalau kita lihat, 2.9 sebenarnya lebih hampir pada nilai sebenar iaitu 2.91 berbanding 3.

|2.9-2.91| = 0.01
|3.0-2.91| = 0.09

Cara ini penting dalam pengiraan wang (thus, the name “banker”, I suppose), untuk mengelakkan dari ada “sen” yang ghaib secara tiba-tiba.

Pembundaran Dalam .NET

Dalam .NET 2.0 (1.x tak ada), cara mudah untuk membundarkan nombor ialah menggunakan Math.Round(). Math.Round(2.5) akan hasilkan 2 sebab secara defaultnya Math.Round menggunakan cara Banker’s Rounding. Kita boleh supply satu lagi parameter utk pastikan jenis rounding yg kita mahu, iaitu sama ada Math.Round(2.5, MidpointRounding.AwayFromZero) atau Math.Round(2.5, MidpointRounding.ToEven). ToEven utk Banker’s Rounding, dan AwayFromZero utk Asymmetric Arithmetic Rounding. Untuk Symmetric Rounding aku tak jumpa macam mana nak buat.

Rujukan:
http://ewbi.blogs.com/develops/2003/11/vba_round_yet_a.html
http://blogs.inetium.com/blogs/jgood/archive/2006/04/21/77.aspx
http://msdn2.microsoft.com/en-us/library/system.midpointrounding.aspx

p.s: Satu perkara yg perlu diingat, kalau buat pengiraan utk wang, *mesti* gunakan data type Decimal. Kalau untuk saintifik, lebih elok gunakan Double atau Single.

p.s.s: Dlm PoEAA, Martin Fowler mencadangkan penggunakan Money class untuk mewakili wang. Ada satu method menarik, iaitu allocate yg gunakan utk membahagikan wang kepada berbilang bahagian, supaya tak ada “sen yang tercicir”.

High On Code!

Posted by Ikhwan on August 21, 2006

I’ve been coding straight from 4.00 PM until now, about 12.00 midnight. Okay, not really that straight, I took some time to “solat” and have dinner. But, hell yeah, I feel high! Totally awesome, dude. I’ve not felt something like this for about… err.. quite a long time I guess. Wow, I miss this feeling! The burning desire, the passion, the excitement. And the output of this sudden rush to code: a simple MVC framework, with ActiveRecord style object persistence.

Okay, I can probably go a little bit more, but it’s late, I need to sleep.

Dance Fingers, Dance (Part 2)

Posted by Ikhwan on August 20, 2006

Okay, we are back again. This is the second part on how I try to maximize my keyboard utilization. Click here if you want to read the first part.

Command, and Conqure Your Destiny

Using command-line to operate a computer is almost always faster than depending on GUI to to things. An example, the task is to delete files with extension “.abc” from a folder, and in its subfolder, and the sub of that subfolder. Well, have fun traversing the folders in and out! A rather clever trick is to use the Search function in Windows Explorer to search the files. All the corresponsing files will be listed down, and then you can quickly end their misery with a quick Select All and Delete. But using command-line, you just need this: “del /s *.abc”! Yeah, good riddance…

“But dude, it’s such a pain to open the Command Prompt! It’s like, Start then All Programs, then Accessories and finally Command Prompt”. I’ve told you to use shorcuts right? It’s just Win+R, type “cmd” and Enter. “Okay, but we still need to navigate to the folder right? All these slashes makes me dizzy!”. Well, you are right there. I really wish that Windows Explorer has a Command Prompt panel built-in somewhere in it, and any command entered targets the currently open folder. That would be sweet. Rather than waiting the feature added in, what we can do is to install this one Windows XP Power Toy, it adds a “Open Command Prompt Here” in the context (right click) menu. It’ll open a Command Prompt and directly make your selected folder as the current working directory.

Another reason why I like to use commands is that because I suck at searching things. I’d always goes up and down the file list several times before finding what I want. Firing apps from Start menu is not easy also, my Start menu fills half the screen. The desktop? Even worse, if you have a desktop like this.Because I usually know what the name of the file, it’s easier to just type in the filename in command-line and be done with it.

One app that I can’t live without is the SlickRun. It’s something like the Run box (Win+R), but slicker. You can add you own “magicwords” to run app, do things, open sites, etc. To open Notepad++, I would just Win+Q (can customize to any key) to activate SlickRun, type in “np” and Enter. “mp3″ for WinAmp, “vs” for Visual Studio, “sql” for SQL Management Studio, and “ie” to open Internet Explorer. Actually, I don’t need to key-in “ie”, I would just type “http://antikes.blogspot.com” and it’ll open the site with my default browser. When I want to look up something in Google (and I do that a lot), I’d just “go needle in haystack”. “go” is my magicword for Google. You can also navigate to your folder using this thing, just key in the path. It also remembers what you key-in previously. Man, this thing is awesome.

It’s hard to get used to command-line, we Windows users are so pampered with the nice GUI. I’m not exactly a 100% command line guy. Of course I use the mouse every now and then. If my hand is on the keyboard at that moment, then I’ll use command line. If it’s on the mouse, then I’ll point and click.

Wow, it’s late again. Sleeping late is not good for health. Some study even says that people who always sleep late gains more weight. I have enough fat, I don’t want more. Looks like we’ll gonna have a third part.

(to be continued…)

10 Things Every Web Development Office Should Have

Posted by Ikhwan on August 19, 2006

Wow, what a nice office! I would be darned happy if my office is 1% as nice as that.

Item #10, ping pong table. Incidentally, I like to play ping pong very much. If one day I have the chance to setup an office of my own, I definately will get a ping pong table.

“Cara terbaru menyebar kuman HIV” - HOAX!

Posted by Ikhwan on August 18, 2006

Korang pernah dapat email yg cakap pasal ada pesakit-pesakit AIDS yang tak bertanggungjawab menyebarkan virus HIV kepada orang tak bersalah, dgn meletakkan jarum-jarum suntikan di tempat awam? Hari ini aku dapat lagi satu.

Yang aku tahu, virus HIV tak boleh hidup lama di luar badan manusia, jadi tak mungkin dia boleh berjangkit secara macam tu (correct me if I’m wrong). Jadi oleh sebab hari ini aku bosan, sebab tak tau nak buat apa (ada sebenarnya, aku cuma tengah test my procrastination skills), dan sebab ada 3 popia kat atas meja aku ni, maka aku ingat nak do some good for the human race dan research betul ke cerita ni atau cuma hoax.

Kat bawah tu ada email tu ada nama somebody called Dr Yasmin, so aku try google. Memang nama tu wujud dan ada email dia. Aku dah beria nak tanya dia lalu email ni, tapi rupa-rupanya somebody has beaten me to it, somebody named maurina. Baca sini. It’s a hoax!

Dear Maurina,

This is a hoax message, it has been circulated over 5 years now, and someone very irresponsible has used my name for making the news a more credible one!!!!

Sincerely,

Dr Yasmin

I sure hope that blog entry is true though. Spreading a hoax about a hoax would make me seem really, really dumb. Oh, aku baru dapat satu lagi popia!

Siti Nak Kahwin

Posted by Ikhwan on August 18, 2006

Siti Nurhaliza dah nak kahwin. Aku tak rasa apa-apa pun. Aku bukan macam korang, berangan-angan nak kahwin dgn orang glamour-glamour. Aku bukan fan dia pun. Tapi aku tak benci dia, ada lagu-lagu dia yg aku suka. Cuma akhir2 ni aku naik meluat dgn publisiti perkahwinan dia. Gila, macam2 cerita itu ini. TV3 siap buat mini series “Tiada Rahsia”, tiga Sabtu berturut-turut, interview live dgn Siti dan Datuk K, cerita pasal bila bibit-bibit cinta mula berputik la apa semua. Ceh.

Ini ada satu surat terbuka orang tulis utk bakal mempelai wedding of the year ni, got it from Syed. Klik sini.