Archive for the ‘PHP’ Category

PHP is now less crappy than Java

Wednesday, July 23rd, 2008

And by “is less crappy than Java”, I mean “has closures”.

The syntax goes thus:

function fun() {
    $a = 1;
    $b = 2;
 
    // variables being closed around need to be
    // explicitly specified:
    $closure = function() use($a) {
        // prints 1
        echo $a;
        // prints nothing (outer $b isn't in use)
        echo $b;
        // no effect outside $closure (outer $a not used as reference)
        ++$a;
    }
 
    //prints 1
    echo $a;
 
    $closure2 = function() use(&$a) { ++$a; }
    $closure2();
    // prints 2
    echo $a;
 
    // still prints 1 because $a was copied in the declaration
    // which is a bit of a wtf, but better than create_function
    $closure();
}

Now how long until PHP 5.3 is anything like widespread? I’m guessing three years or so.

Charts! For vowels!

Tuesday, October 16th, 2007

Contrary to (my) assumptions, I actually wrote a program to draw the vowel diagrams like on the IPA chart, instead of the normal “I will! Honest! But later”. Apart from being used to show which symbol means what, the IPA Handbook also uses them to show more accurately what the vowels actually are. This is the intended use of this program, of course, because otherwise you might as well have an image.

(more…)

MimeTeX for those without CGI

Tuesday, October 16th, 2007

For some reason CGI doesn’t work on this server at all. Trying to run things just ends up with the program itself being served, rather than its output. (Yes, I have the executable bit set.) This means that MimeTeX, which is a CGI program written in C, doesn’t work at all.

Of course, this doesn’t really matter since they have a public server, http://www.forkosh.dreamhost.com/mimetex.cgi, which apparently anyone and everyone can use. Of course I feel a little guilty leeching off their site like that even if Adrað’s bandwidth is pretty negligible, so I hacked together a filter for fauxML that uses their server once and saves the result locally. I’ve put the result here so anyone on the other end of a Google search or whatever can save a few minutes’ hassle by copypasting it.

(more…)