2011-09-01

Apple Keyboard on linux

To be able to use an Apple keyboard (MB110D/A) on a linux system, the correct layout must be set first. Select the corresponding in the Keyboard Preferences. In this case Germany Macintosh is added to the layouts list.
Keyboard model should be Apple.


Unfortunately, the keys [^/°] and [] remain reversed. To fix this the key codes have the be reassigned:

1) Find out the keycode
With help of the programm xev the keycode can be figured out. Start the programm as follows and press the keys [^/°] and [] afterwards. The keycodes should be displayed.
$ xev | grep keycode
    state 0x10, keycode 94 (keysym 0xfe52, dead_circumflex), same_screen YES,
    state 0x10, keycode 94 (keysym 0xfe52, dead_circumflex), same_screen YES,
    state 0x10, keycode 49 (keysym 0x3c, less), same_screen YES,
    state 0x10, keycode 49 (keysym 0x3c, less), same_screen YES,
So we need to fix the assignment for the keycodes 94 and 49.

2) Show current key assignment
The current key assignment can be displayed using xmodmap.
$ xmodmap -pke | grep " 94"
keycode  94 = less greater less greater bar brokenbar bar
$ xmodmap -pke | grep " 49"
keycode  49 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032 
Here you can already see the problem. On the button [^ / °] with keycode 94 are the signs for smaller, bigger, ...

3) Change key assignment
With xmodmap the key assignement can be changed.
$ xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar'
$ xmodmap -e 'keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032'
However, this change only lasts until the next reboot. In order to implement this change permanent or restore after a reboot, the new assignments must be stored in the file ~/.Xmodmap.

$ xmodmap -pke | grep " 49" >> ~/.Xmodmap 
$ xmodmap -pke | grep " 94" >> ~/.Xmodmap 
The file should look like this now:
keycode  94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032
keycode  49 = less greater less greater bar brokenbar bar

2011-07-15

Patch files with git diff

In order to create a patch file that is usable with "patch -p0 < patchfile" with "git diff", the option "--no-prefix" has to be used:
git diff --no-prefix > patchfile

Now the patch can be applied using:
patch -p0 < patchfile

If you already have a patch file out of "git diff" where the "--no-prefix" option was not specified, the patch must be applied as follows:
patch -p1 < patchfile

This way the standard prefixes a/ and b/ are ignored.

2011-06-18

Auto-Update for Java Applications

Java WebStart-Applications have a great update mechanism using JNLP. It checks during launch if there is a new version available on the server and downloads the new version to the client automatically. This way the client always runs with the latests version available on the server. But what about standalone Java applications?

Appcast - an RSS 2.0 update feed

Similar to podcasts a appcast is a RSS 2.0 feed to announce a new release of a software product. It basically uses standard RSS 2.0. The reference to the new version file can be specified in the enclosure tag:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>MyApp Changelog</title>
      <link>http://example.com/MyApp/appcast.xml</link>
      <description>Latest changes and updates.</description>
      <language>en</language>
      <item>
         <title>Version 1.3.2</title>
         <pubDate>Wed, 18 Jun 2011 09:20:11 +0000</pubDate>
         <enclosure url="http://example.com/MyApp-1.3.2.zip" length="1234567" type="application/octet-stream" />
      </item>
   </channel>
</rss>

Just place this as appcast.xml on some host that is accessible by the application. The application can check if there is a new update available using this appcast.xml.

Appcast Framework for Mac OS X

Andy Matuschak's Sparkle is a free software update framework for Mac OS X that is very widespread. It has some appcast extensions for custom version strings and DSA signature for the update file. An complete sparkle appcast example can be found here. With these extensions is also possible to include a link to the release notes file.

Appcast updates for Java Applications?

The RSS 2.0 structure is very easy and there are already java parsers available. The sparkle extensions can also be parsed in Java. You can use JAXB to get the values out of the enclosure tag:
@XmlAccessorType(XmlAccessType.FIELD)
public class Enclosure {
    @XmlAttribute
    String url;
    @XmlAttribute
    long length;
    @XmlAttribute
    String type;
    @XmlAttribute(namespace="http://www.andymatuschak.org/xml-namespaces/sparkle")
    String version;
    @XmlAttribute(namespace="http://www.andymatuschak.org/xml-namespaces/sparkle")
    String shortVersionString;
    @XmlAttribute(namespace="http://www.andymatuschak.org/xml-namespaces/sparkle")
    String dsaSignature;
...
The other tags can be processed the same way. You only need to compare the current application version string with the one from the appcast enclosure. If the appcast version is newer, download the update file.

But how do you handle applications with multiple JAR files if every component has it's own versioning? The version string from the MANIFEST.MF file can be used or one can add a new version string, e.g. 'Appcast-Version: 1.2.3', to the JAR's MANIFEST.MF file. This can be read easily at runtime with java.util.jar.Manifest class:
Manifest manifest = new Manifest(new FileInputStream(new File("manifest.mf")));
Attributes mainAttributes = manifest.getMainAttributes();
if (mainAttributes != null) {
   return mainAttributes.getValue("Appcast-Version");
}

The appcast URL itself can also be placed inside the MANIFEST.MF file for each application module, e.g. using "Appcast-Url: http://example.com/MyApp/appcast.xml".

Keep in mind that it is not possible to replace a JAR file of a currently running application. So you need a bootstrap mechanism to check and download updates and apply them during next start of the application.




2011-02-12

Enable colors for git on Mac OS X

To enable colors for all git commands on Mac OS X use:

$ git config --global color.ui true

2011-01-08

top command on OS X

On Linux systems the top command shows the running processes sorted by the highest CPU consumption by default.
This is not the case on Mac OS X systems. There the processes are sorted by their PID in descending order (highest PID on top).
For those that are interested in the processes that consume much CPU use the following:
top -o cpu

This is for sorting the processes according their CPU usage.

For easier access you can create an alias.
Add the following line in you .profile file:
alias top='top -o cpu'