Archive for the ‘Programming’ Category

The ASP.NET Bin and App_Code folder misconception

2008 May 5

This post has been moved to “The ASP.NET Bin and App_Code folder misconception”. Please visit the new server.

Tutorial penggunaan SQLite dari .NET menggunakan bahasa C#

2007 June 11

This post has been moved to “Tutorial penggunaan SQLite dari .NET menggunakan bahasa C#”. Please visit the new server.

Tulisan ini telah dipindah ke “Tutorial penggunaan SQLite dari .NET menggunakan bahasa C#”. Silahkan kunjungi server barunya.

SQLite, mesin SQL yang kecil dan cepat

2007 May 29

Tulisan ini telah dipindah ke “SQLite, mesin SQL yang kecil dan cepat”. Silahkan kunjungi server barunya.

This post has been moved to “SQLite, mesin SQL yang kecil dan cepat”. Please visit the new server.

I knew it! Files are living things! They have genes!!!

2007 May 26

The problematic file is freetest.htm. I have identified that it has an NS_ERROR_XPC_NOT_ENOUGH_ARGS gene. With that gene, you cannot do any AJAX from the file on certain environments…

No, I’m not on a crack… Listen to my detailed account, all you Javascript developers… That defective gene might be on YOUR file.

After learning how to use AJAX on a dummy page, I coded the real thing on freetest.htm, the real page. Like most Javascript programming, sure enough it only works on one browser. The lucky one is Opera 9 this time. The suckers are Firefox 2 and IE 6.

Browser programmers are ultra-smart guys, I assume the mistake is on my part. OK, so I copied the AJAX code to a dummy, clean, HTML page to find the bug. However it works!

Ah, so it must be some arcane interaction between the previously-existing Javascript code and the newly-added AJAX code. But my AJAX code is pretty complicated. Therefore I tried adding the simplest possible AJAX action in my real page, trying to see whether a simple AJAX works at all. The simple AJAX creates an XMLHttpRequest, sends a request, and retrieves the response. This time it works in Opera 9 and IE 5. Firefox (using Firebug debugger) gives this error:

uncaught exception: [Exception... "Not enough arguments"
nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)"
location: "JS frame :: http://localhost/aspx/freetest.htm ::
doAjax :: line 26" data: no]

It’s time to hunt which other js file conflicts with this one. I deleted the reference to other js files one by one, until there is no Javascript code other then the AJAX itself! But still AJAX doesn’t work!

Lol now that’s funny. OK, so I tried modifying my real file further (I’ve backed it up), deleting more useless things like CSS and title, until it matched another dummy file (freetest-simpleajax.htm) with the same AJAX code down to every character. Browsers are weird, so there is still the slight possibility that the TITLE tag messes things up. However it still doesn’t work while AJAX works on the other dummy file!

Obligatory md5 result:

1ab3bdf1ab23aabd6cfa4b1210bc7ee2 *freetest.htm
1ab3bdf1ab23aabd6cfa4b1210bc7ee2 *freetest-simpleajax.htm

(since the content of the files are identical, the genes must be stored somewhere else such as in the NTFS Master File Table)

Lol… I tried using the save as command to save freetest.htm into freetestxxx.htm. That’s probably the equivalent of reproduction. Amusingly, freetestxxx.htm works fine. Did the defective gene not get passed?

Ah, I forgot a very basic thing! Phenotype (visible traits, like the body height of an ape and an HTML page throwing exception) comes from the intricate interaction between genotype and the environment! Basic Biology… Let’s try opening freetest.htm on another tab of the still-running firefox.exe instance…


It works!

So, it must be the environment. The other tab must be too humid or something for freetest.htm to do AJAX. It’s not a problem of cache (the tab loading an old, nonworking version of the file). I tried modifying freetest.htm by adding visible text and reloading it on both tabs. The text appears on both, signifying that both tabs opened the most recent version of the file. However AJAX still doesn’t work on that cursed tab…

Whatever… I still haven’t achieved what I wanted, making the real AJAX code work on the real page… Back to work…

Edit: The culprit is the function named parent. Renamed it to domParent. What’s weird is that after the exception occurs, the tab will be unable to do AJAX on that page even after the problem has been corrected (hence the story above).

Edit 2: It doesn’t work in IE! The ringleader is different this time… In IE 6, there is no XMLHttpRequest required for AJAX, but we can achieve the same thing by creating an ActiveXObject as shown:

var foo = new ActiveXObject('Msxml2.XMLHTTP');

However, it turns out that the variable foo won’t behave completely like a real Javascript object! It fails when we try to dynamically add a property, such as: = 'This thing normally works';

My code adds an id for every XMLHttpRequest object created, so it fails miserably in IE 6… Geesh, I now have to code a different way of tracking those requests…

HtmlKanjiMarker 0.01

2007 February 23

The first release of HtmlKanjiMarker 🙂

HtmlKanjiMarker is a program that reads a local HTML file and then marks all unknown kanji red. If you’re studying kanji, this program might be interesting and useful.

Because the program is written in C#, you first need to install .NET Framework 2.0. After that you can download HtmlKanjiMarker 0.01 (487 KB) itself. To run the program, just extract the contents somewhere and run “HtmlKanjiMarker.exe”. Instruction on using the program can be found on the included “readme.txt”

PS: If my university server borks, you can try downloading from

PS2: The program doesn’t run yet on Mono 1.2.3 because they haven’t implemented the web browser control.

HtmlKanjiMarker: my red grades

2007 February 17


This program was actually made quite some time ago, but I haven’t blogged about it.

HtmlKanjiMarker reads a local HTML file and then marks all unknown kanji red. The list of known kanji is taken from two sources. First is from the “Max grade” textbox on the upper right. I entered 4 because I’ve studied all Jouyou kanji grade 4 and below. The second is from a text file, “ExtraKnownKanji.txt”. The file should contain all kanji you’ve learned, outside from the textbox range.

Using this program, I can visually see how effective my current kanji knowledge is for a certain page. It also makes hunting new kanji easy. Last, It can answer questions such as “what if I learn all grade 5 kanji?”. (just change the “Max grade” textbox)

Programming the algorithm naively yielded a very slow marking. This is because a HTML page contains tons of characters, and there are ten thousands of kanji to check againts. I actually benchmarked and overhauled the algorithm several times. I originally wanted to write about the algorithm changes, but lost the interest by now :).

So, here’s some generated Wikipedia pages viewed from my eyes of 1249 kanji: Newton, September 11 2001 attacks, Wikipedia. Rest assured, I’m still quite far for literacy…

Keep running, and if tired, walking. A small rest is also fine, just don’t surrender!