Chủ Nhật, 8 tháng 11, 2015

RomajiDesu has been updated with smart Japanese word decomposition

Watching real time search of user using Google analytics was somewhat very interesting. Many users, I suppose beginners, searched a verb in a changed form, not dictionary form - jishokei (辞書形). It made me think of my early days when self studied Japanese by trying to understand a favorite Japanese song, by copying a whole words into a dictionary without getting anything.

In the  the earlier version of RomajiDesu's Japanese Dictionary, if you searched "見てください", there'd be no result. But in this version, you will get the jishokei of the verb "見る", as well the possible conjugation form "Polite Imperative" (command). So from the verb (miru - look), and the inflection (polite imperative), you can easy guess the meaning: "Please look!"


It also words with Japanese noun and and adjective. And if you put in the search field a complex Japanese sentence, RomajiDesu will automatically decompose it into small and comprehensible components (which is similar to RomajiDesu's Japanese Translator). For example, "RomajiDesuが大好きです", into "RomajiDesu ga Daisukidesu" (I love RomajiDesu)





Chủ Nhật, 11 tháng 10, 2015

Wind visualization for meteorologist

This is my new creation for my department to visualize wind on different levels and forecast times. Streamline map is a very useful tool for forecasters, an animated wind map with speed indicator is even more useful I think. This is done using d3js and pure canvas javascript.

Thứ Tư, 11 tháng 3, 2015

New feature with RomajiDesu Kanji dictionary

RomajiDesu's Kanji dictionary has been updated with Chinese pinyin, Korean reading and Sino-Vietnamese (Hán Việt) reading. The updates have been done due to some suggestions from RomajiDesu users.  I don't really know how useful these updates are but as a Vietnamese, I found it's really cool to see how many words in Vietnamese, Chinese, and Japanese is related. The photo is my name (Hải) written Kanji, which means 'the sea' and pronounces  'hǎi' in Chinese, 'hae' in Korean, and 'kai' in Japanese ^_^

Thứ Ba, 13 tháng 1, 2015

A simple example of Delegate Pattern in Swift

Well, I've just start self learning to program iOS apps using Swift programming language. One early thing that you stumble into when learning it is a concept call "Delegate pattern". It's quite confusing for a self-taught learner like me and I've looked around for a good simple example. In wikipedia, there an article that explain the concept with many languages. However, I don't like the the functions and class names. So I try to rewrite the example which is simpler and funnier. Well, there's ways to go with Swift and iOS, but at least the first steps must be interesting, huh?

protocol AnimalBehavior {
    func eating()
    func calling()
}

class DogBehavior : AnimalBehavior{
    func eating(){
        println("The DOG is eating...")
    }
    func calling(){
        println("Wufff! Wufff!")
    }
}

class CatBehavior : AnimalBehavior{
    func eating(){
        println("The CAT is eating...")
    }
    func calling(){
        println("Meowwwww")
    }
}


class Animal{
    var behavior: AnimalBehavior;
    init(){
        behavior=DogBehavior();
    }
    func eating(){
        behavior.eating()
    }
    func calling(){
        behavior.calling()
    }
    func isACat(){
        behavior=CatBehavior()
    }
    func isADog(){
        behavior=DogBehavior()
    }
    
}


let myPet=Animal() // Notice this is not a variable but const
myPet.isACat();
myPet.calling(); // Meowwwwww
myPet.isADog();

myPet.calling(); // Wufff! Wufff!

Thứ Ba, 28 tháng 10, 2014

A little girl can help preserving Vietnamese traditional folk art?

Traditional folk art is something any nation wants to preserve but it's not always simple. I remembered one evening in 2013, we went to watch a Japanese Noh play "AMA" in a famous Noh theatre near Heian Jingu in Kyoto. The play was opened for free in order to introduce this special kind of Japanese traditional performance art to people, Japanese or 'gaijin' (foreigner). Even so, not all the seats were occupied. The reason is, even with the free leaflet that guided you how to enjoy the show, not many people in the theatre understand what's going on with the show. A native Japanese lady sat next to us said even she didn't fully understand the lyrics, which seems to be in old Japanese. Also, most of my Japanese friends say that they have never been watching a Noh play before.

Back to Vietnamese traditional art, "Chầu Văn" is a similar example. Originated around 16th century, it purpose is to serve Vietnamese traditional religious ritual (Đạo Mẫu), the genre once became a very popular kind of art. Now a day, Chầu văn is one of the national heritages of traditional culture. And again, not many people, especially young people, understand this genre. I've watched and listened to Chau Van many times before, but I didn't understand or enjoyed it either. Most other people simple don't care about this special art.

Until one day, this little kid showed up in the finale of Vietnamese's The Voice kid, 2014. Her beautiful performance and maybe her innocence, some how made the Chau Van song "Cô Đôi Thượng Ngàn" became so lively and enjoyable. Countless of young people gave whole hearted compliment to the performance and started to be interested in this type of art. Thien Nhan (the girl) became the champion of the show, and somehow give out this kind of art to many people, especially youngsters.

If you have no idea of what Chau Van is, then enjoy watching this




Thứ Sáu, 27 tháng 6, 2014

A new Japanese Translator and Morphological Analyser

Years ago, I stumbled on some of my favorite songs in Japanese and I always want to know the meaning of them. Many foreigner fans know Japanese lyrics in Romaji without knowing the meaning or how they write in Japanese. That's the reason I created the a Romaji to Hiragana/Katakana converter wich later became a comprehensive website that assisting learning language: RomajiDesu. Later, I stumbled on songs that I can only find the lyrics in Japanese and a natural need is to know how to pronounce them, ie. to convert from Japanese to Romaji. I did make such a converter back then using Edict Japanese dictionary and my simple PHP code. But I removed it from RomajiDesu after that because its performance is bad and the converter cannot perform well with such a complexity language as Japanese.

It's been a while since I meet Mecab, (Yet Another Part-of-Speech and Morphological Analyzer), and it's time I put back the converter, now called RomajiDesu Online Japanese Translator. The formula is:

Mecab + Edict + Kana to Romaji + Google translation = RomajiDesu translator.

 The result is as follows (Figure 1):
Figure 1. A screen short from RomajiDesu's Japanese translator. The text is a paragraph from the song "Mirai e", (to the future) by Kiroro.
The current result is quite a satisfactory to me as it perform very fast, the translated Romaji/Kana is quite correct. And more important, the original text is decomposed into small part-of-speech elements which will shows more information when I hover the mouse over theme (Fig. 2). A very useful features is that, the translator will indicate the original base form (dictionary form) of the words. When I click on the words, I will get the meaning by looking up from the Japanese dictionary.

Figure 2. As figure 1 but when the mouse is over.
The last feature is the translated English, this is actually done by Google section translation, the best machine translation out there in my opinion. However, since Japanese language is very complexity, even Google translation is still far from acceptable translation for complex sentences. However, it's quite correct for simple structures and still serve as a reference for the more complex ones.




Thứ Tư, 26 tháng 3, 2014

How to remember the Kanji: Sakura 桜.


Has the Sakura () season started in Japan?

I took this photo Osaka Castle (大坂城 - Ōsaka-jō) in Sakura season last year. Sadly I am not staying in Japan currently, but I can imagine the pink sakura blossoms start lighting up the country, from the south to the north.

So how do you remember the Kanji ? To me, there's a woman (女) on the right who is enjoying the
sakura petals (⺌) falling from above near a sakura tree (木) on the left. It seems to be logical, right? ;)
How about you?

I miss Kyoto, Japan!


Thứ Ba, 10 tháng 9, 2013

How to log MySQL slow queries

Since I upgraded mywebsite to VPS, I can analyse the slow queries by loggin them into a file without restarting mysql as follows:

# touch /var/log/slow
# chown mysql:mysql /var/log/slowqueries
# mysql -e 'SET GLOBAL slow_query_log=1;'
# mysql -e 'SET GLOBAL slow_query_log_file="/var/log/slowqueries";'
# mysql -e 'SET GLOBAL long_query_time=5;'

Or I can add these lines to my.cnf:
slow_query_log=1
slow_query_log_file=/var/log/slowqueries
long_query_time=2

To test if it is working correctly, try:
# mysql -e 'SELECT SLEEP(6);'

Chủ Nhật, 1 tháng 9, 2013

Romajidesu is back!

After three days upgrading, RomajiDesu Japanese dictionary is back on a new powerful VPS server. After one year, Romajidesu steady gain the trust from Japanese leaner community and the traffic reach approximately 3000 visits per days, or nearly 20000 page views per day. Another great upgrade of RomajiDesu before that is the website framework. The underline framework is also upgraded to a more powerful and extensible one, which cannot be seen from the surface.


Thứ Ba, 23 tháng 7, 2013

Audio pronuciation on RomajiDesu

If you are a frequent users of the RomajiDesu English - Japanese dictionary, you must have noticed the difference, there are a small speaker icons next to Kana definition of each dictionay entry. Click on that, and you will hear the audio pronunciation for the word. For example:
A sample search for "恋人" (Lover) using RomajiDesu dictionary
Have fun learning Japanese!

Thứ Năm, 28 tháng 2, 2013

Farewell Paypal, never see you ever again!

I opened my Paypal account in 2007 but haven't used it since then until recently we have a charity cause to help a friend who has a brain tumor. Our friends oversea offered help and I thought Paypal is a the best way for them to send money to help. I logged in to my Paypal account and got account verification. The verification itself was not comfortable because they seemed not to recognize the security number on my Visa debit card, so they charge $1.95 and I had to call my bank to get the verification code.

Just after the a second donation was made, I received two email said that my account was limited again because:


Feb 26, 2013: We need a bit more information about some money you recently received or withdrew.(Your case ID for this reason is PP-002-223-472-153.)
Feb 26, 2013: We've noticed some changes to your usual account activity. As a security precaution, we'll need a little more information about you and your account.
(Your case ID for this reason is PP-002-223-472-236.)

Well, it seems that I just need to log into the resolution center and choose the case ID and provide them answer or proof, right? There are nothing to choose there. There is a section to verify a credit card, but I need to add another card and verify again! WTF?

So I chose email contact and provided them information of the two above cases.  They did kindly answer an email said that give time 01 day for reviewing my account. Then, after 02 days, this is what I received:

For the safety and security of the PayPal network, we often review accounts for potential risks. After reviewing your account, we have decided to close it because of security issues. We are making every effort to minimize any disruption to your business. If your PayPal account balance is zero, and you have no unresolved buyercomplaints or chargebacks, your account will remain limited. 
-----------------------------------Disbursement options----------------------------------- 
Option 1. If you owe refunds to any of your buyers, you can use the money in your PayPal account to refund them.To refund your buyers:1. Log in to your PayPal account.2. Click "Contact Us" at the bottom of any page.3. Click "Contact Customer Service."4. Under "Choose a Topic," select "Sending/Receiving Money."5. Under "Choose a Subtopic," select "Refund/Cancel a Payment."6. Click "Continue" and follow the instructions to refund payments. 
Option 2. Money in your PayPal account will be held for 180 days. After 180days, we'll email you information on how to receive your funds.We regret any inconvenience this may cause.

It's so dissapointing, but of course I chose Option 1. However, again, there is no "Contact Customer Service"!!. I took me sometimes to figure out that should be "email us" section.

It can be understandable cares must be taken especially with countries which have many suspicious activities. But it is so disappointing since they just close a account with no clear reason. And  the process was also confusing and annoying. I've had the most horrible experience I've ever had.

Well, thank you and farewell Paypal.

Thứ Bảy, 24 tháng 11, 2012

How to Redirect Mobile Users to Your Mobile Site using PHP

Recently, I've developed the mobile version of the English Japanese Dictionary with the subdomain m.romajidesu.com, now I want an effective way to redirect mobile users to mobile version.

PHP mobile detection or JavaScript detection?

There are some considerations, the first one is you can use a client-side (javascript) or server-side redirection (PHP). Some people say that redirection using javascript is more accurate. However to me, loading the whole website until it redirect is a waste of time users and server resources, that's why I choose PHP redirection.

The PHP mobile detection techniqe

The second consideration is how to detect if a user is on a device or not. Of course I wouldn't re-invented the wheel, I googled for several techniques out there. Basically, all detection code based on some global variables, notably $_SERVER['HTTP_USER_AGENT'], to determine if a request is from a mobile device or not. There are some way to check using regular expression, array checking or just regularly if-block. To determine which one is faster, I write a code to benchmark it. The code is somewhat like this:
$start_time=microtime_float();
if (is_mobile()){    
    echo '<br/> mobile';
}else{
    echo '<br/> not mobile';
}
echo "<br/>".(microtime_float()-$start_time);
$start_time=microtime_float();
if (is_mobile1()){    
    echo '<br/> mobile';
}else{
    echo '<br/> not mobile';
}
echo "<br/>".(microtime_float()-$start_time);
Where is_mobile is a function using normal if-block checking and is_mobile1 is a function  regular expression technique. The out put of the program is as follows:
not mobile
8.1062316894531E-5
not mobile
0.00014901161193848
So in generally, the first function perform about 2x faster than the second one. I adopt the function from Russell Beattie's blog with just few modification as follows:
function is_mobile(){
    $op = isset($_SERVER['HTTP_X_OPERAMINI_PHONE'])?1:'';
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    $ac = strtolower($_SERVER['HTTP_ACCEPT']);
    if (strpos($ac, 'application/vnd.wap.xhtml+xml') !== false
        || $op != ''
        || strpos($ua, 'sony') !== false 
        || strpos($ua, 'symbian') !== false 
        || strpos($ua, 'nokia') !== false 
        || strpos($ua, 'samsung') !== false 
        || strpos($ua, 'mobile') !== false
        || strpos($ua, 'windows ce') !== false
        || strpos($ua, 'epoc') !== false
        || strpos($ua, 'opera mini') !== false
        || strpos($ua, 'nitro') !== false
        || strpos($ua, 'j2me') !== false
        || strpos($ua, 'midp-') !== false
        || strpos($ua, 'cldc-') !== false
        || strpos($ua, 'netfront') !== false
        || strpos($ua, 'mot') !== false
        || strpos($ua, 'up.browser') !== false
        || strpos($ua, 'up.link') !== false
        || strpos($ua, 'audiovox') !== false
        || strpos($ua, 'blackberry') !== false
        || strpos($ua, 'ericsson,') !== false
        || strpos($ua, 'panasonic') !== false
        || strpos($ua, 'philips') !== false
        || strpos($ua, 'sanyo') !== false
        || strpos($ua, 'sharp') !== false
        || strpos($ua, 'sie-') !== false
        || strpos($ua, 'portalmmm') !== false
        || strpos($ua, 'blazer') !== false
        || strpos($ua, 'avantgo') !== false
        || strpos($ua, 'danger') !== false
        || strpos($ua, 'palm') !== false
        || strpos($ua, 'series60') !== false
        || strpos($ua, 'palmsource') !== false
        || strpos($ua, 'pocketpc') !== false
        || strpos($ua, 'smartphone') !== false
        || strpos($ua, 'rover') !== false
        || strpos($ua, 'ipaq') !== false
        || strpos($ua, 'au-mic,') !== false
        || strpos($ua, 'alcatel') !== false
        || strpos($ua, 'ericy') !== false
        || strpos($ua, 'up.link') !== false
        || strpos($ua, 'vodafone/') !== false
        || strpos($ua, 'wap1.') !== false
        || strpos($ua, 'wap2.') !== false)
        {return true;}
        else{ return false;}
}  

The redirection code 

Now come to the fun part, which I haven't seen many people posted on the internet. What I want is, if a user visit www.romajidesu.com for the first time, he/she will be redirected to m.romajidesu.com, but if he/she somehow doesn't like the mobile version and go black to the standard website by click on the link on the bottom, he/she should not be redirected. The flowchart is somewhat as the image bellows
The following is the actually code, which can be included at the beginning of any page you want to be redirect automatically (of course you have to change the domain name)
$arr = explode('.', $_SERVER['SERVER_NAME'], 2);
$sub=$arr[0];
$need_redirect=false;
if (!isset($_SERVER['HTTP_REFERER'])){
    $need_redirect=true;
}else{
    $domain = parse_url($_SERVER['HTTP_REFERER']);   
    $host = $domain['host'];
    if (!preg_match('/romajidesu\.com/', $host)){
        $need_redirect=true;        
    }    
}
if ($need_redirect && ($sub!='m') && is_mobile() ){
    $old_url=$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
    $new_url='http://'.str_replace('www.', 'm.', $old_url);
    header("Location:".$new_url);die();
}

Thứ Tư, 21 tháng 11, 2012

RomajiDesu mobile version 1.0

Finally RomajiDesu Japanese features a dedicated mobile version! When enter romajidesu.com on a mobile device, you will be redirected to the mobile version at (m.romajidesu.com). 

The design of the mobile version is much simpler and clearer to ensure best experience on smart phones and even tablets. It features a responsive design that automatically choose the appropriate font sizes for different resolutions.

Of course you can always switch back the the standard version anytime you want.

Thứ Tư, 10 tháng 10, 2012

Minor updates on RomajiDesu

There are some minor updates to get to the version 2.1 today. Some updates includes:
- Improvement of look up speed thanks to caching mechanism.
- A social twitter button has been added, now you can share to your friends fast and easily.
- A Bookmarklet button is added, you drag the bookmarklet to your toolbar, select any word on any website, and click on it to look up the word.

It's almost two months since RomajiDesu version 2.0 has been officially launched. Since then, the traffic to Romajidesu has almost tripled from around 500 visits per day to 1400 visits per day. I am so happy today when I saw RomajiDesu appeared on a review on Lifehacker.jp. The article was announced by a lot of people which then immediately drew a lot of attention to the dictionary.

Thứ Bảy, 18 tháng 8, 2012

Romajidesu 2.0 has officially launched!

I am really happy to announce that RomajiDesu English Japanese dictionary version 2.0 has officially launched after several weeks of hard working! The new version is really a out-standing one with a lot of new features and stuffs which are optimized in terms of look-and-feel and performance.

So what's new about the new version? The first innovation is the new English Japanese dictionary, the former dictionary result has been replaced by a much richer content with related words, relevant examples and a beautiful layout (Fig. 1). The performance also increases dramatically thanks to the intelligent caching.
Figure 1. A sample result page

 A brand new Kanji dictionary has been included. The Kanji dictionary is empowered with an advanced Kanji search form and a multiple Kanji lookup methods. Without complicated input as other dictionary out there, here you can search for a Kanji directly, or by English meaning, or number of strokes, or a specific grade, etc.  The result page will high-light popular (joujou) Kanji and put the English meaning there for you (Figure 2).
Figure 2. A sample result page for Kanji Lookup.

The Kanji Detail page is real deal with lots of useful information such as ON reading and KUN reading, related Japanese words and meanings,...and a nicely rendered stroke order diagram. (Fig. 3).

    Figure 3. A sample result page for Kanji Lookup. 

      Figure 4. A fast and useful methods of looking up Kanji by selecting multiple Kanji radicals 
    Last but not least, the Kanji dictionary includes a powerful Multiple Kanji radical lookup methods. The result page is also use the smart card display which include a short English discription (Fig. 4). So if you are a Japanese learner, check it out and I strongly believe that you will love it. But if you have any suggestion of how to improve the dictionary, please leave a comment here.

    P/S. The section Japanese to Romaji has been remove from the homepage temporarily because I want to improve it in terms of accuracy and performance. If you are capable of implement such thing, please contact me.

Chủ Nhật, 1 tháng 7, 2012

RomajiDesu Japanese dictionary - a major update

RomajiDesu website has been updated to a new version (1.1).

The most importance improvement is the inclusion of the large example sentence database of Tanaka Corpus. 

To look for meaning of Japanese word and example sentences, you only need to type in a single input! And as before, you can type in Original Japanese, or Hiragana, or Romaji, or English!

The result page now may contains up to two tabs: Words (definition) and Sentences (examples contain the searched word). Each record of examples sentences is beautifully rendered with clickable word and hiragana pronunciation if available (Furigana style). You can click on "more" for more results also being loaded and displayed gracefully.
If you are a Japanese learner, you definitely should check out, for example, the meaning of love in Japanese.

Source: RomajiDesu.

Thứ Bảy, 30 tháng 6, 2012

About exporting/importing MySQL database via SSH

I used to use phpMyAdmin to do everything related to MySQL. However, now I am coding the website Romajidesu, which contains large dabase of Japanese dictionary with example sentences, importing/Exporting MySQL data using only phpMyAdmin alone seems to be very slow if not impossible. So here's the ways to do it (via SSH).


Step 1. Export A MySQL Database

It is a good idea to export your data as often as possible for backup or for moving data from localhost to server.
From SSH or command shells, execute the following command:
mysqldump -u username -p database_name > dbname.sql 
You will be prompted for a password, type in the password for the username and press Enter. Replace username, password and database_name with your MySQL username, password and database name.
File dbname.sql now holds a backup of your database and is ready for download to your computer or upload to server. If you just want to backup a specific table, use this command:
mysqldump -u username -p database_name  table_name > dbname.sql 
One more thing you can do is gzip the file to save the upload/download time, I find gzipping reduces the file size  6 times in my case. From SSH, execute the following command:
gzip dbname.sql 
The final file will has the form dbname.sql.gz

Step 2. Import A MySQL Database 

In case you used gzipped file, you need to ungzip in as the importing file must be in .sql format.  From SSH, navigate to the directory where your .gz file is and execute the following command:
 gunzip dbname.sql.gz 
When you have your .sql file, run this command: 
 mysql -p -u username database_name < file.sql 

Thứ Năm, 7 tháng 6, 2012

Look up Japanese word on Romajidesu!

To all Japanese language lovers! 
Romajidesu have just added an unique dictionary for looking up Japanese word.  I am really happy with the simple, clear and effective interface of it. The cool thing about the dictionary is that you can type in Japanese words (Kanji/Hiragana/Katakana) or even Romaji and English to look up the meaning.
Check it about at English/Romaji Japanese dictionary and brave yourself for more cool stuffs to come!

Chủ Nhật, 22 tháng 4, 2012

RomajiDesu version 1.0b released

I am so excited to launch my latest website - RomajiDesu. It's is a free website which has several tools for assist Japanese learners. Currently (Version 1.0b), RomajiDesu has three tools:
  • Romaji to Hiragana: Basically you can type or copy Romaji (e.g. an Japanese song) to convert to Hiragana script. You can also translate it into English (I use Google translate engine). The translation of course is far from perfect, but sometimes it's useful to get the general meaning.
  • Romaji to Katakana: Convert Romaji to Katakana, basically you just use to get the foreign words (like: hotel->hoteru->ホテル).

Developing it is a lot of fun because it combines two of my hobbies: programming and learning Japanese :)

Thứ Năm, 17 tháng 2, 2011

Cài đặt Zendframework với Xampp trên windows XP

Cài đặt ZendFramework

- Cài XAMPP, vd dụ vào C:\xampp

- Giải nén zend framework vào trong thư mục cài đặt xampp, ví dụ: C:\xampp\php\ZendFramework-1.11.3

- Thêm vào biến môi trường Path của windows:

o C:\xampp\php";C:\xampp\php\ZendFramework-1.11.2\bin;
(Bằng cách chuột phải vào My Computer à Properties à Advanced à Enviroment Variables)

- Thêm vào php.ini:

o include_path = ".;C:\xampp\php\ZendFramework-1.11.3\library"

Lưu ý

- Không có dấu cách giữa các path

- Có thể cần xóa zf.bat cũ trong C:\xampp\php

Sử dụng công cụ zf.bat

Xem thông tin phiên bản, hướng dẫn sử dụng

Vào Start à Run: cmd,

zf show version

zf --help

Tạo project

Di chuyển đến thư mục của project, ví dụ:

cd C:\xampp\htdocs\projects\

Gõ lệnh

zf create project [tên thư mục project]

Ví dụ

zf create project funstir.com

Sẽ tạo cài đặt một nền tảng trống vào C:\xampp\htdocs\projects\funstir.com

Khi khởi động localhost, vào địa chỉ http://localhost/projects/funstir.com/public

Sẽ hiển ra trang chủ của project mới tạo