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.

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 10.10.0.0 with netmask 255.255.0.0. 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 {

    @Test
    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);
        System.setErr(printStream);

        //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
        System.setErr(oldSystemError);
    }
    
    private static class MyProductionCode {
        private final Logger logger =
            LoggerFactory.getLogger(MyProductionCode.class);
        MyProductionCode() {
            logger.error("Something went wrong", new Exception());
        }
    }
}

28 May 2011

Ninite - a great way to install programs

I recently re-installed my computer (due to a disc crash). This time I tried the Ninite (http://ninite.com/) way to install software. It is a web page where you can check what programs to install. The web page has the most popular free software. When you have selected what programs to install you download the Ninite installer and run it. The installer will download and install each software automatically. I tried it and it worked great!