Caching using weak references

Some time ago I wrote a Java class that caches generated images so I don’t need to re-render them all the time (rendering SVG graphics takes some time…). There’s only one problem: As more and more different images are getting cached, the maximum heap space of the JVM will eventually get exhausted. Increasing this limit is not an option. This can be “fixed” by using a queue for the images: If it is full, the first image cached will get discarded so the memory usage will be limited. This can be improved by implementing a least recently used (LRU) caching strategy, which is exactly what I did.

This has the drawback that even if there is plenty of memory remaining, cached images are deleted if the queue is full and a new image is about to be added. Today, I learned about the java.lang.ref package and especially about it’s SoftReference class. Objects referenced by SoftReferences will be deleted by the garbage collector if the JVM runs out of memory, which should be the ideal way to implement a cache…

You can learn more about it at Wikipedia and IBM Developer Works.

Show me the bill!

I share a flat with two other students. When someone bought something we all (or two of us) will benefit of like food or household articles, we don’t split up the price immediately. Instead, we put it on a (paper-based) list. When this list is full, someone (me…) needs to do the math and figure out who needs to pay how much money to whom. This is where computer science comes in handy ;-) So I finally wrote a small program which takes such a list and prints something like “A needs to pay B 23.42 Euro”. Continue reading

Writing iCal data to phone calendar using gammu

Normally, I use a paper-based calendar to write down dates of appointments. Since such a calendar isn’t able to notify me about upcoming events, I wanted to use the reminder feature which is built into the calendar of my mobile phone (Nokia 6030).

Because I really hate typing on the phone keyboard, the calendar data needs to be sent to the phone using my computer. I already configured gammu some time ago to connect to my phone. For calendar editing, I use Mozilla Lightning. So the only thing that was left was some shell script to automate the transfer process between computer and phone. Continue reading

GNOME "Places" menu: Adding and deleting bookmarks

If you look in the “Places” menu of the GNOME panel or the “Places” view in open/close dialogs or in the file manager, you will see a list of folders. It often includes some local folders and – in addition – the remote locations you connected to via the “Connect to server” functionality.

These entries are saved in your home directory in the file .gtk-bookmarks. It is built using a simple scheme: Each line consists of a target URL and a label to display, separated by a blank. You can simply reduce or extend your list of bookmarks by editing this file.

An example, showing various protocols:

sftp://username@host.na.me/path/to/folder My folder on host.na.me (via SSH)
ftp://user@another.host/mypath Another bookmark, using FTP
file:///home/user2/music My local music folder

This will be displayed as

My folder on host.na.me (via SSH)
Another bookmark, using FTP
My local music folder

One computer – two workstations

If you run Linux, need multiple workstations but only have one computer with at least one graphics adapter, you could build a multi headed workstation. Don’t expect high speed graphics, because almost certainly there will be no graphics acceleration in your final “Hydra” system as it is called by some people.

What you need:

  • a graphics adapter with two outputs, able to work in the mode called “extended screen” (I used an Intel onboard video card, G33)
  • two monitors, two mouses and two keyboards, of course
  • recent versions of Xorg and Xephyr (I tried Ubuntu 8.04, including Xorg 7.3)

I used the great tutorial from Josean. In this article, I will present the additional fine tuning I needed to get a system that fulfills my expectations. Continue reading

tiwocBlog in English

I think most of the content is also relevant for the English speaking crowd out there so I recently decided to switch the language of this blog to English. There will be – however – some exceptions to that rule: Some postings just don’t make sense for you if you aren’t capable of the German language (links to German websites etc.).