Archive | programming RSS feed for this section

NoClassDefFoundError for GooglePlayServicesUtil

9 Sep

This might save some people from losing a few hours over a seemingly simple issue. When you update the Google Play Services SDK, and possibly the Android API, it might happen that your application suddenly crashes when calling isGooglePlayServicesAvailable with a NoClassDefFoundError.

Continue reading

Optimization tip: faster 2D transforms

18 May

Drop the last column

A 2D transform is typically shown as a 3×3 augmented matrix. However the last column (or row depending which order you use) of an augmented matrix is always 0 0 1, so we don’t need to store it. We only store a 2×3 matrix.

\begin{bmatrix} a & b \\ c & d \\ e & f \end{bmatrix}

The 2 upper rows will contain the rotation, scale and shear factors, while the lower row contains the translation.
Continue reading

Using the NDK and JNI to build android applications

25 Aug

When writing applications for android in java, there are often parts that you expected to perform better. It’s not always the algorithm that is to blame. Java has its limits. Even with a JIT compiler it will have more runtime overhead, and a garbage collector will run at times you don’t want it to. We can solve this by moving demanding pieces of our code to C, C++ or assembler.  Continue reading

Memory management in C++ Part 2

29 Jun

While part 1 focussed on avoiding memory leaks, this post will look at memory strategies which optimize speed. While in many cases a normal allocation/reallocation/deallocation scheme works well, there are several instances where this can slow down software considerably. In these cases one of the following strategies can help to improve the performance of your application.

Continue reading

Avoiding SQL injections using stored procedures and access privileges

8 Feb

In the previous article I showed that the only way to be sure no one messes with your query is to use prepared statements because the statement is precompiled and not alterable afterwards. For people who don’t like to use prepared statements due to the added complexity, or people who worry about the overhead of prepared statements for one time queries there is another solution: stored procedures.

Continue reading


8 Feb

A useful construct in MySQL when you want to create a new row in case it doesn’t exist yet or update an existing one is:


For example if you have a PRIMARY KEY ‘id’, a UNIQUE KEY ‘u_key’ and a value with no constraints ‘data’ and you want to insert or update ‘data’ referenced by ‘id’, you can write:

INSERT INTO my_table (id, data) VALUES (662606957, 'some data') ON DUPLICATE KEY UPDATE data='some data';

However, this only works as long as you don’t define the UNIQUE KEY as NOT NULL. If you do define it as NOT NULL, it won’t work because it can’t use the default value more than once. In that case you need to supply a unique value for the UNIQUE KEY as well:

INSERT INTO my_table (id, u_key, data) VALUES (662606957, '0x600613', 'some data') ON DUPLICATE KEY UPDATE u_key='0x600613', data='some data';

Memory management in C++ Part 1

23 Jan

While scripting and other high level languages often have one way to manage memory, working with a lower level language gives you the ability to choose how to manage each allocated piece of memory. This can be both a blessing and a curse, as one way is not always the best solution for each case, so choosing the best strategy can become hard. This article tries to give an overview of several techniques.

Continue reading