Sunday, September 30, 2007

El Escoreal and La Noche Blanca

The last week and -end I was very occupied with two things: the annual CNIO Retreat in El Escoreal (25 (!!) talks about cancer...) and the White Night in Madrid (all museums, theaters, etc. are open all night round).

El Escoreal was more of a "cultural & social" event: apart from having some drinks the first night with my workmates (no, I did not go out 'till 6 in the morining again - last year was enough for me!), I also watched the Vuelta (the spanish "Tour de España"). After seeing it, I can happily confirm: visiting bike races is probably the most boring sport event to attend to - 5 min of action (uh, which action?). Also, I went with Martin and Carlos to the El Escoreal monastery, where basically all the spanish Habsburgs are burried - i.e. a "must" for an Austrian, monarchist, or a republican who wishes to release his anger (we were wondering why Carlos, a Mexican Republican, did not piss on the graves - just kidding in case you read this, Carlos ;-]). Anyway, a quite impressive place, but not what you would expect from a King who pretends to live a modest monk life (well, Phillip II probably thought it was...).


The second event, La Noche Blanca, was quite fun - and very long, until about 11 am in the morning. We tried to visit some of the performances and attractions, but stopped this quite soon: You just can't imagine how many people are out on the streets, it seems all of Madrid is there at once. My modest estimate is one million, really - I never have seen something like this (and I thought Madrid is crowded at night quite regularly... well, this beats everything). So after fighting through the masses, we went to a party place on the southern rim of the center, which proved to be just as crowded. In the end, at about 7 am, we decided to "retreat" to my place and have some copas (drinks) with good music at my place. There somebody showed me "Testimonios" on youtube.com: if you understand a bit of spanish, very funny comedies of Björk et al.!

Monday, September 17, 2007

Weekend Dance

As it is still summer time here in Madrid (well, at least for us northern foreigners), I just enjoyed a all-night open air DJing event in t-shirt and short pants this weekend. Remember this is Madrid, so nothing ended before the sun chased us away! It also was the first time I saw Massive Attack live, which turned out to be quite cool. They're not so much bout an energetic performance, but you could imagine them as a mixture of Pink Floyd-ish showcasing and a De Phazz-like Mary Jane atmosphere... Anyway, great concert with about 50k visitors in a full arena. I even liked Sven Väth - but only only because I was standing next to a wall for his performance, so his BPMs were doubled by the echo :)=)... Oh, and if you like slightly harder beats (they had tons of good old hardcore samples in their mixes), put you ears on Vitalic, at least live they rock! Another unknown tip and quite impressive was Digitalism. Have phun listening!

Friday, September 7, 2007

Why I like Apple

TextMate Python and Django cheat sheet

After not finding anything appropriate, I decided to do my own reference card (aka cheat sheet) for the pythonic and django commands you can use in TextMate. If you want to have it, download it from here.

Monday, September 3, 2007

Another reason why Java looses big

WARNING: this is a pure geek post - don't read if you are not into programming or (lucky you) never have to touch Java.

Because of a certain library and some other reasons, I recently was forced to program in Java. In this course, I had to make a command line call (to dump flatfiles into my PostgreSQL database). Knowing many languages, I though this would be pretty straightforward with Java, too - nada! Here's the code to do a command line call in Java as safe as I can get it:

/**executes cmd on the Runtime
*
* This method throws a RuntimeException if any output
* is found on STDERR - so catch it if your program
* does so to log only. The content of STDERR is
* sans newlines in the message of the RE.
*
* @return exitVal - anything else than 0 is invalid */
private int runtimeExec(String cmd)
throws InterruptedException, IOException {

// execute the command
Process child = Runtime.getRuntime().exec(cmd);
int exitVal = child.waitFor();

// check STDERR
InputStream stderr = child.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null)
error.append(line + " ");

// close the streams
stderr.close();
child.getInputStream().close();
child.getOutputStream().close();

// throw RE on STDERR output
if (error.length() > 0)
throw new RuntimeException(error.toString());

return exitVal;
}
Pretty nasty, eh?! So which precautions are required? Here's the explanation of above code:
  • Although a program should terminate with exit value non-zero on error, I found that the postgres dumping using psql -d mydb -f mydump.pg actually does terminate with 0 when an encoding error is encountered. This means your program happily continues while your database has been abrogated. The only means to find this situation is to throw a RE on any text found on STDERR.
  • The second really bad thing is if you call this code say a few thousand times, you will run into a "too many open filehandles" error. Why? Because you have to close all three streams (IN, OUT, ERR), as the Java GC just sucks - my process runs over days, going into this segment about 1000 times. So on about the last day, this program crashes. Nice, just love garbage collection...
Oh, and it actually still ain't completely safe: you would have to do a try...catch...finally to close the streams, if you'd want to be perfect!

So my advice, again, is: keep away from this hideous language and develop something real! I hope this was my last "me vs. Java"-encounter for a long time!