Friday, September 17, 2010

Skånetrafiken och Android

Jag läste en kurs om applikationsutveckling för Android i somras. Kursen avslutades med ett projekt. Mitt projekt var en Androidapplikation för att söka resor och tidtabeller för Skånetrafikens bussar och tåg.

Jag blev nöjd med resultatet så jag publicerade appen i Android Market. Mer om den finns på Sök på "lokaltrafik" i Market/Butiken för att hitta den.

Saturday, May 15, 2010

Wikitrends 2.0

Wikitrends 2.0 is now live. Rewrote and optimized most of it. Compared to the old version a single update now takes 1/10 of the time, with 10x more data. The site now has Wikipedia page views trends over three different time periods; montly, weekly and daily (last version only did daily.) I also moved the site to Wikimedia Toolserver. Thanks to Wikimedia Deutschland for hosting it on their two monster 8-core machines.

The monthly trends, which updates once per day, are based on 432 GB of uncompressed data. To make it even remotely possible to work with without a huge cluster of machines, I filter, aggregate and compress it down to a mere 10 GB.

Sunday, February 21, 2010

Chipmunk for Java

I started working on this project a couple of weeks ago. I was looking for a good (as in good performance) physics library that I could use in Java projects. The ones I found reportedly didn't work well on slower hardware.

The result is Java bindings (i.e. a JNI) to Chipmunk, the 2D physics engine. Below is a demo of it running a simulation on Android Dev Phone 1.

The bindings are far from complete, but I have decided to release the project anyway. Code can be downloaded or browsed from its project page at Github.

Saturday, October 24, 2009

Flicker-free rendering with double buffering in Java

If you draw graphics directly using the paint(Graphics) method in an AWT component such as Canvas, Frame or Panel your rendering will suffer greatly from flickering. The general solution to this is double buffering.

There are many ways to implement double buffering. One way is to not do it and instead use Swing components, such as JFrame and JPanel, that already does double buffering. Use paintComponent(Graphics) and override it the same way as you would with paint(Graphics).

class JPanelWithSmileyFace extends JPanel  {
 public Dimension getPreferredSize() {
  return new Dimension(200, 200);

 public void paintComponent(Graphics g) {
  g.fillOval(10, 10, 180, 180);
  g.fillOval(90-30, 50, 20, 30);
  g.fillOval(90+30, 50, 20, 30);
  g.drawArc(40, 40, 200-2*40, 200-2*40, -10, -160);
Example paintComponent.

public class SmileyFaceDemo {
 public static void main(String[] args) {
  JFrame window = new JFrame();
  window.getContentPane().add(new JPanelWithOval());
Example main.

Friday, August 14, 2009

Google Doodles

Themed Google logos always drive massive amounts of traffic. Today Google celebrates the birthday of Hans Christian Ørsted, a Danish physicist and chemist, which gives his wikipedia page a whopping 1 million percent uptrend in traffic volume over the last 24 hours.

Screenshot from (my project) Wikitrends.

Thursday, August 6, 2009

Middle clicking and scrolling

Some more Firefox tweaks in about:config.
  • Enable scroll on middle click: general.autoScroll = true
  • Disable load URL on middle click: middlemouse.contentLoadURL = false
  • Disable paste on middle click: middlemouse.paste = false

Monday, June 29, 2009

Store dict in AppEngine Datastore

This post is about Python and Google Appengine.

I want to store a dict/dictionary in a model. There is no native DictProperty. However there are workarounds.
  • Encode it somehow (for example with pickle) and store it as a blob.
  • Use an Expando model and store your key-values with setattr(yourmodel, key, value). You can get your dict later with yourmodel.dynamic_properties(). See also delattr. This seems to trigger encoding bugs for non-ascii keys.
  • Store keys and values separately with two StringListProperty. Combine them to build a dict with dict(zip(keylist, valuelist)).