Buddhists’ Calendar

I made a small online tool: Buddhists’ Chinese calendar:

http://www.idogicat.com/cal_fojiao.html

Here is the Japanese version:

http://www.idogicat.com/cal_fojiao_jp.html

Here only the Buddhism festivals celebrated in China are adopted, since it’s mainly targeted to the Chinese Buddhism practitioners (this also includes most - if not all - of those in Japan and Korea).

Buddhists' Calendar

Nuclear problem?

After the big earthquake, the biggest problem happened to be the nuclear plants, which is very scary.

Here are some links that monitors radiation in different locations. By checking these frequently, our chance of being safe can increase:

    Online Character Conversion Tool Set

    Many kinds of characters are used in computer systems, even for the same language. This sometimes causes a lot of inconvenience.

    In Chinese world, there are two kind of writing systems: simplified Chinese and traditional Chinese. The former is mainly used in mainland China and Singapore, while the latter is used in Taiwan and Hong Kong. It’s a lot of trouble to convert an article written in one system to another. In order to make this easy, I wrote this simplified & traditional Chinese characters online conversion tool. With this tool, you can convert an article in a snap. This tool is actively used by Christian organizations in Vancouver where materials in both simplified and traditional Chinese are needed. Some Chinese language students also find it useful to learn characters or convert materials in the two writing systems. Even some professional translators are users of this tool.

    In Chinese & Japanese character sets, there are full-width characters for English letters, numbers and symbols. I don’t really know when they should be used. In my opinion, in most cases we should use the ordinary half-width characters. But when you turn on the input method, it’s very easy to type a lot of full-width characters in an article. It’s very troublesome to change all these stuffs from full-width to half-width, or vice versa. This full-width & half-width character online conversion tool provides a quick solution.

    A problem with Japanese character sets is that the not-so-good but old half-width katakana characters are still widely used nowadays. These characters are mainly used in following two situations:

    • bank fund transfer
    • mobile phone oriented web sites

    Maybe it’s very tricky to renew all bank systems and ATM’s to switch from half-width katakana to full-width ones, when you wire some money via internet, you must enter the beneficiary’s information in half-width katakana (and English letters, numbers and symbols when applicable). The problem is that usually people show you their information in full-width katakana in their web sites or emails: if they write them in half-width ones, these characters may show scrambled. As a result, you have to type these information by yourself with half-width characters. This is error-prone, also sometimes you don’t have Japanese input method installed at all. So it’s always painful to wire money using web sites of Japanese banks. In order to make this process easier, I developed this full-width & half-width katakana online conversion tool.

    BTW, I really don’t think it looks good to show a bunch of half-width katakana characters in an article full of full-width kanji and hiragana characters. But due to the size of mobile phones, it seems that there is no other choice to make Japanese mobile web sites show reasonable amount of information in a small screen, unless everyone throw away their mobile phones at once and switch to something like iPhone…

    These tools, together with the Suzhou numerals & Arabic numerals online conversion tool, forms the online character conversion tool set provided by me. It’s advised to check the result thoroughly after conversion, and of course I won’t be responsible for any bad result that these tools may cause. Hope these tools can help you out and make your life easier in Asia.

    Suzhou Numerals Conversion Tool

    In 2010 British TV series “Sherlock” episode 2 “The Blind Banker”, the smugglers used a set of mysterious symbols to pass on messages. Those symbols are in fact numbers written in “Suzhou Numerals”, which is an ancient way of writing numbers in China.

    Suzhou numerals derived from a kind of rod numerals in ancient China, but different from the counting rods that were for math and engineering purposes, Suzhou numerals were mainly used for accounting and business purposes. It is much easier than the formal Chinese written numbers system, made it much easier for almost everyone to understand, no matter what their education levels were.

    Today, in some of the small traditional stores in Taiwan and Hong Kong, Suzhou numerals can still be seen occasionally. But it’s gradually disappearing with the wide spread of western style supermarkets, where of course Arabic numerals are used.

    In order to save the traditional culture, I developed a small online tool to convert numbers written in Suzhou numerals and Arabic numerals. In the following screen shot, it converted Pi into Suzhou numerals.

    MacBook and Windows

    Ideally, we should only use OS X in a MacBook, that’s why Mac should be used anyway, since Apple used a lot of proprietary things that optimizes the performance of the whole system. But due to Microsoft’s huge influence, no matter we’d like to admit it or not, there are many reasons for which we have to use Windows. A few examples include:

    • Microsoft Office: of course, there are Mac versions, but GUIs are different, and you need to pay for them again…
    • Visual Studio: good IDE for C++, and good RAD tool like VB and C#, etc.
    • Windows Live Mail: if you have some Hotmail accounts for historical reasons like me, you will find it very handy.
    • IE: oops, but there are some banks like those in China with out-of-date tech that requires this.

    So I managed to install Windows right after I got my MacBook. It was a pain by the way, since my Windows XP installation CD is the MSDN version, with more than one versions of Windows in one CD, this proved to have problem installing: Mac’s Boot Camp failed to handle the prompt of choosing Windows to install. So I had to customize and burn a CD with only one version of Windows…

    It seems that there are still some issues with Boot Camp. I feel the following two major ones annoying:

    • It consumes more resources: When I use OS X, the temperature of the machine is fine; while when I boot to Windows, it’s hot, even when it’s not busy (for example, just put it there without doing anything). I think that this could be caused by Boot Camp since Windows XP is not that bad.
    • The Blue Screen of Death occurs occasionally. This seldom happens (in fact, almost not) in my previous PCs and notebooks. So this may also be caused by Boot Camp.

    Although there are these problems, I still enjoy using Windows in MacBook. One good thing is that this notebook has 4GB RAM, while Windows XP can only use 3GB. So I used the extra 1GB to create a RAM disk, and I configured the system to use this place to store garbages like temp files and cache data of web browsers. This is really cool.

    Note: After I wrote this article, I found in Microsoft’s web site that Windows XP can also be configured to use 4GB of memory. But I still keep the current settings since I really feel the idea of having a 1GB RAM disk is very cool…

    Setup Web Dev Env in MacBook

    Since Apple’s MacBook notebook uses OS/X that is built on top of Unix, it’s very like a server environment (while in Windows, we need to install something like Cygwin). So we can use this as a development environment. The problem is that it’s not so apparent to find where and how Apple organizes the things. For web development, it’s as follows:

    Apache2

    Apache2 is pre-installed.

    • script: apachectl (in path)
    • config: /etc/apache2/*
    • htdocs: /Users/<user_id>/Sites
    • URL: http://localhost/~user_id/
    • log: /var/log/apache2/*

    PHP

    PHP 5 is also pre-installed, we need to enable it in Apache’s config file: uncomment the line with ‘php’:

    LoadModule php5_module        libexec/apache2/libphp5.so

    add php type in “<IfModule mime_module>” block as follows:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    Restart Apache, we can pass the php test by creating a test.php as follows and put it in ‘Sites’ dir:

    <?php phpinfo(); ?>

    Perl & CGI

    Now comes the good-old Perl CGI. According to Apache’s configuration, the CGI dir is “/Library/WebServer/CGI-Executables”, it’s mapped to URL “http://localhost/cgi-bin”. To make it easier, we can create a soft link in home dir:

    ln -s /Library/WebServer/CGI-Executables Cgi

    Now it can be tested with following script:

    #!/usr/bin/perl -wT
    
    print "Content-Type: text/plain\n\n";
    
    print "Hello CGI!\n";

    mod_perl

    Add following lines in proper  places:

     # load it
     LoadModule perl_module        libexec/apache2/mod_perl.so
    
    # add a place to test mod_perl scripts
     ScriptAliasMatch ... (omitted, refer to the CGI one)
    
     <Directory "/var/www/cgi-bin/mod_perl">
     SetHandler perl-script
     PerlHandler ModPerl::Registry
     Options +ExecCGI
     PerlOptions +ParseHeaders
     </Directory>

    Now we are pretty much done. The only remaining thing that is good to have is MySQL…

    Grab the Internet Trouble Makers!

    There are a lot of people trying to crack or spam others’ web sites (in vain)… What they usually do can be categorized into two types: one is trying to posting their articles (usually advertisements for drugs and so on) automatically to a lot of forums; the other one is trying to download files that the web masters might put there carelessly (for example, *.mdb, web.zip, etc.).

    I don’t care about this too much, unless they keep doing this all the time, which consumes my band width. In order to grab them out and filter their requests out using a firewall, I did the follows:

    First, in Apache’s configuration file, filter all these suspecious requests into a separate log file. For example, I am using Apache in Linux, but if someone requests for /forum/post.asp, or /data.mdb, then it’s for sure that they are from crackers or spammers. I put all of these in a file called worm_log (these things used to be from worms…).

    Then I wrote a small script to calculate the number of hostile requests:

    #!/bin/sh
    
    allIPFile=/tmp/ips.txt
    ipListFile=/tmp/ip_list.txt
    
    myTmpFile=/tmp/mytmp.txt
    
    cat worm* | cut -d ' ' -f 1 | sort > $allIPFile
    
    cat $allIPFile | uniq > $ipListFile
    
    lines=`cat $ipListFile`
    
    rm -f $myTmpFile > /dev/null 2>&1
    
    for ip in $lines ; do
            n=`grep $ip $allIPFile | wc -l`
            echo "$ip: $n" >> $myTmpFile
    done
    
    cat $myTmpFile | sort -nr -k 2,2 > spammers.txt

    The output is something as follows:

    222.73.173.10: 404
    58.215.65.183: 355
    222.73.173.11: 351
    210.83.81.80: 314
    121.14.212.82: 140
    118.102.26.197: 117
    221.231.114.10: 56
    221.5.6.198: 48
    ...

    Now we are very clear about who are the top trouble makers and should be blocked out of the firewall.

    Got permanent residency

    After working here for more than 10 years, and waiting for several months, I eventually got the permanent residency on last Friday. I am very happy with this since now I have much bigger freedom than before.

    Ordinary visas have strict limitations. I hadn’t been aware of this before, until a friend of mine was sent back to China for working on another job, that is not in the same area as indicated by her visa… That was a terrible lesson.

    Getting a permanent residency has following benefits:

    1. Do what you want to with no limitation (if it’s legal…)
    2. much higher creditworthiness (for example, when you apply for a mortgage loan, or do business)
    3. no expiry (but reentry permission has)
    4. unemployment protection: according to the law, a foreigner is to be sent back if he cannot get a job in three months after losing his job. Since unemployment insurance starts the first payment after three months from the time when one loses his job, this is unfair for foreigners who also keep paying for unemployment insurance (and have to do so). With PR, this won’t be a problem.

    PC Awaker

    Click to download it.

    Click to download it.

    Usually there are a lot of rules in global companies. One of them is the rule of forcing PC go into screen saving after 5 minutes, and if you want to use the PC again, you have to enter your password to unlock the PC.

    I admit that this is necessary for security reasons. But sometimes it’s not so reasonable for some of the PCs. For example, if one needs to support a product in a fast paced environment, they cannot afford entering password every time they need the PC - and in fact, the PC’s screen should never be turned off during the work time at all.

    The tricky part is that usually we cannot change the screen saver settings because this feature is locked to enforce this rule. In this case, this ‘PC Awaker’ comes to the rescue.

    This application is a tiny Windows utility, it is designed as a ‘tray application’, that is, it usually stays in the ‘tray’ of Windows task bar, unless you bring it out. The way how it keeps PC ‘awake’ is to send simulated key strokes periodically - to press F14 key every 4 minutes, to be precise. These are hardcoded since I don’t think it’s necessary to make these configurable.

    The license of this software is ‘HSL‘. Help yourself if you need it.

    Download it here. It was built in Windows XP using Visual C++ 6.0. I hope that it can work in Windows 9x/ME/NT/2000/XP. Don’t know if it works in Windows Vista…

    My Tetris with AI Functionalities

    (click on image to play tetris)

    Tetris game was invented by a Russian scientist. The concept is very simple but effective - even today there are a lot of people enjoying this game.

    I am not only interested in playing this game, but also interested in writing it (since I am a programmer :-) ). It has been my habit to implement Tetris games to practise GUI programming with a newly learned language. The earliest one was done on MS-DOS using C language (in an Borland IDE called Turbo C, by the way), I worked on some tricks like writing directly to Video-RAM to increase the performance, etc; then I did it using Visual Basic 6.0; then Visual C++ 6.0. Unfortunately all these versions are lost due to hardware upgrades.

    Then in 2000, I joined a New York based company called Financial Sciences Company. There Java was chosen as the main language to work on their next generation trading applications. I knew nothing about Java at that time (I was accepted because of my C++ skills). So I learned it by reading ‘Core Java 2′ and ‘Professional Java Server Programming (J2EE edition)’, and practised and sharpened the skill by writing some programs in my spare time. This implementation of Tetris was the result of my study and practice of Java GUI programming using Swing. I think that it is the best one among my Tetris series.

    Lately I don’t have the time to play with these Swing stuffs any more, so I just got some time to improved the algorithm in AI part to make it demo better. You can choose ‘X’ level to see the demo.

    Features:

    * Employing M-V-C pattern, game logic, data and the game screen are seperated, this makes the code very clean;
    * The game panel is encapsulated as a component, so it can be dropped to any container conveniently using an IDE;
    * Except the control buttons etc., it doesn’t use any control in Java API, instead, it draws directly to screen;
    * It supports multimedia;
    * It supports internationalization (i18n), with built in English, Chinese (simplified & traditional) and Japanese languages support;
    * It has a very easy-to-use and intuitive user interface;
    * It has an effective AI logic to demonstrate how to play this game.

    About AI:

    The AI part was implemented in following way:

    The basic idea was to try to turn and put the coming block at each possible positions, evaluate the results, then choose the best one. But how to evaluate the result is the main problem.

    First, we need to find which factors affect the final result, and get them out. For example, the height is definitely not a good thing (0 is the best); and holes under other blocks are evil, and so on. Then put these factors into a formula, with a set of coefficients, one for each of the factors. Now the remaining problem is to find the optimal vector of coefficients.

    In order to do that, a training program is needed. I prefer the ‘quick-death’ way to screen out the bad ones as quickly as possible. So I just put it in a server and let it run during the day while I left home to work, and when I came back home at night, I got the result…

    Click here to have fun with this Tetris game!