vendredi 28 décembre 2007

EasyMock and methods with side effects

I really like EasyMock, but was disappointed to not see any explanation in the documention about how to simulate the modification of an argument of a method with side effects.

I thought that maybe I could write a custom argument matcher that modifies the argument (even if it seems weird to implement a side effect on the matches method of the IArgumentMatcher)

Actually, it was confirmed by this brilliant article about a Generic Custom Argument Matching in EasyMock

mercredi 12 décembre 2007

Continuous Integration and test environment availability

When a developper does not have an environment to run the unit tests of a projet, never allows this team member to check in, even if you have a continuous integration server running.

If the build is broken, this programmer will have to perform several check in with the new code and wait for the next build in order to know if the build was fixed. Et voilà, the continuous integration server has become the test environment for this person...

jeudi 22 novembre 2007

Convert an image to high quality PDF, Redux

In a previous post I explained how to Convert an image to PDF with Gimp, but the quality of the picture in the PDF turned out to be rather poor for printing purpose.

So here is an other way, install tiff2pdf.
On Ubuntu for instance :
Then save your image as a tiff image, then use tiff2pdf to convert it to a PDF. For example, for an A4 sized PDF :

For a multiple pages PDF, preprocess your TIFF files with tiffcp

dimanche 18 novembre 2007

Convert an image to PDF with Gimp

In order to have an image printed by a professional printing service, I had to export the image created with Gimp to a PDF file. Here is how to do that.

  • With Gimp save the image as a PS file, with the right size in the option dialog box (for instance, for an A5 dimension choose 148x210 mm)

  • In a terminal convert the ps file to a pdf file, with the matching size


Update : There's an other another way that gives much better results regarding the compression ratio of the picture in the PDF, see Convert an image to high quality PDF, Redux

vendredi 2 novembre 2007

Karl Weick quote

“Fight as if you are right; listen as if you are wrong.”Karl Weick

mardi 9 octobre 2007

I want closures in Java !

It's true, trying other programming languages, different enough from your main programming language make you a better programmer/designer in general.

My main programming language is Java, but I also do a lot of Ruby, and it definitely helps me to find new technics in Java.

Now, the problem is : the more I use closures in Ruby, the more I miss closures in Java...

However sometimes, even in Java, the only answer to some OOP problem is some sort of closure, implemented via a callback interface with an anonymous inner class. But the syntax cost of such a construct is very high. All the more so since only final local variables can be used in the anonymous inner class.

So. I do hope closure will make it in the next release of Java.

dimanche 7 octobre 2007

XMLRPC/Ruby presentation for TSP

The slides of my presentation on the implementation of a TSP consumer in Ruby for the first TSP workshop are archived here.

samedi 6 octobre 2007

TDD : state-based testings VS behavior-base testing

Using TDD to write my code I'm still trying to find when I should use mock objects or just test against the whole cluster of objects. That's the difference between state-based testing (no mocks) and behavior-based testing (using mocks) explained in this brilliant article by Martin Fowler : Mocks Aren't Stubs

I'm sure that both technics are useful and I switch from one technic to an other depending on the complexity of the objects I'm testing.

  • State-based testing (no mock) tend to increase the amount of integration test between objects, so is better suited to tests clusters of object with complex interaction

  • Behaviour-based testing (with mocks) tend to increase the test coverage on a given object as it is easier to control the test environment of the object under test


Using mocks objects tend to create more work, but the more I use them the more I detect bugs in my code that would very hard, or impossible to detect with state-based testing.

Last time it happened it allowed me to see that an external object was called and was not supposed to be called (because the mock was called and warned me that it was an unexpected call)

I would have never been able to detect this call with state base testing because :

  • It did not change the state of the object under test

  • It did not change the state of the external object


However the call to the real external object is very CPU intensive and would have harmed the performance. Behavior based testing allowed me to see this, it would have been undetected with state-based testing.

jeudi 4 octobre 2007

TDD, red-green-refactor : red as important as green

When I got started with TDD, I tended to often forget the first step : red

At first, it can seem silly to try to run a test when you did not write the matching functional code. You may think "Of course, it is going to be red ! There's nothing in my application for this feature !"

Of course... Unless there's a bug in your test. And it could be green and you're not going to see it. Then, you write the application code, with a bug too, you run your buggy test, and it is green even with your buggy functional code...

Basically the red step of red-green-refactor helps you debug your test before your code. The red step really is some sort of TDD applied to the test itself. When there is no functional code, a test must be red. It does not mean that the test is correct, but if it is green, surely, it must be fixed.

And even if your test is red and buggy, it is not a big deal, because when your functional code will be written, the test will be red too. The problem could come from your functional code, from your test, or both, but at least you will have to fix something to make the test pass.

TDD like all Agile techniques, is all about rapid feedback. Red gives you feedback about your test, green feedback about your functional code.

lundi 24 septembre 2007

Unusual Git usage : temporary commit into a local SVN checkout

I really love Git, the distributed source code management designed by Linus Torvald. It is VERY easy to setup a new local repository (just type git init in the root of your working directory). I do it all the time, even for a simple bash script creation. Even for the simple text files I use as TODO lists.

A few days ago, I add to work offline in an old SVN checkout. I wish I could have used git-svn but it was an old checkout, and I was offline now. So much for git-svn for now...

I had to find something to be able to undo my changes while I was offline. So why not try Git in a local SVN checkout ? After all, the only thing that Git does is to create a .git file, it does not modify the local files if I don't want to.

So, at the root of my SVN checkout directory :
git init
Then, I must hide the .svn metadata directory, so I modify .git/info/exclude and I add the line :
.svn


Now Git will ignore the .svn directories and I can type :
git add .
git commit

Now at least I can regularly commit my changes into Git and go back in time if
I badly break my unit tests during my TDD session. Of course when I'll be back online
and I'll commit into the SVN repository I'll lose the commit history in Git, but as I
was offline anyway, at least I could work with a safety net.

Even used in this unusual way, Git is still useful.

jeudi 20 septembre 2007

JAgraffe : quickly send your pictures by email

I had coded JAgraffe two years ago for my own use. I still use it almost on a weekly basis.

mardi 18 septembre 2007

Usual GnuPG commands

I tend to forget these very usual GnGPG commands as I use them only once in while. Now I won't forget them, or at least I'll known how to quickly find them :

Sign a file :

Encrypt and decrypt a file for my own use :

Encrypt a free text for someone :

Get my own fingerprint :

samedi 15 septembre 2007

Mix RJ45 and coaxial (10Base-2) ethernet cables

Problem : how do you add a WIFI AP (Access Point) to an already existing network wired with 10Base-2 coaxial ethernet cables ?

Of course this is an old network with old PC, and you can not replace the 10Base-2 network adapters of the PC in order to rewire with RJ45 cables.

Answer : just find one more 10Base-2 network adapter in a drawer, and add it in an old Linux box that already has a RJ45 network adapter.

Setup two subnetworks, one on each adapter of the Linux box, with routing of the traffic from one subnetwork, to another (or even better, build a bridge, in order to have one single subnetwork).

Plug in the AP to the linux box with a crossover RJ45 ethernet cable.

This linux box can even be used as a gateway both for the LAN and for the WLAN !

vendredi 14 septembre 2007

Simple iptable gateway script

It's the second time I must setup a Linux gateway connected to a DSL line. The DSL modem interface is ppp0 and the LAN interface is eth0. Here is the script I use to setup the iptables :

lundi 10 septembre 2007

Sort JPG images by EXIF date in Ruby

Everybody now has a digital camera, and, during special events everybody takes plenty of pictures, and you end up with all these JPG images from different cameras. Each set of pictures tells the same story from the beginning, so it would be great to be able to reinterleave all of them in order to tell one single story.

That what the folllowing little Ruby script does, thanks to the libexif-ruby library. If you run it in a directory with JPG images, it will create a subdirectory and copy all images, renaming them, prefixing with the EXIF date set by the camera.

First, install the libexif-ruby library. On Ubuntu you can type :

Then copy the following script in a ruby script file :

samedi 8 septembre 2007

Linux and Logitech MX mouses resolution

Without its real driver, my Logitech MX 510 mouse is seen by Linux as a 400 cpi resolution mouse. Actually it can be used in 800 cpi thanks to lmctl

I've added this script to the 'Startup Program' list of Gnome :

The xmodmap call allows to properly configure the thumb buttons.

An other Nautilus script : create directory with date

I've already described how to add custom scripts for Gnome file manager, Nautilus. So here is a an other simple script : it allows to create a directory with the name prefixed by the current date, via the contextual menu (right click) of Nautilus in the window of an other directory.
Just type the name of the directory in the popup dialogue ; spaces will automatically replaced by underscores.

You must install XDialog to be able to use this script.
On Ubuntu :

And here is the script :

jeudi 6 septembre 2007

Nautilus File Manager scripts : Scale JPG images

I really appreciate the feature of Nautilus (Gnome file manager) that allows the use of custom scripts via the right click contextual menu. To be seen by Nautilus, the scripts must be copied in a specific directory ; you can reach this directory with :
Right clic in any directory window --> Scripts --> Open Scripts Folder

For example here is a bash script that can be used to scale all JPG images in a directory (a directory is created and the scaled images are copied into this directory).

You must install XDialog and ImageMagick to be able to use this script.
On Ubuntu :


Then copy the script in the script directory of nautilus :

mardi 4 septembre 2007

Simple CruiseControl + Ant example

I always have a hard time finding online a simple example of CruiseControl + Ant file whenever I need to quickly setup a Continuous Integration server for a project. So here is the configuration I had set up for the open source project TSP (Transport Sample Protocol) :


For TSP the Ant build file was there to trigger the C build :

For TSP the setup instruction were :
  • install a binary distribution of cruise control
  • replace the config.xml file with the previous file. Change the email addresses of the 'returnaddress', and the 'always address'. You can add as many 'always address' as you want
  • go to the 'projects' directory of the cruisecontrol install and perform an anonymous check out of tsp :


you can test the build without cruise control if Ant is available :
go to projects/tsp/make and launch :

If everything is OK, with the build, run the cruisecontrol.sh script. you're done,
cruisecontrol is up and running.