Block Access from a Range of IP Addresses

There are some guys from certain locales who keep posting spamming comments to my web site on a daily basis. Although most of them were caught automatically and won’t be shown, yet some of the spammers spam so frequently with very big posts, it’s really annoying to delete these periodically in order to avoid the waste of resourses.

Analyzing the IP addresses of these spammers, we can find that some of the most active spammers use a different IP address every time (they may intentionally use dynamic IP address provided by their ISP’s), so that you can hardly block them, for enumerating all the IP addresses in config files of Apache or firewall is very tedious. But fortunately, all these IP addresses belong to the same IP range (I think that the spammer didn’t use a proxy), and normal internet surfers from this IP range are hardly willing to browse my web site due to language / locale / interest reasons. So we can simply block the access from all IP addresses in this range. For this reason, I created this “IP Range Calculator” online tool to make this process easier: it does the tedious IP address mask & CIDR calculation and generates firewall commands as well as proper lines for Apache’s config file.

Here is a real example. Note that I don’t have any discrimination to people or IP addresses in this range, just as I said, a real surfer from this range won’t actually browse my web site, and the only ones who do access my web site are usually spammers. So it’s not unfair to restrict access from this range.

First, get one of the most frequent spammer’s IP addresses:

Then use “whois” service to get the IP range:

Now launch the “IP Range Calculator“, enter the IP range got from whois, and click “Calculate” button. Then the calculation result is used to generate related firewall commands and lines for Apache config file to block the IP addresses. You can use either of them according to your needs.

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

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.

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!

Japanese Calendar

(click on image to use calendar)
(click on image to use calendar)

This is an online Japanese calendar, based on the wonderful online Chinese calendar written by Sean Lin.

This is very handy to check when you don’t have a calendar at hand. I made mistakes like rushing to office and eventually found that I was the only one there because it was a holiday. This calendar can help to prevent this kind of mistakes.

What I did:

  • replaced Chinese holidays with Japanese holidays
  • added the algorithm of calculating ‘furikae kyuujitu’ (振替休日)
  • added calculation of ‘rokuyou’ (六曜)
  • i18n & l10n
  • designed the GUI or the layout as shown in the screen shot.

Check Japanese calendar here.