09 February 2012

Mysql 5.1/5.5 and Unicode

I noticed that Mysql 5.1. and 5.5 has a difference with respect to the support for Unicode characters. Mysql 5.1 only supports the Basic Multilingual Plane (BMP), that is code points between 0 and 65535 (U+0000 to U+FFFF). Characters whose code points are greater than 65535 (U+FFFF) are called supplementary characters and support for these are included in Mysql 5.5. Read more at http://dev.mysql.com/doc/refman/5.5/en/charset-unicode.html.

Java String support both Basic Multilingual Plane and supplementary characters so this may cause some problems if a String is send directly into Mysql. Typically you will see this error message:
java.sql.SQLException: Incorrect string value: '\xC2\x9F' for column 'APN' at row 1


A little warning: even in Mysql 5.5 the "utf8" "charset" does NOT support supplementary characters. Use utf8mb4 instead.

07 February 2012

How to take a Java heap dump from command line

A heap dump is a great way to analyze a Java program in search of memory leaks. I mostly use Eclipse Memory analyzer for such an analysis. It is possible to acquire a heap dump from inside Eclipse Memory analyzer. But it may not always be possible to run a GUI in a foreign environment.

Use jps to find out the process id
C:\>jps
11448 MyLeakingApplication
12084 Jps

Use jmap to acquire the dump
C:\>jmap -dump:format=b,file=c:\Temp\mymemorydump.hprof 11448
Dumping heap to C:\Temp\mymemorydump.hprof ...
Heap dump file created

14 January 2012

Implemented choosable renderer for java quick search popup

I have now implemented so it is possible to choose (or implement one's own) renderer. I made a nice yellow renderer default:

I have made a web start version available. Try it out at http://code.google.com/p/java-quick-search-popup/.

08 January 2012

Created an open source project

I have for a while wanted to create an open source project, but has not had any good ideas. But yesterday I finally did it. I created http://code.google.com/p/java-quick-search-popup/. It is a small Java Swing component project.

24 November 2011

How to change file premissions in Git on Windows

Git manages file permissions for each file in the repository. It may be appropriate to have the executable bit set for shell/bash files to make them easier to execute in Linux systems.

Windows own file permissions does not map to the Git file permissions so it may be a bit hard to change file permissions when you are on Windows. This is how you do it:

Lets assume the file script.sh needs to have the executable bit set. Use the command git ls-tree to inspect the file permissions:
C:\views\myproject>git ls-tree HEAD
100644 blob 55c0287d4ef21f15b97eb1f107451b88b479bffe    script.sh


As you can see the file has 644 permission (ignoring the 100). We would like to change it to 755:
C:\views\myproject>git update-index --chmod=+x script.sh

C:\views\myproject>git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   script.sh
#


The file is now staged. Note that the file contents is not changed, only the meta data. We must commit the file so save the change:
C:\views\myproject>git commit -m "Changing file permissions"
[master 77b171e] Changing file permissions
 0 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 script.sh


Running git ls-tree again to see the change:
C:\views\myproject>git ls-tree HEAD
100755 blob 55c0287d4ef21f15b97eb1f107451b88b479bffe    script.sh

05 July 2011

Steam gives away Team Fortress 2

The popular multi player first person shooter game Team Fortress 2 is now free to play on Steam. I took the "bait" and installed Steam just to play this free game (and the game is really fun). So how can Steam money on this? Well there are two things that they can make money from:

1. In-game purchases
Many free 2 play games have an in-game store. In Team Fortress 2 there is a store where you can buy visual appearances (like hats) and also weapons. I was "suckered" in to buy some kind of instrument (called Wrangler) the engineer class in the game can use. For that I spent 0,39€:


2. Buy other games in Steam
The other thing that they can make money on is other games, that cost money. Since the user already has installed Steam the effort to buy something is lower. And since I could only transfer a minimum of 5 € to my virtual "Steam Wallet" I had some over. So I bought a game call Trine for 1,99€. Once I have bought one game (although cheep) there is a high probably that I will buy more games in the future.

24 June 2011

Switch to UTF-8 charset in Mysql on Ubuntu

When installing Mysql on Ubuntu the default character set is probably latin-1. Since Ubuntu uses UTF-8 for most other things this may be little strange. But it is easy to change.

The Mysql configuration file /etc/mysql/my.cnf has a magic line:
!includedir /etc/mysql/conf.d/

This will make it include settings on the subdirectory conf.d. It's not recommended to change the my.cnf file directly since it will cause problems when upgrading Ubuntu/Mysql to a new version.

Create a new file: /etc/mysql/conf.d/utf8_charset.cnf with the following contents:
[mysqld]
default-character-set=utf8

[client]
default-character-set=utf8

Restart mysql and you will have UTF-8 as character set:
$ mysql -u root -p -e "show variables like '%character%'"
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+ 

Update 2012-11-12: This is valid for Mysql 5.1. For Mysql 5.5 see comment below by Martijn.