Older blog entries for mathrick (starting at number 94)

Another day, another mishap

So. I wanted to get around the city and look for cheap bikes today. Instead, I got flat tyre and spent entire time I had allocated on first attempting to fix it, and then getting new one and changin it. Ghrr. Also, the laptop I’m using right now has danish keyboard, in small notebookish layout to that. And some genious invented having “Fn” key instead of Ctrl, and Ctrl slightly to the right. So I need to aim to the right when I want to hit Ctrl-Backspace, which often results in Alt-Backspace instead. Which for some reason means “delete everything” in IE (yeah, I’ll be installing FF ASAP here). So first half of this post has been already typed in 3 times. Yay for great ideas. Now I need to finish before I run out of battery juice, because I have the laptop, I have the power adaptor, but I don’t have cable to connect that adaptor to the mains :>


Hi there, from Denmark

Wow, an update. There haven’t been one in something like… 4 months? That means I had to delete several thousands of spam comments before doing anything :(. I need to finally update to WP 1.5, hopefully it’ll cope better with spam. Honestly, I’d like to just have my spamassasin but for blog, and a way to delete all the spam comments at once.

Anyway, I’m in Denmark now (been here since Thursday). Thanks to Socrates/Erasmus programme, I’m in Odense (take a look at the coordinates which should be somewhere close to this post :), as an exchange student. So far it’s very cool, if you have ever seen kids books illustrations of typical Danish town, there’s a news for you: it’s all true. The houses really look like they do on pics, most are small and very, hmm, cute. Also, the interior design seems to be universally good, you just don’t get to see badly arranged houses.

The city is all crazy about bikes, Odense being one of the biggest Danish towns is also the most bikified one. You can get by bike everywhere. And you have special bike lanes on every street, including roundabouts, which is something completely uncommon in Poland. That’s the part I really like about it, although I still don’t have a bike on my own (I will be going to town to look for a bike tomorrow). What totally beat me was young woman, with two small kids, doing quite significant shopping, and then riding home by bike. Turns out that with a basket, kids seat and a trailer you can do it.

There’s still a lot to do before the term starts, good thing my “buddy” (the person you get assigned to help you get around in the city when you arrive, sort out the paperwork, etc.) is a very nice guy, and extremely helpful. Thanks to him, I have a bike before I get my own, same thing with a computer (I don’t have a laptop, and couldn’t really take my desktop with me here).

One very noticable thing (besides everyone speaking Danish) is that you can get away with English almost anywhere. Even the old ladies walking with dogs will tell you you don’t need to be afraid in English once they notice you don’t understand Danish :>. Another is that Danes really like their Danebrog, there’s a good chance to see a flag on every street, and about every other shop is called “Dansk something” (the rest is called “Fynsomething”, Fyn being the name of island Odense is situated on). Quite similar to Americans and their love of Stars & Stripes, I think.

That’s enough for today, I need to get up early tomorrow and look around the city for a cheap bike.


25 Nov 2007 (updated 5 Dec 2007 at 13:53 UTC) »
More useful bash prompt

Working on a project with a rather deep directory hierarchy, I finally got tired of my prompt overflowing the line and wrapping around. So, here’s a handy <code>bash</code> function to put in your <code>$PS1</code>. It should be noted that I did not write it, I only wrapped it up in a function and added some aesthetic options, but all the hard work and <code>bash</code> hackery was done by BearPerson from <code>#bash</code>.

# Produces the same effect as \w in $PS1, but makes sure that the
# result length doesn't exceed $1 chars. If any dirs are omitted, they
# are replaced with [...]. Optional $2 turns on ANSI VT100 escape
# sequences to dim the [...] part. Optional $3 specifies the colour
# code to dim to (otherwise 02, "dim")
bound_pwd ()

    pre=$([ $ansi ] && echo -n "\[\033[${colour}m\]")
    suf=$([ $ansi ] && echo -n "\[\033[0m\]")

    [[ $CANDIDATE =~ $regex ]]

    echo $CANDIDATE

To use it, either put it in your <code>.bashrc</code>, or in a file that is sourced by <code>.bashrc</code>, then replace <code>\w</code> in your <code>$PS1</code> with <code>$(bound_pwd)</code>. Personally I use <code>$(bound_pwd 25 1)</code> to get at most 25 chars, with VT100 colour codes.

Obligatory screenshot:

Bash prompt with the shortening

<s>Update: If you use VT100 colours, remember to surround the <code>bound_pwd</code> invocation with <code>\[ \]</code>, otherwise non-printing characters will confuse <code>bash</code> and make it wrap lines incorrectly</s>

Update 2: The above update was wrong. It’s actually more complex than that, and due to the fact that <code>bash</code> doesn’t exactly have coherent escaping semantics, I had to rework the function. If you use VT100 colours and have downloaded an earlier version of bound_pwd, you have to download it again, it has changed. Additionally, to have it really work, you have to add this function:

set_ps1 ()
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:'"$(bound_pwd 25 1)"'$ '

And in <code>.bashrc</code>, add this:

# Yes, it's silly that ; alone is not valid syntax

Make sure it’s the last line to set <code>PROMPT_COMMAND</code>. Especially if you’re on Debian/Ubuntu, as their default <code>.bashrc</code> sets it conditionally.


13 Nov 2007 (updated 14 Nov 2007 at 22:22 UTC) »
Routing complete Apache traffic to a CGI handler

Following up on my CGI-Lisp work, here’s a short recipe on how to route the entire Apache traffic to a CGI handler. This is not trivial because of a few problems that need solving:

  1. <code>mod_actions</code> will fall into infinite loop if you try to associate a handler with <code><Location /></code> (as will <code>mod_rewrite</code> if you attempt to rewrite <code>/.*</code>)
  2. <code>mod_rewrite</code> will not execute CGI scripts by default
  3. <code>mod_rewrite</code> only serves physical paths under <code>DocumentRoot</code> (and it’s good practice not to have <code>/cgi-bin/</code> under DocumentRoot)

These can be all solved, but require some searching and reading into the meaning of various options, so I’m posting a ready solution here:

<VirtualHost *:80>
    DocumentRoot /var/www/

    RewriteEngine On
    # PT means "passthrough" and will allow mod_rewritten URLs to be matched by
    # virtual locations, not just physical paths
    # T= specifies mime-type to ensure the CGI handler will be executed
    # sock.cgi is the handler we want to handle the entire traffic
    RewriteRule ^/(.*) /cgi-bin/sock.cgi/$1 [PT,T=application/x-httpd-cgi]

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        #Add whatever options you normally use for your /cgi-bin/
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

As an added bonus, it seems that the <code>REQUEST_URI</code> sent is the URL before rewriting, so you don’t have to do anything special to filter out <code>/cgi-bin/sock.cgi</code> from it.


12 Nov 2007 (updated 14 Nov 2007 at 22:23 UTC) »
CGI-Lisp 0.5

Following the best agile methodologies, with rapid turnaround, short deliverables, tight customer feedback loop and probably something else involving “leveraging” and “assets”, <s>I’m</s> we’re proud to announce CGI-Lisp 0.5, the latest incarnation of the market-leading, award-winning product in the mod_lisp-compatible CGI-to-Lisp bridges space.

I call it 0.5 because I think it pretty much complete, but not enough to insist there are no bugs to be fixed or additions to be made.

Highlight of changes:

  • POST now considered working. I haven’t actually done anything to make it so, but I tested it and mapped enough variables to have it actually useful (and it turns out to be working out of the box otherwise).
  • Much more complete mappings. It should have most of the variables anyone cares about now.
  • Tested a bit more. And by tested I mean “played with several Hunchentoot applications and found them not breaking horribly”.


10 Nov 2007 (updated 14 Nov 2007 at 22:23 UTC) »

I’m happy to announce the first release of CGI-Lisp. It’s a small hack that allows you to trampoline webserver requests into a long-running Lisp process, just like mod_lisp (and using the same protocol), except that it runs as a CGI handler. So you can run it on shared hosting.

The code was stolen from Rob Warnock, who hacked it years ago. I in turn hacked it into speaking unmodified mod_lisp, which allows it to be used as a drop-in replacement:

CGI-Lisp screenshot

It’s been extensively tested by running it on exactly one machine in exactly one scenario. That means it will quite possibly break for you. If you still ain’t scared, grab the tarball here.

Update: so yes, I realise you hate GLib and can’t install it on your server. Debugging it was sufficiently annoying, though, for me not to be willing to put up with the sorry excuse for string handling of plain C. And I don’t think it will be very useful without handling POST anyway. I will probably fix that later on, but I don’t have the time now.

Update 2: I rewrote it not to require GLib. It’s slightly slower than before, but not much, and it’s good enough for me. POST non-handling still needs fixing though. You can grab the updated version from the same place.


29 Oct 2007 (updated 5 Dec 2007 at 20:48 UTC) »
Everything you (never) wanted to know about C++

Ladies and gentlemen, the C++ FQA Lite!

If you hate C++, you’ll have a great time reading this brilliant and amusing rant that rings just so true. Occasionally you’ll weep when it rings a little bit too true, invoking painful memories.

If you love C++, it’s a big flaming rant, but written with technical competence that easily shadows everything else out there that’s been written on the subject. You can’t claim any knowledge of C++ without having read it. And chances are that it’ll make you not love that sin against all good and just before it’s too late. Just think about it, the author is still trapped inside the warped world of C++, dealing with errors that have defeated everyone else on his team. The FQA is really a desperate cry from inside the asylum for you to stop while you still can. Think about it, you’ll be endlessly happier if you do.

If you don’t care about C++… Well, lucky you. But if you know someone who likes C++ more than they should (that is to say, at all), consider doing them a favour and pointing them to the FQA. Friends don’t let friends use C++.


28 Jan 2007 (updated 28 Jan 2007 at 15:22 UTC) »
Im in ur specs, synergistically leveragin ur award-winnin opportunities

Quiz time: Guess what it is about?

The Hardware Start Button, (…), is designed to be an attractive and discoverable actuator for launching the new Start menu and search experiences in the Windows Vista family of operating systems. The Hardware Start Button creates and deepens affinity between physical hardware and the Windows Vista user experience while complementing the brand platforms and product design languages of hardware manufacturers.

If you guessed "the Windows key" (found on just about every keyboard manufactured after 1996), then you're right. And this ridiculous paragraph is the intro to a spec detailing such exciting aspects as what paint to use, or how polished the key surface can be.

 More gems:

<u>What’s new in Version 1.01?</u>

Conventional Keycap Design Requirements (page 7)A matte finish with a consistent texture of MT11000 or equivalent may be used on the Hardware Start Button dome and chamfer instead of an SPI A2 gloss finish for an indefinite period of time, not until December 31, 2007 as the Version 1.0 specification stated.

The Hero Start Button functions as a Start Button just like the other implementations in this specification. It is not required and is provided as an option for keyboard manufactures that want to take advantage of its more dramatic look.

And what is this "more dramatic look"?

Larger size, clear dome, and full-color printing and placement on the keyboard. The Hero Start Button uses a lens insert and is placed directly below the space bar.

If you feel brave, read for yourself.

In other news, OpenOffice.org is a steaming pile of shit that leverages every fucking opportunity to fucking crash every fucking minute and present you with a completely useless and retarded recovery dialogue even though I never changed a single character in that document.


23 Oct 2006 (updated 23 Oct 2006 at 19:10 UTC) »



Inkscape is nice. The above is a quick trace of a photo, because flexible image resolution adjustment was needed (and doesn't have anything to do with the Linux distro).

On the other hand, the original SVG (linked to if you click on the image) shows how little parity is there between freely available SVG implementations. Inkscape displays it correctly (obviously), librsvg does a rather nice job, but can't display masked objects at all (there is a slight gradient on the brim which is masked), and FF simply butchers the image, unable to display something as simple as a gradient correctly. 

As Ankh says, it's not good when the only widely-available, decent SVG viewer is Adobe plugin inside IE. 


7 Oct 2006 (updated 8 Oct 2006 at 22:49 UTC) »
<This title contains mature language. For your protection, it has been withheld>

"This address uses a network port which is normally used for purposes other than web browsing. Firefox has cancelled the request for your protection"

 Dear Mozilla,

 You guys are fucking idiots.


 Update: okay, so I checked, and that's a legitimate security issue, known as cross-protocol attacks. Or rather it would be, if it wasn't for the fact that a user-entered URL cannot usefully be a source of such attack. And there's a bug dating back to 2001 stating "Add user UI for that". Still lame and just as enraging when I have to use another browser for one stupid address.


85 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!