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:
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. However, then the PPA upgraded to GIMP 2.8.6, which contains a horrible UI bug (seems like neither the GIMP team, nor the PPA maintainer has any particularly strong QA process).
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 .m4a extension. Android can both play and read metadata tags from such files.
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.
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-pbkdf2from a terminal and enter the desired password, copy the output. - Edit
/etc/grub.d/40_customand add this to the end:
set superusers="root"
password_pbkdf2 root output from grub-mkpasswd-pbkdf2 goes here
password bogus bogus
- Make
/etc/grub.d/40_customnon-readable for users:
chmod o-r /etc/grub.d/40_custom - Edit
/etc/grub.d/10_linuxaccording to this diff:
90c90,94
< printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
---
> if ${recovery} || ${in_submenu}; then
> printf "menuentry '${title}' ${CLASS} --users '' {\n" "${os}" "${version}"
> else
> printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
> fi
258c262
< echo "submenu \"Previous Linux versions\" {"
---
> echo "submenu \"Previous Linux versions\" --users '' {"
- Edit
/etc/grub.d/20_memtest86+according to this diff:
27c27
< menuentry "Memory test (memtest86+)" {
---
> menuentry "Memory test (memtest86+)" --users "" {
33c33
< menuentry "Memory test (memtest86+, serial console 115200)" {
---
> menuentry "Memory test (memtest86+, serial console 115200)" --users "" {
46c46
< #menuentry "Memory test (memtest86+, experimental multiboot)" {
---
> #menuentry "Memory test (memtest86+, experimental multiboot)" --users "" {
52c52
< #menuentry "Memory test (memtest86+, serial console 115200, experimental multiboot)" {
---
> #menuentry "Memory test (memtest86+, serial console 115200, experimental multiboot)" --users "" {
- Run
update-grub
(I am not sure if it is possible to abuse memtest86+, but better safe than sorry.)
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.
How to roll your own bootable Linux CD-ROM
When booting a regular Linux system, it just mounts some partition with a nice file system (such as ext4) on your HDD on / read/write and there you go.
When booting from a CD-ROM, it’s not that simple. The CD-ROM file system, ISO 9660, does not support the file names and attributes that a Linux system normally needs. And the CD-ROM is read only.
There are ways to work around these issues. You can use the Rock Ridge extension to ISO 9660 to get the file names and attributes needed. And the read only issue can be handled either as I have described in an earlier post, or by using unionfs.
How to roll your own Debian based Linux distro
Goal
To build a minimal Debian based Linux system with a fully functional bash shell, TCP/IP networking with DHCP client and apt setup to be able to install any package from the Debian repositories. The resulting system will use about 157 MB disk space and consume less than 10 MB RAM.
This is now implemented in Bachata Linux.
Prerequisites
A Debian based Linux system to work from (e.g. Ubuntu desktop) with the debootstrap and extlinux packages installed. Some virtualization environment is highly recommended for testing, such as KVM/QEMU.
How to move MySQL data directory in Ubuntu Server
By default, the MySQL data is placed in /var/lib/mysql, which is a reasonable default. However, sometimes you want to place it somewhere else, such as on an other file system. Using a symlink doesn’t seem to work, so you have follow this procedure.
To move the MySQL data directory from /var/lib to /mnt/mydata, run these commands as root:
apt-get install mysql-serverservice mysql stopmv /var/lib/mysql /mnt/mydata/- replace
/var/lib/mysqlwith/mnt/mydata/mysqlin/etc/passwd– mysql/etc/mysql/my.cnf– [mysqld] datadir/etc/apparmor.d/usr.sbin.mysqld(twice)
service mysql start
Using ZTE Blade Android phone with Ubuntu 11.10
Using a ZTE Blade Android phone connected with USB is a bit tricky with Ubuntu 11.10.
First you need to apply the patch in this bug, after doing that you should get USB storage to work.
After doing that, it is also possible to get development and debugging to work over USB. Create a group androiddev (addgroup --system androiddev), and add yourself to it (gpasswd -a yourUsername androiddev). Then create a file /etc/udev/rules.d/11-android.rules with this content (4 lines, watch the line breaks):