twenty-first century code monkey

Kategori: Programmering (Side 2 af 2)

JAOO 2007 – Monday

JAOO 2007Again this year I had that opportunity to participate in the JAOO Conference in Århus. Like last year I’m going two days, this year it will be Monday and Wednesday, which is great, because the conference party takes place Monday evening 🙂

Monday started with the opening keynote by Robert. C. Martin in which he talked about clean code and what it means to be a professional developer. He made some really good points and mentioned interesting quotes like: “First make it work – then make it right – then make it fast”.

After the keynote I followed the Virtualization for Developers track for the better part of the day. A lot of our infrastructure at work is virtualized so this track was perfect for me. The track started with a general introduction to virtualization, how things works and terminology, fx Virtual Infrastructure, which I had never heard about before.
Most of the track was presented by guys from VMWare, so naturally it surrounded their products. In the next talk they presented what they call Virtual Appliances (VA), which is similar to a .msi file on Windows, just that the .msi file installs an application, the Virtual Appliances installs a complete virtual machine setup, which may span multiple machines each with different OS and applications. This was quite interesting and it’s already readily available to try out. VMWare has prebuilt VA’s on their site and their VMWare Player application is available for free.

Later on in the track they talked about some experimental features that are part of the newly released VMWare Workstation 6. One of them, Record/Replay, enables you to record all input to the VM and replay it. In the demonstration the user was writing an email, editing a photo, etc. and accidentally opens a file that BSOD’s the PC. In normal cases all work would have been lost, but it this case it was just a matter of replaying all the actions and “take over” the VM at the correct time before it began to open the file that caused the BSOD. A very cool feature, but it still has some rough edges.

After a lot of virtualization talks I decided to sit in on the “Beautiful Debugging” talk by Andreas Zeller. This was an interesting and inspiring session. Andreas Zeller started his session by stating that the only way debugging can be beautiful is if you don’t have to do it at all. He elaborated on this for the rest of the session and he presented the very interesting concept of Delta Debugging where you compare two version of your program, a working version and a buggy version, and modify the input until you can isolate the part of the code that contains the bug. Of course this is grossly simplified description of the process. Unfortunately the presentation was mostly aimed a C code, but I guess it should be possible to use the same ideas and principles for debugging java.

After all the talks it was time for the party keynote which was held by Charles Simonyi, who is the 5th civilian to travel to space. Unfortunately this was not as exciting as it sound and seemed a little bit like your average holiday picture presentation, though some parts were okay.
The party started shortly after the keynote and the drinks and food was excellent. The food was prepared by Chili John and the beer was sponsored by Microsoft and Sun.
Unfortunately we had to leave rather early since we had to travel back to Aalborg in time for work on Tuesday, but we still had time to enjoy the party, the food and the beer.

All in all Monday at JAOO 2007 was great, and I’m looking forward to my second day at the conference this year.

New email notification for Evolution v2

About a year ago I posted about a small python script that shows a pop up each time a new email arrives in Evolution.

Since then I’ve been working on a new version from time to time and with the release of Ubuntu Feisty Fawn it’s time to release a new version of my code. This time around it creates a status icon and a status icon pop up when new mail arrives as seen below

New email notification v2

When the icon or the pop up is clicked the Evolution window receives focus through the use of wmctrl. Unfortunately I have not yet been able to retrieve and display the subject of the email or to select the newly received email when giving focus to Evolution. Perhaps that will happen for v3. Feel free to give me pointers!

The script can be downloaded here.

To run the script you will needs these packages on Ubuntu:
apt-get install python python-dbus python-notify wmctrl

If you needs pointers on how to implement something similar I can recommend Python’s Status Icon doc as well as the Desktop Notifications Specification for communicating with dbus.

Digital Signatur trickery

In Denmark the government is pushing the use of a digital certificate to identify against most government websites, etc. and for signing and encrypting email. I kinda like the idea so I signed up for one back in ’04. It expired last month, though so I have renewed it, although not without my fair amount of trouble. Apparently Linux and/or Firefox isn’t as supported as they would like the general public to think. (Or perhaps it’s, as usual, my own fault for using beta software – Firefox 2 and Ubunty Edgy).

Anyway, I booted Windows and got the certificate renewed and created a backup. Back in ’04 the backup was actually the PKCS12 certificate file, but that is not the case anymore. Nowadays it’s a plain old HTML file with some in-line javascript that loads the “required” software to install the certificate. PKCS12 is pretty standard and doesn’t require any additional software, so I don’t get why I can’t just have the file directly.

The usual path for the PKCS12 file is to load the certificate in Internet Explorer using the html file, and then export it. But for some reason it’s not possible to export the private key, only the public key. I tried this both running Internet Explorer in Windows and through wine, but with no luck.

At this point I was kinda pissed and figured the html file must have some information regarding the PKCS12 file and surely it did. Looking at the javascript there’s a variable with the name “pkcs12”. This variable is base64 encoded though, since PKCS12 is a binary format. So I quickly hacked together a little python script that extract and converts the certificate, so it’s ready for use by Firefox, Evolution, etc.
If you have the same problems as me you can get the script here and run it like this:

./extractpkcs12.py backup_file.html output_certificate.pkcs

JAOO Conference 2006

JAOO LogoThis year I had the opportunity to participate in the JAOO conference sponsored by my employer, which was quite nice. I was able to join in on Tuesday and Wednesday and my plan was to follow the Performance in Modern Enterprise and Open Source Enterprise Java.

Tuesday
Tuesday’s keynote was held by Guy Steele where he presented a new programming language he’s working on at Sun, namely Fortress. Fortress is designed with parallel computing in mind which means that by default for-loops, etc. will be parallel instead of sequential. Also the language is made for scientific computation, which pretty much means maths out of my league, so I didn’t quite get the computation of vectors, etc. he talked about, since I’ve never worked with that before. Anyway, the first half of the presentation was quite interesting, but in the second half Guy went into too much details with the maths.

After the keynote I heard the first four talks on the Performance track. The highlight was definitely the talk on Performance Anti-Patterns by Kirk Pepperdine, which had a couple of interesting points and I have to say, at least some of the code I write fits all too well with these patterns. Kinda bad 🙂 Anyway, the talk inspired me which is a huge plus in my book.

The talk on The Art Of Micro-Benchmarking In Java by Angelika Langer wasn’t too exciting, but the part where she talked about the Java HotSpot VM was quite interesting and I learned a lot.

The rest of the day I switched to the Java Rich Client Development track, which meant the talks on the Google Web Toolkit by Bruce Johnson and the Echo2 framework by Tod Liebeck.
The Google Web Toolkit (GWT) is bad ass and caught my interest from the beginning and Bruce Johnson was quite good at entertaining the listeners and getting his message through. In many ways GWT is AJAX made easy, as it wrap the entire JavaScript thing in well-known Java code.
The Echo2 Framework was in many ways the same thing in a different wrapping. Unfortunately for the presentation, Tod Liebeck seemed very nervous and he had a hard time getting the message through. Still the Framework looks quite interesting, but doesn’t run quite as smooth as I would’ve expected on my machine. (I’m running the development version of Ubuntu Edgy, so perhaps it’s my own fault!)

Wednesday
On Wednesday I was supposed to followed the Open Source Enterprise Java track, but I decided to listen in on the Hot Old Ideas – Experiences Of An Old Country Programmer by Dave Thomas. Dave Thomas talked about all the various programming languages he had worked with or at least have touched in some way during his career and this was quite a few. It caught my interest and I felt like following the Back To The Future track, but I figured it would be of mostly nostalgic value, so I decided to follow the Open Source track as planned anyway.

I heard a talk on JMS and Apache ActiveMQ by Bruce Snyder and after that a talk on Spring and Patterns by Eberhard Wolff, where he talked about how Spring uses patterns. I really like working with Spring, so I had high expectations for this talk, but (obviously) I was disappointed as I didn’t really learn anything new.

Next up was Are We There Yet? by Rod Johnson. Rod talked about how Java Enterprise have progressed since 2003 to where we are today, and talked about which direction Java Enterprise could potentially go in the next years. This was interesting and gave me some insight into technologies I haven’t worked with before such as Aspect Oriented Programming (AOP) and Spring 2.0.

That was the last real talk on the Open Source track, so I decided to follow my co-workers to the Kevlin Henney talk on the Architecture Quality track. This turned out to be a great decision, since Kevlin made some really good points and did it with a sense of humor that was very entertaining.

Finally I went to the keynote panel on How Will We Be Programming in 2016?. This panel turned out to be quite entertaining as well and the listeners had a few laughs, but we didn’t really get a definite answer on the question, which was kinda expected I guess 🙂

Overall the two days at the JAOO Conference were great and I look forward to next years event.

Video files for your Ipod Video the easy way

Once in a while I need to convert some video files so they are playable on my Ipod. I can never remember all the parameters I need to specify to ffmpeg, so I hacked together a small scripts that does all the magic. It does a two-pass encoding of the video file and the quality is quite nice.

You can get the script here. If ffmpeg complains about missing codecs, etc. simply get it from Debian Multimedia.

If you insist on running ffmpeg directly you can try these parameters, that’s what I used to do before I made the script.

ffmpeg -i [in file] -vcodec xvid -b 384 -s 320x240 -qmin 2 -qmax 5 -bufsize 4096
-acodec aac -ab 96 -g 300 -pass [1 or 2] -passlogfile /tmp/ffmpeg.stats -f mp4 [out file]

Search Engine for Java

Apache Lucene logoFor a project at work we need some search engine like functionality. We’ve tried to do it ourselves, but usually our implementations were too slow, too memory intensive or too much work to maintain. I was recently recommend by one of my coworkers to have a look at the Apache Lucene project, so I’ve spent the last couple of nights studying it and doing a test implementation. Coincidentially, Lucene released the 2.0.0 version in late May. 🙂

First impressions are quite impressive – Lucene is a very easy to use search engine and it’s quite fast as well. It is possible to implement a fully working search engine with only a few lines of code. To do this you need two parts – an indexer and a searcher.

The indexer can be implemented with the following lines of java code.

IndexWriter indexWriter = new IndexWriter("/tmp/index", new StandardAnalyzer(), true);
Document document = new Document();
document.add(new Field("article", "This is a sample article to test the Apache Lucene search engine", Field.Store.YES, Field.Index.TOKENIZED));
indexWriter.addDocument(document);
indexWriter.close();

These lines of code creates the index for the Lucene’s searcher. Of course the index is rather small with just one document, but it’s easy to add more fields to a document and more documents to the index.

The searcher can also be implemented with a few lines of code.

IndexReader indexReader = IndexReader.open("/tmp/index");
Searcher searcher = new IndexSearcher(indexReader);
QueryParser parser = new QueryParser("", new StandardAnalyzer());
Hits hits = searcher.search(parser.parse("sample"));
System.out.println("First hit: score " + hits.score(1) + " - " + hits.doc(1).get("article"));
indexReader.close();

This code creates a Searcher that will search the index for the search word “sample” and print the first hit to System.out. This is really all that is required to build a basic search engine. You will of course need all the glue code to make it user friendly and customize it to your needs.

All classes are from the Lucene project, so all that is required is the lucene-core-2.0.0.jar file somewhere in your classpath. Oh.. yes.. you need to catch a few exceptions as well, so the above code won’t run directly. 😉

New mail notification for Evolution

Here you’ll find a small python script that will show a nice little notification when a new email is received by Evolution. It looks like this on my machine running Ubuntu Dapper.

New mail notification for Evolution

The script works by attaching itself to your systems dbus and listens for “new email” events from Evolution. When an event is received it compares the email folder to the _watch_folders array and decides whether to show the notification or not. The magic really lies in the two dbus lines near the bottom of the script. The rest is just to make the notification a little nicer. The magic part is actually the work of a former coworker of mine, so I can’t really take credit for that 🙂

The scripts of course requires python as well as libnotify to display the notification and the tango-icon-theme for the nice icon. The following commands should prepare your system to run this script. Just toss the script into gnome’s session manager and it’ll always run at startup.

apt-get install python2.4 python2.4-dbus libnotify-bin tango-icon-theme

Nyere indlæg »

© 2024 Tommy Winther

Tema af Anders NorenOp ↑