Monday, December 22, 2008

Solving Table Name Case Sensitive Problem of Mysql on Linux

Table name case sensitivity issue is a common problem to hit when you are trying to port an application to use Mysql on Linux. You can set the Mysql to always store table name in lower case by setting the startup parameter lower_case_table_names=1.

You can type the following to check if the parameter is set or not:-

mysqladmin -u root -p variables


If it is not set, you can set it by editing /etc/mysql/my.cnf:

sudo gedit /etc/mysql/my.cnf

In my.cnf, it should have portions like this:-

[mysqld]
#
# * Basic Settings
#

#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

lower_case_table_names=1

user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking


Then, restart the server:-

mysqladmin -u root -p shutdown
sudo mysqld

Thursday, December 18, 2008

Email, How Reliable is it?

Email is one of the most important application in Internet today beside Web. However, it has become a channel where hackers target to steal confidential information such as login info from user. One of the most popular trick is to masquerade and send a fake email, saying the user account is going to expire and ask the user to login with a fake hyperlink, which link to a fake page with similar design to the real login page.

From technical point of view, how easy to send a fake email? The answer to this question is : 'It's very simple'.

You do not need to write a C program, BackTrack 3 or any hacker tool. You can easily do it with high level language such as Java. It depends on how your email provider securing their SMTP server, but in my case, most of the companies that I have worked with is having their SMTP that you can easily send a fake mail.

At very basic level, these few lines of Java code using Spring Framework can masquerade as 'Your Boss' and send out an email to your colleague saying that he is fired:-

JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("mail.yourcompany.com");
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom("Boss <yourboss@yourcompany.com>");
helper.setTo("your_colleague@yourcompany.com");
helper.setSubject("You're Fired!");
helper.setText("I am very unhappy with your face, you're fired!!!");


You still will be able to find out which machine this email is sent from if you examine the email's properties. We joked with one of our colleague years ago with this. She was stunned and we quickly clarified with her before any bad thing happens next, it is sin. However, this shows that most people 'TRUST' email, and they believe it.

Do you believe your email?

A Little Information About Setting up Streamyx

Depending on the model of your router, here's some tips that can help you to setup your Streamyx connection:-
  • Use 'your_user_id@streamyx' as username
  • Set 'PPPoE' as connection type
  • Set VPI =0 and VCI=35
  • Default DNS servers : 202.188.1.5 and 202.188.0.133
  • New added DNS servers : 202.188.1.4 and 202.188.0.132

Monday, December 15, 2008

Enabling TraceMonkey in Firefox 3.1

TraceMonkey is the new Javascript Engine in Firefox 3.1 which is claimed to be 20-40 times faster than the order one. I have not tried out Firefox 3.1 myself yet and will wait for the official release.

Here's the steps to make sure TraceMonkey is enabled for both web content and XUL/chrome in Firefox 3.1:-

-Open a new tab and type "about:config"
-Enter "jit" in filter field
-Make sure both "javascript.options.jit.content" (for Web Content) and "javascript.options.jit.chrome" (for XUL/chrome) have the "true" value.

Thursday, December 11, 2008

Strange Oracle Error : ORA-12505

I have been using Oracle 10g R2 for development for quite a while. However, when I was starting my application server from Eclipse today (not the first start, it should be near the 10th time after my machine boot in the morning), an exception is thrown saying:-

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl

This seems to be an TNS error, but I am very sure my last startup works and I never touched anything in Oracle since my last application server startup. I tried with tnsping orcl, it works and I have got no idea what's the cause. I tried restarting the TNS listener, oracle server itself as well as my Eclipse, nothing works

Finally, I decided to reboot my machine. And you know what, it works after reboot. Strange?

Wednesday, December 10, 2008

Updating Flex Builder to 3.2

Last week after reading about Flex Builder updates in Artima.com, I decided to update my Flex Builder 3. So I fired up my Flex Builder 3 and go to:-

Help->Search for Flex Builder Updates...

However, nothing happens. After googling for a while, I found out that the Adobe Updater is not installed, you need to execute Setup.exe in the following directory:-

{YOUR_FLEX_BUILDER_INSTALL_DIRECTORY}/AMT\AdobeAUM5.1All.win
.installer/Setup.exe

Once it's setup, select again (try restart Flex Builder if it doesn't work):-

Help->Search for Flex Builder Updates...

The update process should be started.

Just wonder why it is not installed during installation of Flex Builder 3?

Apache Derby to Handle Case Insensitive Search

I have been using Apache Derby which can be bundled easily with the 'Lite' version of the product that I am developing in Flex/Java. The fact that by default Derby gives different result set for "where name='chua'" and "where name='CHUA'" has been an egg on my face. Using UPPER/LOWER with function index doesn't sounds good solution to me, neither to my boss. Derby folks are actually aware of the importance to support this, and several proposals have been made in the mailing list, but none have been implemented yet.

However, I am lucky enough to find a solution that I like with Collator here:-

http://blogs.sun.com/kah/entry/user_defined_collation_in_apache

The approach is to create a custom collator provider which returns collator with strength of SECONDARY, which gives case-insensitive comparison for EQUAL and LIKE.

Copied from the blog above:-

"
  • Create a class that extends java.text.spi.CollatorProvider and returns a collator that orders strings the way you want it to
  • Create a text file named META-INF/services/java.text.spi.CollatorProvider which contains one line with the name of your collator provider class
  • Put the compiled class file and the text file in a jar file which you drop into your JRE's lib/ext directory or in one of the directories specified by the java.ext.dirs property
"

And the sample custom collator provider:-

"
public class MyCollatorProvider extends CollatorProvider {
public Locale[] getAvailableLocales() {
return new Locale[] {
new Locale("en", "US", "caseinsensitive")
};
}
public Collator getInstance(Locale locale) {
Collator c = Collator.getInstance(Locale.US);
// Ignore tertiary differences (case differences)
c.setStrength(Collator.SECONDARY);
return c;
}
}
"
Make sure the custom collator provider jar is in java.ext.dirs for JRE that starts Derby. Create the database using connection string similar to following:-
'jdbc:derby:NoCaseDB;territory=en_US_caseinsensitive;
collation=TERRITORY_BASED;create=true'

Using territory based collation disables query optimization when doing LIKE query, I don't know the reason behind it. In the application that I am building, the user is allowed to use every single column to search and filter data. But, not every single column is indexed. ;-)

My Very First Blog

This is my very first blog. I have been hearing from friends about how cool it is to blog, and the very valid point for me to start blogging is knowledge capture. After being a software developer for a while, I had experienced solving the same problem more than once as I had forgotten the previous solution. Hopefully, blogging can help me in that aspect. ;-)

Short introduction of myself:-
I am a software developer based in Malaysia. I graduated from University of Technologies Malaysia (UTM) and have been building Java-based products and solutions since my career started. Two years ago, I started to code Adobe Flex for RIA User Interface backed by Java backends to lead development of next generation HR solution for my current company. Besides Flex and Java as my mainstream, I also spend my spare time (aside reservation for my lovely girlfriend) coding Scala, Ruby on Rails, C#.NET and PHP.