I've just come across a Grails plugin called PrettyTime and I find it's really interesting library. Basically, it's utility library to format Date/Time value in a human-friendly form (eg: "right now", "two days ago", "3 months from now"...), it also supports localization for many languages but Vietnamese. So I decide to write a small resource bundle class for it.
package com.ocpsoft.pretty.time.i18n;

import java.util.ListResourceBundle;

public class Resources_vi extends ListResourceBundle
{
   private static final Object[][] OBJECTS = new Object[][] {
   { "CenturyPattern", "%n %u" },
   { "CenturyFuturePrefix", "" },
   { "CenturyFutureSuffix", " sau" },
   { "CenturyPastPrefix", "cách đây " },
   { "CenturyPastSuffix", "" },
   { "CenturyName", "thế kỷ" },
   { "CenturyPluralName", "thế kỷ" },
   { "DayPattern", "%n %u" },
   { "DayFuturePrefix", "" },
   { "DayFutureSuffix", " sau" },
   { "DayPastPrefix", "cách đây " },
   { "DayPastSuffix", "" },
   { "DayName", "ngày" },
   { "DayPluralName", "ngày" },
   { "DecadePattern", "%n %u" },
   { "DecadeFuturePrefix", "" },
   { "DecadeFutureSuffix", " sau" },
   { "DecadePastPrefix", "cách đây " },
   { "DecadePastSuffix", "" },
   { "DecadeName", "thập kỷ" },
   { "DecadePluralName", "thập kỷ" },
   { "HourPattern", "%n %u" },
   { "HourFuturePrefix", "" },
   { "HourFutureSuffix", " sau" },
   { "HourPastPrefix", "cách đây " },
   { "HourPastSuffix", "" },
   { "HourName", "giờ" },
   { "HourPluralName", "giờ" },
   { "JustNowPattern", "%u" },
   { "JustNowFuturePrefix", "" },
   { "JustNowFutureSuffix", " khắc sau" },
   { "JustNowPastPrefix", "cách đây " },
   { "JustNowPastSuffix", " khắc" },
   { "JustNowName", "" },
   { "JustNowPluralName", "" },
   { "MillenniumPattern", "%n %u" },
   { "MillenniumFuturePrefix", "" },
   { "MillenniumFutureSuffix", " sau" },
   { "MillenniumPastPrefix", "cách đây " },
   { "MillenniumPastSuffix", "" },
   { "MillenniumName", "thiên niên kỷ" },
   { "MillenniumPluralName", "thiên niên kỷ" },
   { "MillisecondPattern", "%n %u" },
   { "MillisecondFuturePrefix", "" },
   { "MillisecondFutureSuffix", " sau" },
   { "MillisecondPastPrefix", "cách đây " },
   { "MillisecondPastSuffix", "" },
   { "MillisecondName", "mili giây" },
   { "MillisecondPluralName", "mili giây" },
   { "MinutePattern", "%n %u" },
   { "MinuteFuturePrefix", "" },
   { "MinuteFutureSuffix", " sau" },
   { "MinutePastPrefix", "cách đây " },
   { "MinutePastSuffix", "" },
   { "MinuteName", "phút" },
   { "MinutePluralName", "phút" },
   { "MonthPattern", "%n %u" },
   { "MonthFuturePrefix", "" },
   { "MonthFutureSuffix", " sau" },
   { "MonthPastPrefix", "cách đây " },
   { "MonthPastSuffix", "" },
   { "MonthName", "tháng" },
   { "MonthPluralName", "tháng" },
   { "SecondPattern", "%n %u" },
   { "SecondFuturePrefix", "" },
   { "SecondFutureSuffix", " sau" },
   { "SecondPastPrefix", "cách đây " },
   { "SecondPastSuffix", "" },
   { "SecondName", "giây" },
   { "SecondPluralName", "giây" },
   { "WeekPattern", "%n %u" },
   { "WeekFuturePrefix", "" },
   { "WeekFutureSuffix", " sau" },
   { "WeekPastPrefix", "cách đây " },
   { "WeekPastSuffix", "" },
   { "WeekName", "tuần" },
   { "WeekPluralName", "tuần" },
   { "YearPattern", "%n %u" },
   { "YearFuturePrefix", "" },
   { "YearFutureSuffix", " sau" },
   { "YearPastPrefix", "cách đay " },
   { "YearPastSuffix", "" },
   { "YearName", "năm" },
   { "YearPluralName", "năm" },
   { "AbstractTimeUnitPattern", "" },
   { "AbstractTimeUnitFuturePrefix", "" },
   { "AbstractTimeUnitFutureSuffix", "" },
   { "AbstractTimeUnitPastPrefix", "" },
   { "AbstractTimeUnitPastSuffix", "" },
   { "AbstractTimeUnitName", "" },
   { "AbstractTimeUnitPluralName", "" } };

   @Override
   public Object[][] getContents()
   {
       return OBJECTS;
   }
}

Hopefully they will integrate this snippet into the next release of PrettyTime.
A couple months ago, I moved my blog from Blogger to Wordpress, that's because Wordpress offers some nice themes. Recently, I've bought a new domain (my first domain actually) and I want to use that domain for my blog but it costs me 10$/year to use custom domain in Wordpress! Searching around and I found that Blogger let you use your custom domain for free with hassle-free setup. Horay!
Then I moved back to Blogger, but the problem arises, the ugly theme! I think it's the right time for me to learn CSS and start hacking Blogger API. And after 2 weeks of hard working, I've finished my custom theme for Blogger based on Natural Power theme for Wordpress.
I'm quite happy with the result I've got so far. Not too bad for a CSS newbie.
From the normal user perspective, Wordpress provides many useful functionality out of the box, but if flexibility is your top priority, Blogger is your best choice so far.

Some thoughts about Grails

I've just finished my first Grails project. To be honest, it's a quite good mind refreshment for me as a Java developer. Grails simplify alot of complex stuff of Java ecosystems like IoC(Spring), ORM(Hibernate), XML configuration with convention over configuration. It takes you less than 10 minutes to create a full working web application with Spring Security for authentication and authorization, Quartz for job scheduling and Hibernate for data persistence when you're familiar with it. Here are some Pros and Cons:
Pros:
  • Almost "zero learning effort" for Java developers (although it almost took me a week to get productive with it)
  • No XML configuration
  • GORM is much easier to work with comparing to Hibernate (both XML-based and annotation-based), dynamic methods for domain class is definitely a good selling point for me here. It saves me tons of DAO code.
  • Lots of plugins to extend Grails functionalities
Cons:
  • Grails heavily uses convention-over-configuration but the documentation about conventions is not enough. Sometimes it get frustrated when you reading someone's code without knowing the convention his/her using.
  • Bugs. Lots of it, just navigate to JIRA of Grails and you will know what I mean :)
  • Lacking of good IDE support. First I've tried Spring STS, then NetBeans, then IntelliJ IDEA Ultimate (free trial) and finally finishing my first Grails project in Gedit!
Grails is a great framework and I'm still learning it.
I've uploaded a PKGBUILD for ibus-unikey to the ArchLinux AUR. You can install it with yaourt like this:
yaourt -S ibus-unikey
If you don't want to build from the source, you have to install all the dependencies first:
pacman -Sy gcc gconf gtk2
And then download and install the binary package
Then add the following to your .bash_profile

export XMODIFIERS=@im=ibus
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus

PS: Ok, there is no spyware/malware/rootkit in this binary package! If you don't trust me, don't use this method and build the package yourself (this is the way I recommend)
I've just joined a project as a freelancer to customize a commercial e-commerce solution (so let called it EP). OOTB, the email sending of EP does not support authentication, which is a weird thing for such a cool product like that. Actually, EP does declare an JNDI mail session in the context, but in the code they don't use it. With the source code of EP in hand, things get much easier. First, we declare a JNDI resource in our application context (either in your context file in the conf/Catalina/localhost/ or in your context.xml under META-INF inside your war):
<context>
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"
username="my.smtp.user"
password="my-secret"
mail.debug="false"
mail.transport.protocol="smtp"
mail.smtp.host= "xxx.xxx.xxx.xxx"
mail.smtp.auth= "true"
mail.smtp.port= "25"
mail.smtp.starttls.enable="true"
description="Global E-Mail Resource"
/>
</context>
And put those in your web.xml file:
<resource-ref>
<description>Email Session</description>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
And now, in your Java code, you will use this email session like this:
Context initContext = new InitialContext();
Context context = (Context) initContext.lookup("java:comp/env");
Session mailSession = (Session) context.lookup("mail/Session");
//Your code to send the email goes here
If you get a java.lang.ClassCastException, don't worry, this is a known issue. It's because you have multiple Java Mail jar file and Java Activation Framework jar file in your CLASSPATH!
Hope that may help!

Moving to Wordpress

I've just imported all my post and comments from blogger.com to my wordpress.com account. So far so good! I've also cleaned up all of my posts on wordpress.com to make it *cleaner*. Wordpress.com does come with a cool code syntax highlighter as described here http://support.wordpress.com/code/ , the number of programming language it supports is quite impressive.
By the way, I've just found out some cool tricks to use the built-in code highlighter of wordpress. Instead of typing [sourcecode language='css'] code here [/sourcecode], you can use one of the following:
  • [source language='css']code here[/source]
  • [code language='css']code here[/code]
  • [sourcecode lang='css']code here[/sourcecode]
  • [source lang='css']code here[/source]
  • [code lang='css']code here[/code]
  • [sourcecode='css']code here[/sourcecode]
  • [source='css']code here[/source]
  • [code='css']code here[/code]
Enjoy!
I always use PostgreSQL for every project in my company, both in development and production. Recently, I have to use MySQL (version 5.1.36) in my new project because the client uses MySQL for deployment. The first step I have to do is to setup MySQL on my laptop for the project development, I'm using ArchLinux so the steps are straight-forward:
  • Install MySQL with the pacman: pacman -S mysql
  • Start it up: /etc/rc.d/mysqld start
  • Set the root password: /usr/bin/mysqladmin -u root password 's3cr3t'
  • Execute the recommended script to secure the new MySQL installation. Basically, the script will remove the test database, the anonymous users and only allow connection from localhost: /usr/bin/mysql_secure_installation
Here come the gotchas!
I open up MySQL Administrator and connect to the new 'shiny' server with the user 'root', everything is fine. I create a new user, then a new catalog and grant all the neccessary permissions for the new user to use the new catalog. I fire up Tomcat which contains my web application (Spring + Hibernate), the application creates a connection pool (c3p0) at startup to improve performance, but it failed with the error message Connection refused". Hmm...strange! Googling for a while, I was suggested to put this into my /etc/hosts.allow the following line:
mysqld: 127.0.0.1:ALLOW
Restart my web application, now the error message is different Communications link failure .... Open up the configuration of MySQL (/etc/my.cnf), I found out that the skip-networking is on! Here is the documentation about this entry:
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
Comment that entry (by adding the # before it) and restart the mysql server. My web application now can startup properly!
Gotchas solved.
PS: I'm totally new to MySQL, this is my way I made my application work with MySQL, if you have a better setup, I'm glad to know :)