I crashed into a closed door

Last night, as usual, Farfalla woke up at about 2 and started purring and crawling on me.  She refused to settle down, so I had to put her out in the basket and close the door.

About an hour later Grace woke up and was yelling for Mommy.  So I got up to check on her, and I must’ve blinked at the  wrong time because suddenly I slammed my nose into the door and was seeing stars.  I woke Brooke up to deal with Grace and went to the bathroom to view the damage.  I could feel blood, but it turned out that was from the outside of my nose, not the inside.  I most likely bruised or cracked the bone, but it didn’t look too horribly bent out of shape.  But then, after I wiped off the blood and cleaned my hand, my body caught up with my injury and I went into a sweat and felt like I was going to black out.

Brooke was done calming Grace down, so she then helped me, getting me a bag of frozen blueberries (!), which helped both to de-shock my body and to dull the pain in my nose.  Eventually I fell asleep propped up on pillows.

This has nothing to do with my banging my head against a brick wall trying to cross compile Perl (again) for Bering-uClibc.  That brick wall is metaphorical.  But I am making progress there.

Porting to Dojo 0.9

I’ve been using Dojo for a while now, and as I’ve gotten my Sakai install stablized (for the moment), the next summer project is going to be to start migrating my JavaScript mappingand plotting code over to Dojo 0.9.

Right off the bat, I’ve got a problem in that I make nifty charts from data (volume versus occupancy for a loop detector station over time, etc).  While I’ve written out data plotting scripts in many languages, I really was kind of happy to not have to do that again with Dojo.  And now the charting engine is gone (eventually to reappear in dojox, I gather).

Maybe as an interim solution I can  just generate the plots on the server and push them out as png files.

But (surprise) I’ve only done that in Perl and LaTeX, not in Java.  Maybe someone has an example in Batik to crank out plots, or maybe I can port bits I use from the Dojo 0.4 charting engine to Java/Batik.

Perhaps I can use this as an opportunity to learn how to *really* use Java servlets, and write a servlet for plotting my data.

I wish I could just use one graphics language everywhere, say ImageMagick or TixZ or whatever.

Regex nightmare in Java: s!\\!\\\\!g becomes .replace(“\\\\”,”\\\\\\\\”);

If you like Java and love java.util.regex even more, stop reading now. I have a small complaint that was a pain to figure out so I am writing it here in the hopes that it may prove useful to someone else.

The title says it all. If you are looking to escape a single backslash in a string, a lowly ‘\’ character, you have to hit it with 4 and then 8 slashes in the replace command.

“Why” you may well ask, when Perl, which also needs to escape the backslash in a regex, just needs the parsimonious 2 and then 4 backslashes to replace a single slash with a double slash. Well, the answer (as near as I can tell) is due to the fact that all strings in Java are interpolated. That is, there is no notion of the uninterpolated string, at least as far as escaping characters goes. So you get the worst of both worlds—there is no way to write carp "The $variable" in a single string (variable interpolation), and there is no way to write carp q{Ceci \n n'est pas une linebreak}, with no escaping happening at all.

Instead, you get the following. Suppose you have a code snippet such as


this.encodedPointsLiteral=encodedPoints.replaceAll("\\","\\\\");

Suppose you pass to that argument the output of the excellent PolylineEncoder class you’ve converted into a Java class to run on your server. Well, if you expect the replaceAll command to work, you will instead get hit with a runtime error. It seems that the string “\\” properly produces a single “\”, which I would expect would be used to find all single backslashes. Instead, it is passed to something else deep in the guts of the regex implementation and interpolated again meaning that the single slash is escaping nothing at all, which is of course an error.

If you instead use the code snippet


this.encodedPointsLiteral=encodedPoints.replaceAll("\\\\","\\\\\\\\");

Then the first quadruple backslash is reduced to a double backlash on the first interpolation (when you write the string with double quotes), and then is interpolated again to result in a single backlash when the pattern is compiled. Similarly, the eight backslashes are reduced to four on the first interpolation, and then reduced to two when the pattern is evaluated as a replacement string.

It is little things like this that give me hope that my Perl skills, such as they are, will never become as useless as my 68000 assembly language talents.

And if you study Dr. McClure’s javascript code, you will see that JavaScript is also as sane as Perl, with the idiom


encodedPointsLiteral: encodedPoints.replace(/\\/g,"\\\\")

doing the job properly.