Being directly involved with two open source projects, Gallery and Habari, I sometimes get to witness some rather esoteric problem solving. I would never call myself a great developer,
probably not a developer at all, but sometimes people present code that just leaves me wondering if some people come from other planets.
Most of the time this involves some rather heavy regexp trickery like the one below:
/(translate|i18n)\(\s*(((\s*\.\s*)?
('((\\')?[^']*)*[^\\]'|"((\\")?[^"]*)*[^\\]"))*)\s*\)/s
Thats from some kind of language related code in Gallery 2, at least it was in 2004 when the quote is from, that Alan Harder created an insane Regular Expression statement for.
I can't even begin to try and understand what it matches and I'm pretty sure my head would
explode if I did. For some reason regexp seems to constantly elude me.
My other example is more current and from the #habari irc channel. A recent code commit in the svn trunk caused this site to bail out with a sql related issue.
Thanks to Jay Pipes it was a fairly easy fix, involving some simple SQL statements:
CREATE TEMPORARY TABLE dup_slugs SELECT tag_slug, COUNT(*) FROM habari__tags GROUP BY tag_slug HAVING COUNT(*) > 1; SET @row_count:= 1; UPDATE habari__tags INNER JOIN dup_slugs ON habari__tags.tag_slug = dup_slugs.tag_slug SET habari__tags.tag_slug = CONCAT(habari__tags.tag_slug, (@row_count:= @row_count + 1));
I still can't read that properly, but it did indeed fix the problem I had with a recent change to the tags table in Habari resulting in duplicate tags. Or something similar.
My only conclusion is, good developers are in fact aliens. No doubt about it.
3 Comments so far
Jesse Mullan, on May 21, 2008 at 10:47pm, said:
Oh! The first one is to find all the translatable strings in the various php files of Gallery2. It has since been replaced by php's internal tokenizer (which is a sensible move because that original regex is horrific).
Edit Comment
h0bbel, on May 21, 2008 at 10:56pm, said:
@Jesse Mullan: I remember now, and I know it isn't used anymore but it's a prime example of the point in my post. Developers are strange creatures whose brains certainly works in ways that in many cases completely amazes me.
Edit Comment
Caius Durling, on May 27, 2008 at 11:07am, said:
http://rubular.com/ is a rather cool tool if you have problems with regexs and need a quick & easy way to test them =)
Edit Comment