Archive for the ‘Hardware & Software’ Category

Conditional execution in bash

Sunday, September 24th, 2006 by Agro Rachmatullah

For some reason, I needed to run a program, but not if another program is running (can be the same program).

After googling for a bash tutorial, I was able to create the script:

ps aux > psinfo
cat psinfo | grep FORBIDDEN_PROGRAM > programinfo

if [ `wc -l < programinfo` = "0" ]
then
	PROGRAM_TO_RUN
fi

ps is used to list all processes running on the system. grep is used to display all occurences of the string FORBIDDEN_PROGRAM from the output of ps. The output of ps isn’t directly piped to grep, e.g “ps aux | grep FORBIDDEN_PROGRAM” because of the unpredictable behaviour of piping. Sometimes “grep FORBIDDEN_PROGRAM” is started before ps, making 1 entry of the string FORBIDDEN_PROGRAM in the output of ps if FORBIDDEN_PROGRAM is not running. However, sometimes grep is started after ps, which gives a count of 0 if FORBIDDEN_PROGRAM is not running.

wc is used to count the number of lines in a file (and is able to count other things too).

Character variants in Unicode

Tuesday, September 19th, 2006 by Agro Rachmatullah

In the Unicode, there are several code points for fullwidth characters. Here’s a comparison between the normal ASCII characters and their fullwidth counterparts (the normal is written first):

AABBCCDDEEFF

The superscript characters like ² is also a display variant of normal characters like 2.

Another amusing thing is the existence of language-specific characters. An example is the Greek capital letter eta (Η, U+0397) and the Cyrillic capital letter en (Н, U+041D). In my machine, they look exactly like the Latin capital letter H (which is ASCII 72 or U+0048).

I actually have a mixed feeling about including display variants in a character set. In light of HTML and various text-formatting utilities (TeX, office suites), display variants can be regarded as a waste of code points. For example, in HTML subscripts can be achieved using the tag <sup> and specific fonts (for example fullwidth) can be chosen using CSS (or the old-style <font> tag). About language variants, again HTML renders this unnecessary because there is the “lang” (or “xml:lang”) attribute.

However, variants have some merits. One use of those variants is of course for plain text files. For example, with the character “²” I can write “a² + b² = c²” nicely in a plain text file. The other benefit is space efficiency. For example, “²” is one character, while “<sup>2</sup>” consists of a lot.

What I hate about language variants is that it conflicts with one major theme in the Unicode work: CJK (Chinese Japanese Korean) character unification. In the Unicode, there is no such thing as the Japanese 人, Chinese 人, and Korean 人. There is only one character for all three languages: 人. This is in spite of drawing differences between some of the characters! Thus, it is not possible to convey the difference in a plain text file.

For example, here is the CJK character for “now” but displayed differently (if your computer is set up correctly) because of the “lang” attribute: (Japanese) vs. (Chinese). Both are U+4ECA. In my computer it looks like this:

Japanese vs. Chinese 今

See the HTML source code for more info.

私のfirst 1500 words (another edition)

Saturday, September 16th, 2006 by Agro Rachmatullah

The first printout of my first 1500 (or so) words is optimized to memorize the English meaning of a Japanese word. This is because the format is:

KANJI     KANA     ENGLISH_1, ENGLISH_2, ...

So, to drill the words, I cover the English meaning (and kana, if kanji exists) with a paper and then try to answer it.

For drilling the reverse, the ideal format is:

ENGLISH     KANJI_1 (KANA_1), KANJI_2 (KANA_2), ...

This time, it’s the kanji and kana that’s covered and I must translate from English to Japanese.

Of course, we can use the first format to drill English->Japanese by covering the kanji and kana. However there are two shortcomings:

  • The entries are sorted by kanji/kana. Therefore the sound of the answers will be similar if we drill from the top to bottom. This provides an unwanted clue.
  • Entries with the same English (for example 本日 and 今日 for “today”) is separated. Therefore there is ambiguity when trying to answer some items.

Thus the need for another format.

Preparing the first one isn’t hard because that’s exactly the format I use in my ods file. To prepare the second format, I write a filter for my text transformation program, LineFilter. The result is here.

Setting print area in OpenOffice.org Calc

Saturday, September 16th, 2006 by Agro Rachmatullah
Format -> Print Ranges -> Define

After doing the above step, printing-related operations like “Page Preview” and “Print” (with the “selection” option selected for “Print range”) will act upon the defined print area.

Keeping a memorized pro game memorized

Saturday, September 16th, 2006 by Agro Rachmatullah

(Written on… Uhm… No more “written on” stuffs. Too much of a hassle.)

I’ve memorized a lot of Takemiya games. However, as time passed, I gradually forgot the moves. Only general impressions like “Takemiya likes san-ren-sei opening” and “Takemiya sometimes reply a keima-gakari with kosumi” remains.

That is undesirable. Ideally, I want to remember the games forever. Therefore, periodic review is a must. Mnemosyne, anyone?

Mnemosyne is a program that helps you memorize items. It will smartly schedule reviews for you. Items that you already know well will be asked rarely, while items that isn’t memorized well will be asked more frequently. I use Mnemosyne to memorize Japanese words, among others.

We can use simple HTML tags like <b> and <i> in Mnemosyne, so I thought applets could be supported. My first idea was to create a **cough** Java applet myself and embed it inside Mnemosyne. However, following the principle of “don’t reinvent the wheel” and considering that I had to dig a lot of documentation just to get a “Hello World” applet running (almost no past experience making applets), I tried finding other people’s applet first.

So, I dug through Hiroki Mori’s “Interactive Way To Go” because I remembered there was a game replayer there. This is what I found:

<applet codebase="./../java" code="mori/go/FreeBoardApplet.class"
   width=300 height=350 align=left border=10>
	<param name=demo value=true>
	<param name=size value=13>
	<param name=init value="B[cc]W[kk]B[dj]W[kd]">
	<param name=moves value="B[fk]W[ki]B[id]W[ic]B[hc]W[jc]B[gd]W[cf]B[ch]W[dc]">
</applet>

The parameters were easy enough to decode. Give it a board size, initial moves, and navigable moves. Coordinates are in SGF style, which is <column><row> and the top left is “aa” (the letter ‘i’ is used).

I usually memorize the first 50 moves of a game. My idea is to divide the moves into 10 moves chunks. So, a Mnemosyne item will test moves 1-10, another for moves 11-20, and so on.

However, if I want to test moves 11-20, it will help if move 10 was marked. Since the applet only marks the last move played (from the “moves” parameter), move 10 shouldn’t be in “init” but in “moves”. It will be a dummy move, just to provide the mark.

Sadly, the applet wouldn’t appear inside Mnemosyne. Therefore I changed the usage scenario into the following:

  • A Menosyne item will contain a kifu review code, for example: “Kifu review: ab” which means game ‘a’ part ‘b’ (part ‘a’ is moves 1-10, part ‘b’ moves 11-20, etc)
  • Upon seeing that code, I will go to Firefox and type “k ab” (’k’ stands for “Kifu review”).
  • Firefox will be configured such that ‘k’ corresponds to a bookmark, such as “http://localhost/kifureviewer/?code=cc.
  • A page will appear with the applet mentioned before. I will replay the kifu and report the result back to Mnemosyne.

The process is quite disintegrated, going back and forth between Mnemosyne and Firefox.

For the web application, I decided to use ASP.NET. This is because I planned to load the game data from the SGF file, and I’m already comfortable with .NET’s file I/O. I used Mono 1.1.7’s XSP as the web server.

My ASP.NET’s experience was almost none, so I need to peek the documentation even to get a Hello World running. Here’s a sample:

<%@ Page Language="C#" %>
<html>
	<head>
		<title><% Response.Write(DateTime.Now); %></title>
	</head>
	<body>
	<%
		for(int i = 0; i < 10; i++)
		{
			Response.Write("<p>Hello world!</p>");
		}
	%>
	</body>
</html>

Other than that, I searched on how to import namespaces (needed e.g. System.IO and I didn’t want to type it all over). The answer is to put something like…

<%@ Import Namespace="System.IO" %>

…below the “Page Language” thing.

Next is searching where to make classes and static functions. The answer is to put it inside…

<script runat="server">
</script>

…which is put before the <html> tag.

The last info I needed was how to fetch the HTTP GET variables. This example…

Request.QueryString["code"]

…will get the value of the HTTP GET variable named “code”.

From there it wasn’t that hard, just parsing the SGF file and giving the correct parameters to the applet. Normal C# coding in which I’m already comfortable with.

I didn’t read the SGF format specification, but guessing the tag meanings wasn’t that hard. I assumed the SGF to be nonbranching and probably a lot of other simplifying assumptions. Below is shown some first characters of an SGF file:

(;DT[2006-09-01]EV[3rd Toyota Cup]RO[semi-final]
PB[Lee Sedol]BR[9p]PW[Lee Changho]WR[9p]
KM[6.5]RE[B+R]SO[Moyo Go Studio]
;B[qd];W[pp];B[dc];W[cp];B[ep];W[ce];B[dn];W[oc];

The relation from game code to SGF file names is in the file “database.txt” (location and file name cofigurable in the aspx file) which contains for example:

a	20060901_Lee-Sedol_Lee-Changho.sgf
b	20060830_Lee-Sedol_Hane-Naoki.sgf

The path of the SGF file is also configurable in the aspx file.

However, testing quickly reveals a critical problem:

Illegal Go position

It is clear that in putting stones from the “init” parameter, the applet didn’t check for captures.

There were two alternatives if I still wanted to use that applet. First is to ask for the source code of the applet and modify it. Second to do the capture checking myself before giving the parameters to the applet.

I chose the latter, utilizing the class inside my (with Fuad, Awang) Go playing program, Sai. A little hack here, a little hack there, and the board was displayed properly:

Legal Go position

Of course the prisoner count was wrong :). I don’t think there is a way to tell the applet about the initial prisoner count.

Anyway, it supports handicap:

Handicap support in KifuReviewer

However, being a Frankenstein solution, there are many things to improve:

  • The applet should be inside Mnemosyne. (at least I informed the maintainer)
  • Dummy move should be eliminated. The board should start with the last move marked.
  • User should guess by clicking on the desired coordinate, not by clicking the next button.
  • Prisoner count should be correct.

At least now I have a non-completely-manual means to memorize a game infinitely long. 1 game is already in Mnemosyne, and a lot more will certainly come…

Unicode support in desktop blog clients

Tuesday, September 12th, 2006 by Agro Rachmatullah

What blogging tool can work with the Japanese hiragana character あ (’a') properly? Let’s test all programs listed on http://codex.wordpress.org/Weblog_Client.This post is meant to raise awareness of the dismay Unicode support in today’s blogging programs.

First of all, the test system is Windows 98. This is the OS used by computers in Student Internet Center (SIC), and SIC is my gateway into the internet. Unicode works completely fine in Firefox, IE, and Notepad++ here. It’s OK if the program requires Java because it is installed on this computer. It’s fine if the program requires .NET 1.1 because installing .NET 1.1 don’t take much time. Program that requires .NET 2.0 is unacceptable because installing it takes ages on this slow computer (it compiles many files to native code using ngen.exe). Mono 1.1.17 can’t be used as the replacement of .NET 2.0 because Mono can only be installed on NT machines.

These are the programs that aren’t reviewed due to the aforementioned restrictions:

  • BlogWriter 1.0.29 (Zoundry): Couldn’t start on Windows 98 (ZBLOGWRITER caused an exception 10H in module PYTHON23.DLL).
  • ecto 2.1: Needs .NET 2.0.
  • Elicit 1.1.7: Needs .NET 2.0
  • Windows Live Writer Beta: Won’t run on Windows 98 (I’ve already installed .NET 1.1 (does it need 2.0?). It pinvokes a nonexisting function in Windows 98’s kernel32.dll)
  • JBlogEditor: Crashes before even posting.

Now on to those who could run. Some programs mercilessly converts あ to ‘?’. This happens everywhere: in the main and/or code editor and the title text box. Those programs are:

  • BlogDesk 2.6
  • w.bloggar 4.00 (as a bonus, it will crash when exiting)
  • Semagic 1.5.9.7 (btw the version I downloaded (for Windows 98) can only be used for livejournal)

Some programs work better:

  • BlogJet 1.6.2.60: あ is displayed fine in the main editor. It is displayed as a square in the code editor. It turns into a question mark (?) when the post is sent to WordPress. あ is converted into ‘?’ in the title text box.
  • Post2Blog 1.23.3: あ is displayed fine in the main editor. It will be converted into squares when you enter the code editor. However, no character corruption occurs when the post is uploaded (just remember to not enter the code editor). あ is converted into ‘?’ in the title text box.
  • WB Editor 2.5.1: Same imperfection like Post2Blog. Weird for a .NET program. Doesn’t .NET use UTF-8 internally?
  • Qumana 3.0.0: あ is displayed as a square in this program. However posting it to Wordpress works.

Two programs are perfect, which means that the program displays あ correctly in the title text box, main editor, and code editor, and uploads the post with no character corruption. Here are the winners:

  • Flock 0.7.4.1 (a Firefox-based browser with integrated blogging support, among others)
  • Performancing 1.3 (a Firefox extension)

There you go… Most of the blogging clients I reviewed failed. We really live in a primitive age of computing where software developers don’t care about supporting Unicode…

PS: I won’t use Flock nor Performancing. Performancing regards newlines in the code editor as real lines so my post will contain extra lines unless I do some unnatural deleting. Flock messes the <pre> (or <PRE>) tag by converting the starting tag into <pRE> and the ending tag into </PRE>, destroying all newlines in the process (already reported those bugs btw). I’m currently using Qumana to post this blog entry. The Japanese characters that show up as squares is tolerable because I edit the HTML file from my home.

Sorting strings: OpenOffice.org Calc, Explorer vs. Nautilus, dir vs. ls

Tuesday, September 12th, 2006 by Agro Rachmatullah

(Written on 9:26 PM 9/11/2006 GMT+7)

Sorting Japanese words in OpenOffice.org Calc

While sorting my Japanese words in OOo Calc, I noticed that the katakana ア is between the hiragana あ. After a curious investigation, I concluded that OOo Calc doesn’t distinguish between hiragana and its corresponding katakana for sorting purposes. Uppercase and lowercase latin letters are also regarded as the same.

Therefore, the starting condition will determine the "sorted" condition. For example, the following column won’t change if sorted:

A
a

But the same is true for this column:

a
A

Explorer works the same way as OOo Calc, treating capitals the same as its small counterparts and hiragana the same as katakana:

Sorting in Explorer

However, the dir program treats katakana after hiragana which is inconsistent with Explorer:

E:\Temp\sorting test>dir
 Volume in drive E is Archive
 Volume Serial Number is A809-0E48

 Directory of E:\Temp\sorting test

09/08/2006  08:13 PM    <DIR>          .
09/08/2006  08:13 PM    <DIR>          ..
09/08/2006  07:47 PM                 0 Aa
09/08/2006  07:47 PM                 0 ab
09/08/2006  07:47 PM                 0 ba
09/08/2006  07:47 PM                 0 Bb
09/08/2006  07:47 PM                 0 あa
09/08/2006  07:47 PM                 0 いb
09/08/2006  07:47 PM                 0 アb
09/08/2006  07:47 PM                 0 イa

But the behavior will change if we use /o:n (sort by name):

E:\Temp\sorting test>dir /o:n
 Volume in drive E is Archive
 Volume Serial Number is A809-0E48

 Directory of E:\Temp\sorting test

09/08/2006  08:13 PM    <DIR>          .
09/08/2006  08:13 PM    <DIR>          ..
09/08/2006  07:47 PM                 0 Aa
09/08/2006  07:47 PM                 0 ab
09/08/2006  07:47 PM                 0 ba
09/08/2006  07:47 PM                 0 Bb
09/08/2006  07:47 PM                 0 あa
09/08/2006  07:47 PM                 0 アb
09/08/2006  07:47 PM                 0 イa
09/08/2006  07:47 PM                 0 いb

This is weird because by default dir already sorts latin alphabets by name (in other words, the default behavior should match /o:n).

So how does Ubuntu 6.06 fare? I booted the Live CD and here’s Nautilus in action:

Broken sorting in Nautilus

Total mess! Why are kana interspersed between latin alphabets? I couldn’t figure out how that program sorts…

ls (the console command "el-es") is no better:

ubuntu@ubuntu:/media/ntfs/Temp/sorting test$ ls -l
total 0
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 あa
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 イa
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 Aa
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 ab
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 いb
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 アb
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 ba
-r-xr-xr-x 1 root root 0 2006-09-08 12:47 Bb

I’ve reported those bugs to Ubuntu’s Launchpad.

The end of BOAB

Tuesday, September 5th, 2006 by Agro Rachmatullah

(Written on 10:15 PM 9/3/2006 GMT+7)

Because my PC isn’t connected to the internet, I write blog entries at home and upload it later (usually every Tuesday and Saturday). I write the entries on a file called boab.html, then post the whole content as a single Wordpress blog entry. Therefore, each blog entry I write at home will actually be a part of a containing Wordpress blog entry. Hence BOAB, or Blog In A Blog.

Here’s the illustration:

Posting boab.html

As shown, this greatly simplifies the posting process because I only have to post once. However, it is obvious that the downfall outweights the convenience. Because a blog entry with BOABs actually talks about more than 1 topic:

  • Referencing a particular BOAB within a post is hard. People must sort through various BOABs to find the particular BOAB they’re looking for.
  • Conversation in comments will be unintelligible. Different people could talk about different BOABs.

The new process will be:

The alternative method of posting boab.html

It requires more work, but doesn’t have the downfall of the previous method.

It’s silly that an idea as bad as BOAB got used for quite a long period (around 3 months). Actually, the downfalls were pretty obvious but WordPress’ slow SSL connection combined with my laziness to change things that already worked made it persistent. But it’s better to be late than never, right?

Stardict is speechless

Tuesday, September 5th, 2006 by Agro Rachmatullah

(Written on 4:21 PM 9/2/2006 GMT+7)

A feature in Oxford Advanced Genie not found in Stardict (a free/open source dictionary) is the sound. With Oxford Advanced Genie, we can hear how every word is pronounced. For some words, both the English and American pronunciation are available.

For some words, there seems to be a pronunciation info in the GCIDE data for Stardict (I use GCIDE, Oxford, and Longman for Stardict’s data). Some examples (pay attention to the cryptic string inside the parentheses):

Up \Up\ ([u^]p)
Bottom \Bot”tom\ (b[o^]t”t[u^]m)
Great \Great\ (gr[=a]t)
Accumulate \Ac*cu”mu*late\ ([a^]k*k[=u]“m[-u]*l[=a]t)
Apple \Ap”ple\ ([a^]p”p’l)
Abate \A*bate”\ ([.a]*b[=a]t”)

However deciphering it requires one to study the notation.

PS: For ease of pronunciation (from text to speech), Japanese wins hands down. Bahasa Indonesia has ambiguity with the letter e. For example, in “keras” and “basket”, the “e” is pronounced differently.

PS2: Isn’t it weird that “pronounce” becomes “pronunciation” (not “pronounciation”)? Luckily Stardict has fuzzy search. Searching for “pronounciation” gives no result, so I used “/pronounciation” (note the slash) and Stardict gives me “pronunciation” (and other close matches).

Dapper or Edgy?

Tuesday, September 5th, 2006 by Agro Rachmatullah

(Written on 4:00 PM 9/2/2006 GMT+7)

One of my plans after KKN is over is to install Ubuntu on my system. The previous one (Breezy) was wiped when my partition got messed up.

However, with Edgy already on Knot 2 and scheduled to be out on October, would it be better to wait?