Archive for February, 2010

Apple UK keyboard layout for Windows

Because I am now working on a .Net project and I don’t want to work on a PC πŸ˜‰ , I decided to install Windows as guest on my Mac in VirtualBox.

Everything works perfectly fine except that Windows doesn’t like my Apple keyboard. What a surprise! πŸ™„

After a quick search on Google, I found a fix for:

But I didn’t find anything for the ‘normal’ Apple UK keyboard. Unfortunately, I can’t use the MacBook Pro UK keyboard layout because it is slightly different than the USB and Wireless Apple UK keyboards layout. πŸ™

So my friend Google πŸ˜› didn’t leave me any other choice than create my own keymap for this keyboard using the Microsoft Keyboard Layout Creator.

You can download it clicking on the following link: Keyboard Layout Setup Files (English UK – Apple). And here is the source KLC file if you want to make change to it: Source KLC File for English UK – Apple Keyboard Layout.

To use, simply unzip, run setup, and then in your keyboard settings (Control Panel -> Regional and Language Options) change to β€œUnited Kingdom – Custom”. You may wish to remove the default UK keyboard to avoid confusion. If it still doesn’t work, don’t hesitate to reboot Windows! πŸ˜‰

This is working well on my VirtualBox but it should also work on any Windows instance (i.e. VMWare, Parallels, etc).

, , ,

30 Comments

Why GROUP_CONCAT returns BLOB?

Last week, when using the GROUP_CONCAT() function on a MySQL database, I got an unexpected result. πŸ™

Indeed, instead of getting my result as VARCHAR types, I got it as BLOB types! For information, aΒ BLOB is a binary large object that can hold a variable amount of data:
http://dev.mysql.com/doc/refman/5.0/en/blob.html
Because BLOB values are treated as binary strings, it is not easy to use. This is why we would prefer to have VARCHAR values.

So the question is how to get around this frustrating problem?

The answer is, for once, very simple! πŸ˜€
You simply need to:

  • Open your my.ini or my.cnf file;
  • Change the value of the group_concat_max_len system variable to 512 (no ‘k’ suffix);
  • Restart the mysql service

To verify if the value has been successfully updated, execute the following command in your mysql client:

mysql> show variables like "%concat%";
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| group_concat_max_len | 512   |
+----------------------+-------+
1 row in set (0.00 sec)

Note that you cannot set the value of group_concat_max_len to less than 1Kb using the MySQL Administrator GUI. Which means that the only way to set this system variable to 512 (which is less than 1Kb) is to edit your MySQL configuration file as described above.

, , , ,

5 Comments

Locale settings for your cron job

Do you get special characters problem when executing your bash script from a cron job?
And does the same script work fine when it is directly executed from the command line?
If yes, continue reading this article! πŸ˜‰

The reason of this characters problem is probably because of your locale settings.
Indeed, If you try to run the command locale from the command line and from a cron job, you may get different results such as:

From the command line From a cron job
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

As you can see, the cron job is not using UTF-8. That must be the problem! πŸ™‚

So the question now is how to change the locale settings for the cron job?
Some people say that you need to add the following environment variables to the crontab entry:

SHELL=/bin/bash
LANG=en_US.UTF-8
LANGUAGE=en
LC_CTYPE=en_US.UTF-8

But this actually didn’t work for me. πŸ™

What you can do instead is create (if not already present) the file /etc/environment and add the following line:

LANG=en_US.UTF-8

The cron process will read this file when it starts, so you need to restart it in order to apply the change:

service cron restart

Hope this will fix your characters problem. πŸ˜‰

, , , , ,

18 Comments