Note to self about class methods

Don't use them unless you are knowing what you are doing. I recently ran into something strange and was quite busy fixing the problem using much database mojo.

For the calculation of some MD5 sums I was using Digest::MD5. And for some reason I used it this way:

perl -MDigest::MD5 -le 'print Digest::MD5->md5_hex("foo")'
3200a4cda22a4a935412da8113b4139b

Looks good doesn't it? But the MD5 digest is incorrect. Just try it yourself and enter 'foo' in any given web MD5 generator out there.

The right way to use Digest::MD5 (and Digest::SHA1 too) would be

perl -M'Digest::MD5 "md5_hex"' -le 'print md5_hex("foo")'
acbd18db4cc2f85cedef654fccc4a4d8

Okay, my fault. But this annoys me a bit:

perl -w -MDigest::MD5 -le 'print Digest::MD5->md5_hex("foo")'
&Digest::MD5::md5_hex function probably called as class method at -e line 1.
3200a4cda22a4a935412da8113b4139b
fh$ perl -Mstrict -Mwarnings -MDigest::MD5 -le \
  'print Digest::MD5->md5_hex("foo")'
3200a4cda22a4a935412da8113b4139b

To be honest I have no idea, why -w produces a warning (which is a good thing) and use warning doesn't.

PostgreSQL: TO_ASCII & UTF8

In the process of fixing our code for an upcoming upgrade of one database version for one of our $-projects I encountered a strange behaviour. Initiual situation:

  • we're moving from PostgreSQL 8.1.3 to the 8.3.5
  • we're moving from database encoding LATIN1 to UTF8
  • in our code we're using the TO_ASCII function a few times.

And this combination produces some headaches.

But first a gentle introduction to the TO_ASCII function. It converts any given text into it's ASCII representation. Folks bound to languages with german umlauts or some kind of apostrophes encounter many problems. For example: what should you do if you have to build some kind of index based on the first character of the lastname. Certainly you don't want to have an extra entry with 'Ü', instead you want to but them into the 'U' list. Grand entrance TO_ASCII:

 
SELECT to_ascii('Übermeier');
Ubermeier
 

Works like a charm. Caveat: TO_ASCII only supports LATIN1, LATIN2, LATIN9 and WIN1250 encodings but no UTF8.

Okay, the first guess would be to do something like this:

 
SELECT to_ascii(convert_to('Übermeier', 'latin1'));
ERROR:  FUNCTION to_ascii(bytea) does NOT exist
 

Bummer. CONVERT_TO returnes BYTEA, TO_ASCII only wants TEXT.

There has been some discussion going on on the pgsql.hackers mailinglist and frankly I can follow both parties in their point of view. But thanks to Pavel Stehule we have some kind of a hack to sidestep this issue:

 
CREATE FUNCTION to_ascii(bytea, name)
RETURNS text AS 'to_ascii_encname' LANGUAGE internal;
 

This version gladly accepts the BYTEA data returned by CONVERT_TO so we can just use it in this way:

 
SELECT to_ascii(convert_to('Übermeier', 'latin1'), 'latin1');
Ubermeier
 

Problem solved.

Therapieversuch

YouTube Preview Image

Wakka Chikka Wakka Chikka

Wakka Chikka Wakka Chikka - Cover 2004 schon wurde 'Wakka Chikka Wakka Chikka - Porn Music For The Masses Vol. 1' veroeffentlicht, und das unter der Creative Commons Lizenz. Sprich, man kann es sich direkt mal herunterladen ohne das einem der KGB holen kommt.

Nachdem ich in zwei der 17 Tracks kurz reingehoert habe und es durchaus Gefallpotential hat, linke ich das mal hier - vielleicht interessiert es ja einen der 2.5 Leser die ich hab auch.

Critical Mass 500+

Ich trau mich ja fast nichts mehr schreiben nach so langer Zeit, aber nachdem man vielleicht doch den einen oder anderen Hit weiterleiten kann... am Freitag ist es wohl so weit und ich schwinge mal meinen Hintern zum Wiener Critical Mass nachdem ich da schon mindestens drei Mal behauptet hab ich tus und dann doch der Schweinehund nicht zu ueberwinden war. Kollege Hekker hat auch gesagt er kommt und sogar Thomas will seinen Art Director Palast verlassen und mitrollen. Gibt sicher keine bessere Variante Yom Kippur einzuleuten als bei sowas mitzufahren (wenn das Wetter passt zu meiner Schande).

Was gibt es sonst neues? Dem Haxen geht es soweit gut, im Captain Ahab Mode bin ich trotzdem noch. Radfahren geht damit auch noch immer gut, den letzten Schmerz hatte ich wie ich Fussballtricks ala Yair ausprobiert habe - so Drehungen sind nach wie vor Aua.

Gleich nach dem Urlaub gabs eine Upgrade @ $ bei dem ich anwesend sein musste - bis halb zwei Morgens ging es - und das obwohl mir schon den ganzen Tag nach Niederlegen war. Was ich dann auch den Rest der Woche getan hab. Inkl. Schwindel, Kopfweh und dem grossen Ganzkoerperschmerz. Jetzt huste ich noch wie ein Kettenraucher und produziere Dinge in meiner Nase die lieber unausgesprochen bleiben. Jedenfalls hatte die Woche ein Gutes, ich hab mich schon wieder auf die Arbeit gefreut nach ein paar (bedingt durch noch mehr Feiertage unter der Woche) Tagen Einkasernierung.

Na ja - soweit so gut, jetzt gilt es halt nur den Archos samt Helmcam wieder auf Trab zu bringen und am Freitag nicht doch wieder umzukippen und sitzen zu bleiben... und Videoschnittsoftware auf'm Mac hab ich auch noch nicht </note to self>