Good Introduction to Threads and Shared Data Structures

20. June, 2014

Soon, we’ll have computers with 1024 cores but that won’t help unless software developers write code that make use of them.

To do that, you need a fundamental understanding on how threads work and what parallel algorithms are and what the real-world problems might be.

Dmitry Vyukov has created a web site “1024cores” which gives you both an introduction to the basics (what are we talking about? which tools to we have? what is a memory model and why should I care?) as well as some practical algorithms like concurrent skip lists with detailed descriptions of the problems that you will encounter and how to fix them.

If you want to know what the discussion is all about or if you want to polish your knowledge or if you need a specific solution, this is a good place to start :-)

YouDebug, the Non-interactive Debugger

7. May, 2014

“Non-interactive” and “debugger” seem to be contradictory but bear with me. YouDebug is a tool which allows you to debug a running Java application with a script.

How could this be useful? From the website:

[...]your program fails at a customer’s site with an exception, but you can’t (or don’t want to) reproduce the problem on your computer[...]

Sounds like a familiar problem: Customer has a problem but they can’t give you access for security, legal or technical reasons. You can’t go there (too far away) of even if you could, security won’t let you touch anything.

In a nutshell, YouDebug is a debugger that is controlled by a Groovy script:

breakpoint("com.acme.SubStringTest",7) {
  println "s="+s;

This sets a breakpoint in line 7 of “SubStringTest” and then prints the value of the local variable “s”.

Granted, it’s more time-consuming then doing it yourself (and you may need several attempts to get at the bottom of things) but you don’t have to install an IDE at your customer site, you don’t have to bring the source code along and technically, the customer is already running code that you wrote so from a legal and security point of view, this isn’t much different.

Good Summary of Heartbleed

17. April, 2014

This article contains a good summary of the Heartbleed bug and it’s consequences.

Want to know whether you’re affected? Check sites you use here:

Note: You will want to check the issue date of the certificate as well. If it was issued before the April 8th, 2014, you may still be vulnerable since an attacker might have stolen the private keys.

KDE Moves Window Edge Beyond Screen Border

27. March, 2014

With KDE 4.11, a new annoying feature was added: The window manager now moves a window beyond the screen edge. The original idea was to make the scroll bar easily accessible.

But a lot of people didn’t like this for various reasons.

My reason is that I use clicking on the window border to move a window to the front. By careful arrangement of the windows on my second monitor, I can easily switch between 5 windows by moving them against the screen edge: That way, I can use the mile high menu bar trick to position the mouse and one click to bring the window to the front (and no, I can’t use the usual click to front behavior; I know much better than the computer when I want to change the stacking order and when not).

With the window border hidden beyond the screen edge, this wasn’t possible anymore.

Here is a script that solved the issue for me: Snap to Deco 1.1

Installation Instructions:

Once downloaded, the script needs to be installed via

> plasmapkg -t kwinscript -i filename.kwinscript

which unpacks and copies files to ~/.kde4/share/apps/kwin/scripts/ but doesn’t activate them. In order to activate, use the scripts KCM (KConfig Module) graphical interface:

> kcmshell4 kwinscripts

and tick the required script.

Deleting Files From Snapper

16. February, 2014

Snapper is a nice tool to revert changes made to your system.

Unfortunately, it has a nasty side effect: If you happen to delete some large files (say, an ISO image you accidentally copied to the wrong place), and that large file ended up in one of your snapshots, well … the file will be gone but the disk space will still be allocated.

The first step is to locate the large file(s) under /.snapshots

The next step is to delete it/them. That’s not so easy since snapper created read-only file system snapshots. The workaround is to create a writable snapshot, delete the files, delete the read-only snapshot, create a new one and then delete the writable snapshot. Too much on one sentence? Here is the sequence of commands:

cd .../
btrfs subvolume snapshot snapshot snapshot.bak
rm -rf snapshot.bak/...
btrfs subvolume delete snapshot
btrfs subvolume snapshot -r snapshot.bak snapshot
btrfs subvolume delete snapshot.bak

Breakdown: First, we cd into the folder which contains the snapshot itself (it also contains a file “info.xml”).

Then we clone the snapshot in “snapshot.bak” which we can modify.

The last three steps replace “snapshot” with the new, cleaned “snapshot.bak”.

In at least one occasion, that didn’t free the disk space, yet. I also had to delete the oldest snapshot which contained the file.

Successful Git Workflow

29. January, 2014

When working with Git, you’ll eventually realize that an important part is the workflow: How many branches do I need? How do I organize them? How does code flow between them?

Vincent Driessen is sharing his workflow in “A successful Git branching model

Another great resource is “Atlassian Git Tutorials” and especially the “Git Workflows” section.

Oracle’s Java FAQ Displays in Chinese

17. January, 2014

I just looked at an article in the Oracle Java FAQ and I was a bit surprised to get this result:



  • Java 版本: 7.0

從 Java 7 Update 51 版本開始導入了例外網站清單功能。藉由將應用程式 URL 新增至「例外」清單,可讓使用者執行通常會被安全檢查封鎖的「豐富網際網路應用程式 (Rich Internet Applications, RIA)」。[...]

The solution was pretty simple: Append ?locale=en to the end of the URL:

That fixed it for me … sometimes.

Upgrading from Xtext 2.3 to 2.4

16. January, 2014

This is a summary of the steps to upgrade from Xtext 2.3 to 2.4:

  • The plugin org.eclipse.xtext.xtend2.lib has been renamed to org.eclipse.xtend2.lib
  • In the *.mwe2 file of your DSL, replace EcoreGeneratorFragment with EMFGeneratorFragment
  • Run the *.mwe2 script to regenerate the whole project
  • Merge plugin.xml_gen and plugin.xml

import this

10. January, 2014

During the Flask presentation yesterday, I learned about an Easter egg in Python: “import this” which will print:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!

Writing Games with Processing: Intro Screen

24. December, 2013

Merry Christmas, everyone :-)

In the last post, we cleaned up the code. This makes it now very simple to add an intro to the game:

class IntroState extends State {
  Player p;
  Enemy e;
  Step playerStep;
  Step enemyStep;
  void setup() {
    playerStep = new Step();
    playerStep.x += + 3*tileSize;
    p = new Player();
    e = new Enemy("Kenny");

    enemyStep = new Step();

The class Step adds a very simple movement algorithm to the player and enemy we created in setup():

class Step {
  int minX = tileSize * 3;
  int minY = tileSize * 3;
  int maxX = width - (tileSize * 3);
  int maxY = height - (tileSize * 3);

  int x = minX;
  int y = minY;
  int dx = tileSize;
  int dy = 0;
  void next() {
    int newX = x + dx;
    int newY = y + dy;
    if(newX > maxX) {
      newX = maxX;
      dx = 0;
      dy = tileSize;
      newY += dy;
    } else if(newY > maxY) {
      newY = maxY;
      dx = -tileSize;
      dy = 0;
      newX += dx; 
    } else if(newX < minX) {
      newX = minX;
      dx = 0;
      dy = -tileSize;
      newY += dy;
    } else if(newY < minY) {
      newY = minY;
      dx = tileSize;
      dy = 0;
      newX += dx; 
    x = newX;
    y = newY;

The code simply moves a coordinate along the outline of a rectangle. Using this code, we can move the player and enemy and then render the screen:

  void draw() {
  void movePlayer() {;
    p.x = playerStep.x;
    p.y = playerStep.y;
  void moveEnemy() {;   
    e.x = enemyStep.x;
    e.y = enemyStep.y;

drawBackground() is similar to the code in the main game code. Only this time, we display the game title and a short explanation what the game is about.

We could also use this to display a high score list, etc.

  void drawBackground() {
    fill(174, 204, 27);
    rect(0, 0, width, height);
    textAlign(CENTER, TOP);
    color outline = color(255,255,255);
    color fill = color(0,0,0);
    int y = height/2 - 60;
    textWithOutline("Run, Platty, Run!", width/2, y, outline, fill);
    y += 50;
    textWithOutline("Use cursor keys to evade the hungry crocodiles", width/2, y, outline, fill);
    y += 40;
    outline = color(0,0,255);
    fill = color(255,255,255);
    textWithOutline("Press any key to start", width/2, y, outline, fill);
    y += 20;

The last element we need is a key handler which starts the game itself:

  void keyPressed() {
    changeState(new MainGame());

Easy, isn’t it? Just imagine how complex this might have been without the refactoring. We might have ended up with a draw() method with several if(), checking for the current state of the game, trying to avoid messing with the wrong variables, …

By splitting the game into steps, each step can do it’s own thing. This is the major goal of refactoring: Cutting down dependencies.

The whole project can be cloned from here. The version of this blog post is tagged with v9.

Cool, our game is almost complete. One last thing is missing: Displaying the high score table.

Previous: Cleaning Up
First post: Getting Started


Get every new post delivered to your Inbox.

Join 333 other followers