Due to working with Drupal for most of this year, I’ve seen this construct so many times it’s killed me a little inside:

switch($a) {
    case TRUE:
        switch($b) {
            case TRUE:
                break;
            case FALSE:
                break;
        }
        break;
    case FALSE:
        switch($b) {
            case TRUE:
                break;
            case FALSE:
                break;
        }
        break;
}

Someone I work with, who wishes to keep his name off the net, came up with this:

switch(array($a, $b)) {
    case array(false, false):
        break;
    case array(false, true):
        break;
    case array(true, false):
        break;
    case array(true, true):
        break;
}

I’d rather avoid the need for nested switches altogether, but this construct makes it easy to collapse similar branches, and is, I think, a useful addition to my toolkit:

switch(array($a,$b)) {
    case array(true, true):
        break;
    case array(false, false):
    case array(false, true):
    case array(true, false):
    default:
        break;
}

It’s worth mentioning that arrays are compared for equality (==) rather than identicality (===).

Boston Library Yale Safe by rpongsaj

Boston Library Yale Safe by rpongsaj

A couple of years ago I had to open a personal/hotel-room style safe without a key. I contacted the manufacturer, thinking that just maybe, given a serial number, they could supply a new key. Instead I got complete instructions for breaking into their safes. Yay security!

I’m not sure which is dumber – that it’s so simple to open, or that they give “defeat-our-product” howtos to anyone who asks. Anyway:

[instructions removed at nutool's request]

Slipper, heading for the table

Slipper, heading for the table

A fragment of PHP that really shouldn’t work. I hope nobody ever finds a use for this:

switch($n)
{
    case 1;
        echo 'one';
        break;
    case 2;
        echo 'two';
        break;
    case 3;
        echo 'three';
        break;
}

Hi
Can anyone help me handel this URL injection ?
https://www.xxx.co.uk/register.php"| grep "123"
I want to detect it and header back to my index page.
It's quite urgent
Thanks for help

Heh. Poor guy.

I was poking around in Google Maps tonight, and discovered that the “Link” button contains a reference to the last map you looked at, as well as the current one.

Steps to replicate:

Go to http://maps.google.co.uk/ and search for “Birmingham”

Now search for “London”

Click “Link”. The link should look something like this:

http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=London&sll=52.487798,-1.893768&sspn=0.262996,0.617981&ie=UTF8&ll=51.510452,-0.126343&spn=0.537601,1.235962&z=10&iwloc=A

If you snip out the sll attribute (52.487798,-1.893768) and feed it back into Maps, you’ll find it’s the lat/long for Birmingham, not London. I think it’s intentional, because the ll attribute points to London. I can’t see any obvious use for the sll attribute, though – there doesn’t appear to be a back button or history tool on the target page.

Not a big deal, but it could conceivably be an embarrassment to someone, some day.

Check this out:

if (isset($a, $b, $c))
{
    unset($a, $b, $c);
}

Mulitple arguments. Looks like they’ve been there since an early PHP4 release, at least. Why does nobody tell me these things?

The problem:

If you include() or require() files with relative paths, APC will search the include_path on every request, and you won’t gain the full benefit of turning apc.stat off.

Using absolute paths portably in your own code is easy – just use a constant, eg. “require APP_PATH . ‘file.php’;”. External libraries, however, are harder to deal with – you either accept the performance hit, or go through them adding constants by hand (and merging your changes every time there’s a new release).

The solution:

This script rewrites PHP scripts, turning relative paths into absolute paths, allowing you to deploy third party libraries within your build process and still take full advantage of APC.

Some caveats:

It reads from stdin and writes to stdout.

It relies on it’s own include_path; in the real world, you’ll probably want to pass that in on the command line.

It only deals with the most common subset of include statements (variations on T_INCLUDE, T_CONSTANT_ENCAPSED_STRING, T_SEMICOLON).

The Windows support is a bit wing-and-a-prayer.

It’s memory-greedy when dealing with very large files.

It doesn’t play 100% nicely with safe_mode_include_dir.

Thrown out there in the hope it will be useful to someone. I’d be delighted to accept any feedback or additions anyone wants to offer.

Mauve Internet over in Chichester is growing, and is looking for a Junior Python Developer. If you know anyone who might be interested, please forward the link to them.

Quick Link

Matt Jones on the advantages of “Good Enough” in location-based services. (via)

I think lifestreaming might have something to learn from this approach.

« Older entries