2 October 2014
Running Jetty as a service in Ubuntu Linux
Jetty is a popular open source Java application server. In order to run it as a service on a Linux server, they recommend using a horribly overcomplicated and quite fragile script.
In Ubuntu server, there is a better way. Leverage Upstart and its declarative job definitions.
First install Jetty into /opt/jetty and create a jetty user:
useradd --user-group --shell /bin/false --home-dir /opt/jetty/temp jetty Then create a file /etc/init/jetty.conf with content like this:
5 June 2014
Don’t use large BLOBs in MySQL from Java
The MySQL database can store large chunks of binary data (up to 1 GB) using the BLOB data types.
However, this does not work well if you access the MySQL database from Java (or any other JVM based language) using the MySQL JDBC driver.
The JDBC API supports an efficient stream based way to handle BLOBs, but the MySQL JDBC driver does not implement this properly. It works, but it will buffer all data in memory in a way which is very inefficient and can make your JVM run out of memory if the BLOBs are large.
4 March 2014
Don’t use PipedOutputStream on Android
I was using java.io.PipedOutputStream in an Android app. The app performed horribly bad. After doing some profiling, it turned out that the call to PipedOutputStream.write(byte[]) that was really slow. After digging into the Android source code, I discovered that PipedOutputStream.write(byte[]) was not implemented, it just delegated to the default implementation in OutputStream which iterate through the array and call PipedOutputStream.write(byte) for each byte.
Since PipedOutputStream.write(byte) does some synchronization and Object.notifyAll() each time, it is really slow to do this 1000 times when you write a block of 1 KB data.
17 December 2013
Running Adobe Lightroom 4.4 in Linux
I use Adobe Lightroom 4.4 for photo editing. There is one very annoying aspect of this program, it is not available for Linux (only for Windows and Max OS X).
In order to run Lightroom on my computer, I had to use VirtualBox and install Windows 7 in it. This works, but is quite clumsy and annoying. And since Lightroom is the only reason for me to run Windows, I would like to get rid of it.
13 October 2013
Using an embedded SQL database in Java web application
You have a Java web application needing a relational SQL database. According to JavaEE conventions, you declare the DataSource in web.xml:
<resource-ref> <res-ref-name>jdbc/DS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> and then fetch it in code with (DataSource)new InitialContext().lookup("java:comp/env/jdbc/DS").
Using Maven, Jetty and HSQLDB, you can very easily run the web application for local testing without having to setup neither a web container, nor a database. Add this to pom.xml:
<build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.
29 August 2013
GIMP 2.8 in Ubuntu 12.04
This is no longer relevant, since the PPA have updated to GIMP 2.8.10, which has fixed the bug.
If you use Ubuntu 12.04 LTS, you only have access to the old GIMP 2.6 in the standard repositories. This is unfortunate since GIMP 2.8 have a lot of new useful features.
The standard way to get GIMP 2.8 is to use the a PPA, as described here. This used to work fine.
1 January 2013
Using AAC music files in Android
If you have a file with .aac extension, it is AAC encoded audio in an ADTS container. If you want to play such file on an Android device, you have problems. Android 2.x does not support this file format at all, and not even the latest version of Android supports reading metadata tags from it.
The solution is to repackage the audio in an MPEG-4 container to a file with .
24 August 2012
How to design a RESTful protocol
What is REST? In most cases, it is sufficient say that REST is a way to design a network protocol based on HTTP. I perfer to call it a RESTful protocol, but it can also be called RESTful API or RESTful Web Service. It is important to keep in mind that it technically is a network protocol, and not an API like an interface with some methods in a regular programming language.
2 July 2012
How to add password protection to GRUB2
These instructions are tested with Ubuntu desktop 12.04, but will probably be useful in other Linux distros with GRUB2 as well.
The goal is to block everything except booting the default system. In paricular, it should not be possible for anyone to boot into recovery mode, since that will bypass normal login and give root access directly.
Run grub-mkpasswd-pbkdf2 from a terminal and enter the desired password, copy the output. Edit /etc/grub.
14 January 2012
Bachata Linux
Based on what I have desscribed in the two previous posts, I have now made a Linux distribution with an install CD.
It is called Bachata Linux, check it out here.