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:


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.

22 June 2011

How to bypass Cisco VPN client LAN restriction

There are a lot of VPN client softwares. Windows has a built in client and there are a bunch of third party products. For example Cisco VPN client.

The Cisco VPN client has an annoying feature: the VPN provider can decide if local network access is allowed or not. From a VPN provider perspective this is of course a good feature since it increases security. But from my perspective it is bad.
So in other words it may not matter if the Allow Local LAN Access box is checked or not.

One good workaround: use another VPN client that is compatible with Cisco. I have tried and successfully used Shrew Soft VPN Client. It can import a Cisco VPN profile file (pcf-file). It can also be configured to override the VPN provider settings:
Just go to the Policy tab in ShrewSoft VPN client and add an exclude filter. I wanted to access my entire 10.10.XXX.XXX network so I added an exclude filter for with netmask Be careful so your local area network IP range don't collide with services you would like to use on the VPN.

I got the tip from this post: http://serverfault.com/questions/126458/unable-to-access-local-network-when-cisco-vpn-client-is-connected

11 June 2011

SQuirreL - a competent but low user experience SQL GUI

I have on and off used SQuirreL. It is cross-plattform cross-database SQL GUI. Well, the cross-database is limited to JDBC drivers, but it covers most databases (including H2 and Mysql). The software is written in java so it will probably execute on any plattform, although I have only used it on Windows.

The most common operation I want with a tool like this is the ability to look and edit table data. SQuirreL can do this, and this for free.

But the problem with this software is that it is hard to use. I will give three examples why it is hard to use, but there are more things so be prepared to invest a little bit of time to use it.
  1. Installer privileges
    The installer program is made with IzPack. It is easy to run the jar file just by double click on it. However a Windows user quickly realises that the installer does not run with elevated privileges so the program cannot be installed in c:\Program Files\. I have seen other IzPack installers that detects this and tried to elevate the privileges via Windows UAC feature. Why doesn't this installer doesn't do this? I had to manually start cmd with elevated privileges and run java -jar squirrel-sql-3.2.1-install.
  2. Manual installing of drivers
    JDBC driver are standardized so it is easy to implement a software to use them. But I had to manually installs my database drivers and put them in C:\Program Files (x86)\squirrel-sql-3.2.1\lib folder. Why why why? If distribution of drivers is a license issue, please add an automatic download feature in the installer that does this.
  3. How to add a new row in a table?
    I spent some time to find out how to add a row to a table. I tried to right click on a gray (blank) area in the table listing. But no luck. The solution: right click in the contents (table contents) are and a pop up menu is shown a it is possible to select "Insert Row". When you do this a hard to use row editor visualizes.


08 June 2011

TortoiseGit difference between Fetch and Remote Update

In the TortoiseGit application, in the "Git Sync..." dialog there is a drop down box with different options. I tried to figure out the difference between Fetch and Remote Update:
 I found this good answer on StackOverflow: http://stackoverflow.com/questions/2688251/what-is-the-difference-between-git-fetch-origin-and-git-remote-update-origin.

04 June 2011

Slow scala installer

I'm trying to install Scala using the IzPack Scala installer (a jar file). It is extremely slow. I found this post about the problem: http://www.scala-lang.org/node/9670.

Just as the post above suggests I can with Windows Sysinternals Process Monitor (Procmon.exe) see that the installer file is read many (many) times:

03 June 2011

Does Apress squeeze out books without editing?

I'm no journalist. I'm not even good at writing, but then again I'm not paid money to write. But even though I don't have high demands on my own texts I have high demands on books I buy. I recently bought two books from the publisher Apress. The quality of writing in these books have been less than mediocre. This has started me to wonder if Apress editors even reads the books before printing. Perhaps they are more concerned to squeeze out books than making sure the quality of the texts are good.

Git usability and "staging"

The company I work for has decided to switch from CVS/SVN to Git, so I'm learning Git. I have previously worked with Mercurial, so you might think that it should be easy?!

One big difference between Git and other VCS is that Git has the concept of "staging" area. Before a file can be committed it must be staged. The advantage this gives (claimed by advocates of the staging concept) is that is gives you more control over what you commit.

I'm not that convinced... I think that the motivation for this concept is weak, and it introduces a complexity to Git that is totally unnecessary. My biggest motivation for this is: you should use a GUI! If you are a command line junkie you can stop reading now a go back to your black terminal window.

It is no convincidence that the GUI of both (Eclipse) Egit and Tortoisegit completely hides the staging concept. Why? Because there is no need for it when you can select what files to commit individually.

So maybe I was a little bit harsh about "command line junkies". I myself uses a command line when it is warranted. But I firmly believes that you should use a GUI when it is better. In this case it gives an overview and you are less likely to perform errors.

01 June 2011

A (fragile) way of asserting that no Exception is logged

The best logging framework for java is probably Simple Logging Facade for Java or (SLF4J). When using this when developing a library you can be sure that your library logging will be handled whatever logging framework is used by the application.

The slf4j-simple implementation is good when executing tests. It "simply" logs to System.err. It made an effort to assert if there are any exception logged when running a Junit test case:

package se.lesc.blog;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JunitSlf4jLoggerTest {

    public void testCodeShouldNotYeildExceptionInLog() throws Exception {
        //Store away System.err (that slf4j-simple uses to log to).
        //Note: This is a bit fragile!
        PrintStream oldSystemError = System.err;

        //Re-route System.error to a buffer
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(byteStream);

        //Invoke production code
        new MyProductionCode();
        //Make sure no exception has been logged 
        String logging = new String(byteStream.toByteArray(), "utf-8");
        assertTrue("No Exception should be found in log",
            ! logging.contains("Exception"));
        //Reset re-routing of System.err
    private static class MyProductionCode {
        private final Logger logger =
        MyProductionCode() {
            logger.error("Something went wrong", new Exception());