First skydive of the year at Fallskärmsklubben Göteborg - grymt!
64 characters. I wonder whether I should start twittering :) ?
Monday, April 27, 2009
Sunday, April 19, 2009
Uteservering II
Well, I promised some pictures of uteserveringar. Here we go. These pictures are all taken around Kungsportsplatsen in Göteborg.
Sunday, April 05, 2009
Uteservering
Time to let you in again on a little Swedish way of life - uteservering. All it is means that cafes and restaurants serve food and drinks outside. Big deal you ask? Well, here in Sweden it is. As far as I know there are even laws which governs in which period of the year restaurants can do that. Obviously it is out of question during winter. But the magic date is 1st of April. Suddenly you see outdoor chairs, tables and terraces popping up everywhere. However, even spring has certainly arrived by April, the weather can still be quite cold and chilly. That cannot stop a true Swede. As long as there is a glimpse of sun shine everyone will flock to the uteserveringar. See and be seen! Many uteserveringar will even have felt blankets on the chairs one can use to keep warm. I cannot stop wondering whether the law preventing uteservering before April is just there to keep Swedes from freezing to death. Just the fact that a table stands outside the restaurant seems to be enough reason to be sitting there. I will try to add some picture over the next few days. Otherwise come and see for yourself. Not only the nature is waking up right now, but also the whole country. I am suddenly realizing again - I am not alone.
Saturday, April 04, 2009
WTF!
I have to start this blog with a rant. I am currently working at Hibernate's reference implementation of JSR 303. I started out using Junit 4 for unit tests. However, in order to leverage from some other framework I had to switch to TestNG. I thought it should be quite easy to change from one framework to the other - basically just switch the import statements. Turns out is was more difficult than that. After a global find and replace in the test files replacing the package statement I ended up with multiple compilation errors. The problem was that in Junit the assertEquals method has the signature assertEquals(String message, Object expected, Object actual) whereas TestNG's assertEquals is assertEquals(Object expected, Object actual, String message). WTF! Given that TestNG came later - which reason did they have to swap the arguments? Just to make it harder to migrate from one to the other? This applies of course for all assert statements. I am just using assertEquals as an exmaple.
Anyways, I started manually changing the calls, but that was just too tedious. It was time to get sed out again, but soon I realized that sed was not going to cut it this time, because there is no way do non greedy regular expressions . The expression also had to take care of single and multi line statements. An example for a multi line statement would be:
Time to get good old perl out again. Here is what I came up with (the whole expression is one line!):
Well, it did not solve all my problems. In some cases the formatting was a little off, but that could be easily fixed with my IDE. Some comments about the expression:
enjoy!
Anyways, I started manually changing the calls, but that was just too tedious. It was time to get sed out again, but soon I realized that sed was not going to cut it this time, because there is no way do non greedy regular expressions . The expression also had to take care of single and multi line statements. An example for a multi line statement would be:
assertEquals(
"Wrong propertyPath",
propertyPath,
violation.getPropertyPath()
);
Time to get good old perl out again. Here is what I came up with (the whole expression is one line!):
perl -pi -0777 -e 's/(assertEquals.|\n*?)(".*?"),[ ,\n,\t]*(\w*?,)([ ,\n,\t]*.*?)([ ,\n,\t]*)\);/$1$3$4,$5$2\ );/g' MyClass.java
Well, it did not solve all my problems. In some cases the formatting was a little off, but that could be easily fixed with my IDE. Some comments about the expression:
- the -i option allows editing of the file in-line. A very nice feature of perl and something I miss a lot in sed
- -0777 specified the line break character in octa-decimal. Assuming 777 does not appear in your file this is an easy way to match across lines
- there are a lot of \n matches. Even when matching across the whole file .* won't match the new line character. It has to be explicitly specified
- using regular expression buffers I am able to capture the groups of the statement an put the expression together in a different order using $x notation for referring to the matching buffers
- and I almost forgot the ? after the operators ?, + and * turns on non greedy machting
enjoy!
Labels:
perl,
regular expression,
sed
Subscribe to:
Posts (Atom)