Sharing my work
Today I have released a piece of software that I have written as free software. It's a small library that is used to generate the information stuck to an MP3 file that tells your MP3 player what you are listening to, something called an ID3 tag. The software is mostly simple, but it uses some of the advanced CRC32 reversal stuff that I blogged about a while back, so it has some neat features if you're in the business of creating dynamic metadata to audio files stored in dynamically created zip files. My prediction would be that very few people would actually use this, but the standard ID3 generation functionality is probably useful to some.
Anyway, I'm really happy to be able to give back to the free software community, small pieces of software that I have written. My dream is to some day write a piece of software that grows it's own community around it, with other people contributing new functionality and fixes to problems. I hope that some day that dream will come true. For now it's just me publishing small parts of the software I write. Not all that bad.
For interested parties the information about my library, named id3j, is found at Voxbiblia's Free software page.
Update:
Changed the name of the released package, because of a naming collision.
From Ruby on Rails to Java
I have been tasked with making some extensions and changes to a system written i Ruby on Rails with some parts written in Java. For reasons I will not write about at this time we have decided that we want to move away from Ruby on Rails and instead develop using java and the excellent Spring framework.
Leaving one development framework for another is often a painful experience, where lots of code needs to be thrown away and rewritten in one step. For this particular situation doing that massive rewrite, technology change has been something we wish to avoid and here are some info on how we plan to do that.
The first step was to move both the java and the ruby environment into the same namespace from the point of view of the web browser. Since we already use the Apache httpd as a front end for the Ruby environment—executing it via mod_fcgid—this was a simple matter of configuring the same apache httpd instance to proxy all requests to the java environment. That way we can make relative links from pages created in he ruby environment to pages in the java environment.
The next problem to tackle was session management. More specifically, when a user logged in using Ruby on Rails we and then navigated to a page served by the java environment we needed to propagate the information about the logged in user to the java code, hopefully without doing any drastic changes to the ruby code.
It turns out that doing that was not that difficult. The way our Ruby on Rails environment is configured it uses Active Record to store session information associated with a specific cookie in the web brower in the database. Since both ruby and java lives on the same webserver from the point of view of the brower, any cookies set by rails is also sent by the browser as a part of the reqests that ends up in the java environment.
I have then written code that uses the cookie to look up the session data in the database from java. That data consists of a Base64-encoded binary data using the Marshal.dump() facility of Ruby. It turns out that data is not particularly difficult to parse relevant bits from. Looking for the ASCII string of the key of our user id value in the session object in Ruby, then look for the next double qoute char and parse all ASCII digits before the next double qoute occurs seems to be a fully workable solution.
The code to do this can be looked at in RailsSessionIntegrationHelper.java. If you want to get rid of the Spring Framework dependency, just replace the method getSessionData() with one that does raw JDBC instead, and remember to close your connection when you're done.
Filed under Geeky, Programming | Comment (0)Image resizing in java
Doing good image resizing in your favourite software development environment shouldn't be hard. After all, lots and lots of software that has a graphical user interface of some kind needs to do image resizing. However, in java it isn't as easy to do as it should be. I had some resizing needs, more specifically I needed code to resize a large black-and-white image into thumbnail size.
After googling a bit I came up with a recipe from the official Java 2D FAQ at sun.com and used that. After all, the creators of Java should know how to do it right. However, I was surprised to find out that the visual result of the resizing was terrible. Have a look for yourself:

I started out with this letter a in black and white. When resizing that one to a version 40 pixels wide with the code that sun suggests, it looks like this when magnified:

As you see, there is some grayscale smoothing going on but not much and the overall impression is quite jagged. Before anyone asks, yes I'm using the bilinear interpolation option. Compared to the result when resizing in GIMP, ImageMagick or just about any other tool the result is terrible. So i tried around, googled and looked at code here and there.
I was on my way to accept that java just didn't do this, and restort to calling a command line tool from my web application when I found a piece of code that compares the speed and results of different scaling methods. It turns out that if you use the getScaledInstance() method of the java.awt.Image base class with the Image.SCALE_SMOOTH as last parameter, the result looks much better.
Here is a blown up version of a 40 pixels wide rescaling using that method instead:

Ah, much better. Why is this? I don't know. If there is anyone out there that can give me details on why this is I'm more than happy to be educated.
So, if you want to copy my method, please have a look at ImageResizer.java. The version calling a verbatim copy of the suggested solution from Sun's FAQ is in the method sunResize() and the better looking version is in resize().
Filed under Geeky, Programming | Comment (0)The rumours about my demise…
I've been away from my blog for a while. Sorry about that, but Alex has had some complications from a surgical procedure a while back and he has gotten to know some quite nasty multi resistant ESBL producing bacteria in recent weeks and blogging is one of the things that has been postponed.
Anyway, I hope to be back now, at least in some capacity. Since there seems to be people annoyed by an inclusive greeting phrase, I'm happy to indulge:
Happy holidays, friends. It's good to be back.
Filed under Meta | Comment (0)It will be ready on time, Lord Vader
Well, that's debatable. At last however, me and my dear darling has managed to finish building 10143, a.k.a. the Lego Death Star II. Thanks for the fantastic gift, ordningsfrun and family!
Filed under Geeky | Comments (3)
Some thoughts on the failure of John McCain
I knew it! Just as surely as water is wet I will be disappointed at the presidential campaigns in the last weeks before the general election. However, I'm more disappointed at McCain than I expected to be. It feels like things went downhill from the Palin nomination and took a turn for the worse in his response to the financial crisis. My impression of McCain from the 2000 primaries and onwards is that he would be a republican for thinking voters that wasn't stuck in an unholy alliance with the christian right. Someone that with experience that had taken fights with lobbyists, earmarks and someone that had not always chosen the path of least resistance. To me that image was reinforced in the republican primary this spring, when he won against Mitt "Double Guantanamo" Romney and Mike "amend the Constitution so it's in God's standards" Huckabee I interpreted that as a mandate to run a campaign not on fear of terrorist attacks or the promise of a christianist theocracy.
And yet we are here. McCain choose a running mate in Sarah Palin that is just too much. She refuse to have any press conferences, she obviously has a problem with abusing power as has been shown in the state trooper firing investigation and the little we know about her policy stances she is as far out on the right wing side as any of the people that actually lost the republican primary. McCain apparently chose Palin without any serious research. That's a bit scary.
What is more scary, I think is that he managed to look everything but presidential when the recent economical crisis showed it's ugly face. He claimed to suspend his campaign (which he didn't) to get the republicans in congress to support the bail-out bill (which he failed at) only to go on with some really bad suggestions on how to solve the crisis. He managed to miss completely to point out that he had opposed the political decisions that started the suprime mortgage lending which is arguably the biggest single reason we're in this mess. From what I've heard Obama's positions on government mandates telling Fannie and Freddie to lend to people with poor credit ratings is not something to be proud of.
When things began to look bad in the polls, McCain did what may has done before. He went 100% negative in his ad buying, using all of his TV ad budget to attack Obama, and he didn't do it very well at that. I think that most people see through trying to the attempts to tie Obama to the 70s terrorist Ayers. Even if it works it distracts McCain from getting out his main message. He can not not expect to win only because Obama seems scary, he needs to get his own message out as well.
So now almost everything points towards Obama as the next president. Let's just hope that he isn't against free trade as he pretends to be in his campaign. If he is, then this recession might very well turn into an ugly depression.
For a more insightful text on the failure of the McCain campaign in the longer perspective, I must recommend Ezra Klein's excellent article McCain's Anger problem.
Filed under Politics | Comments (3)Getting out of the closet
When is it appropriate to talk about your sexual orientation and gender identification? A difficult question, one that I struggled with a bit a few years back when I had just admitted to myself that I was bisexual, yet I was living in a heteronormative relationship and there were almost no one that knew that about me.
My bisexuality is an important part of me, and something that I want people around me to know about me. When people I spent time with didn't know about that I felt a bit like I walked around with a secret, a secret that grew bigger and bigger by the day. Something that brought a feeling of distance in many relationships.
Life took a turn and I found myself sitting in a sofa on national TV (14min, Swedish) talking about my sexual orientation, and suddenly it was difficult to be more out than that (well, being in a four page interview (Swedish) in Sweden's largest newspaper did also help), but others might not have that luxury. That's one of the reasons of the National Coming Out Day this saturday. The coming out day is a great opportunity to tell people that you don't normally talk about your sexual identity or gender identity who you are. If you are a Facebook user you can use your status message to tell the world that you are gay, bisexual, lesbian, transgendered, a straight ally or anything else that you would like the world to know about. Welcome out of the closet, whoever you are.
Filed under LGBT | Comment (0)I got my name in the paper!
When I was ten years old someone at Budbäraren, the weekly publication of the christian congregation that I was a member of at the time, did a human interest story on me. I remember the interview clearly, we talked about my interests and she took my picture when I played the violin, took a ride with my skateboard and played in the park. The feeling of seeing my name in print when the article was finally out was nothing short of amazing. Exactly the kind of attention I love.
Today I got a similar feeling, when my business partner Johan was interviewed in Financial Times about our company, Voxbiblia. And he even mentioned my name, next to the title "talented programmer". It feels almost like I'm ten again. Not quite, but close.
Filed under Voxbiblia | Comment (0)

