Spacing out CamelCase in PHP

27 May 2009

Here’s a nifty function to put spaces in your CamelCased words:

function spacify($camel, $glue = ' ') {
    return $camel[0] . substr(implode($glue, array_map('implode', array_chunk(preg_split('/([A-Z])/',
        ucfirst($camel), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE), 2))), 1);
}

echo spacify('CamelCaseWords'); // 'Camel Case Words'

I added in the $glue parameter to be even more nifty, but a bit of thinking made it clear that it wouldn’t work when the first letter was lower-case. Should be fine now!

2B or not 2B

18 May 2009

…that is the question. The answer? FF.

Paying the Price for Bad Grammar

10 April 2009

This is why we need Grammar Nazis:

Today, I was flirting via text with a coworker. Things started getting heated, and I wanted to send her a sexy picture. I asked if she had any suggestions. She said, “Your nuts!” She meant, “YOU’RE nuts.” I sent her a photo of my junk. I offended a co-worker with incriminating evidence. FML

blizzard_of_77 on FMyLife


Ahh, grammar…

Things I Learnt Today

30 March 2009

  1. That Ben “Yahtzee” Croshaw is a goon;
  2. that his early stuff is, if anything, funnier than his paid stuff for The Escapist;
  3. that I there will always be something on the Internet that I haven’t seen, and that someone will think I have been living under a rock to have missed it.

Get a Grid for Transparent Images in Firefox

17 February 2009

Here’s a useful bit of Firefox hackery for you all. It puts a checkerboard (or chequerboard, for you elitists) image as the background for your transparent images. It works for any image when viewed directly in Firefox, by checking for a HTML page containing a single img tag. If you reproduce this structure manually, then you’ll see the checkerboard, but there’s very little chance that a legitimate HTML page would match these selectors. It works by adding some content to your userContent.css:

  1. Lifehacker has a guide to finding your userChrome.css file — your userContent.css resides in the same folder.
  2. You may not have a userContent.css file; if not, you should create it. In some instances you may have a userContent-example.css file, which you can rename to get the idea of what goes in this file.
  3. Open the file and insert the following CSS:

    /*
     * Image from http://commons.wikimedia.org/wiki/File:Checker-16x16.png
     * Avoided hotlinking per http://commons.wikimedia.org/wiki/Commons:Reusing_content_outside_Wikimedia#Hotlinking
     */
    html > body > img:only-child {
    	background: url('http://starsquare.co.uk/images/checkerboard') repeat;
    }
    
    html > body > img:only-child:hover {
    	background: none;
    }
    

    With the above CSS, viewing an image directly displays the checkerboard at all times, unless you hover over the image, in which case it reverts back to show the normal image. If you want it the other way round, so the checkerboard only shows when you hover over the image, insert the following CSS:

    /*
     * Image from http://commons.wikimedia.org/wiki/File:Checker-16x16.png
     * Avoided hotlinking per http://commons.wikimedia.org/wiki/Commons:Reusing_content_outside_Wikimedia#Hotlinking
     */
    html > body > img:only-child:hover {
    	background: url('http://starsquare.co.uk/images/checkerboard') repeat;
    }
    
  4. Save the file. If you had Firefox open, you should restart your browser. If not, simply start it up.
  5. Find an image that contains transparency and open it in your browser; a good example is this image.
  6. Pretend you’re in your favourite image editor!
I removed the body:only-child selector, since nightly builds of Minefield include a head tag to specify the page title.

A Message to Tinchy Strider

30 January 2009

It’s misled. I don’t care if you made it up to rhyme with mistreated, or if you use an 8-bit–style riff to appeal to my geekiness — The word is misled. That is all.

Yay, xkcd

17 October 2008

Makefile:
me:
	@true
a:
	@true
sandwich.:
	@[ -w /etc/shadow ] && echo "Okay." || echo "What? Make it yourself."

Shell:
$ make me a sandwich.
What? Make it yourself.

$ sudo make me a sandwich.
Okay.

From CLI-Apps. See also xkcd.

Spotting a Fake Pound Coin

24 September 2008

Supposedly 2% of all pound coins are counterfeit. But how do you know when you have a fake? I heard the news item and had a quick look at the pound coins in my pocket, and couldn’t see anything. I thought that maybe it wasn’t all that easy to spot. But then I saw one my Mum had:

Obverse — the fake is on the left. Notice the lack of detail on the crown and hair, and general fuzziness of the image and lettering Reverse — again, the fake is on the left. The difference is even clearer on this side. Side — the fake is at the top. The lettering around the side is incomplete and off-centre. It is also the wrong way up, but this doesn’t seem to be standard.

There are a few noticeable differences:

  • The lettering and images are faded
  • The images have less fine detail
  • They may not pass the “spin test” (although mine did) — the obverse image is not in the same orientation as the reverse image
  • The lettering on the side is incomplete or off-centre
  • The side inscription and obverse or reverse image may not match the supposed year of print (although, again, this one did)
  • The material of the coin may feel different — this one felt less dense than the real one; gold paint may also flake off
  • A vending machine will probably not accept it
There are other things that you can do beyond just looking at it, such as weighing it on some very accurate scales, or testing the resistivity.

One thing that doesn’t prove it’s fake, however, is the orientation of the lettering on the side. All my pound coins (except the fake) have the obverse facing upwards when reading the lettering, but I’ve seen other coins where it’s the other way around. There’s a three-part post over at Blogalism that goes into more detail, and in one of the comments explains that the coins fall from the face-stamping machine into the edge-inscription machine, giving it a 50% chance of appearing either way up. More information is available on the old WBCC page.

Leeds Festival 2008

25 August 2008

I’m still tired even a whole day after getting back, but I though it was worth it to mention how good the festival was, yet again!

I didn’t get a ticket immediately after last year, but waited until March. With hindsight, I reckon an early bird ticket might be required from now on, as it was even busier than last year! I even missed out on the brie and crackers…

Again, my list of bands includes a couple of bands for whom we only saw the odd song:

Friday Saturday Sunday
Metallica
Pendulum
Avenged Sevenfold
Dropkick Murphys
Plain White T’s
Alexisonfire
Mindless Self Indulgence
Eureka Machines
Babyshambles
Rage Against The Machine
Vampire Weekend
Goldfinger
Friendly Fires
Biffy Clyro
Serj Tankian
Dizzee Rascal
Taking Back Sunday
The Killers
Bloc Party
You Me At Six
The Raconteurs
Seasick Steve
Hifi Handgrenades
The Automatic
Random Hand

Again, I felt like I missed a load, but with so many on at the same time it’s impossible to get it all in! Thanks go out to Rob Marshall for his clash finder, which helped out greatly!

View pictures of the festival

Radovan Karadžić’s Disguise

24 July 2008

Radovan Karadžić, the recently captured war criminal, was doing a good job disguising himself as Noel Sharkey:

Noel Sharkey Radovan Karadžić
Er, I can’t remember which is which now.