Word Clock v2

8 November 2009

I’ve seen a few nice-looking representations of clocks around, but when I saw Gumuz’s word clock I though I could make some improvements to it. Here’s a couple of the changes:

  • Rewrote using MooTools (only because I know it better, I’m currently developing in it, and it gave me a chance to play with Google’s JS API)
  • Rewrote some of the JavaScript logic to be a bit tidier
  • Replaced the letters with dots for an arguably prettier output
  • Reordered the hours in the HTML so that “twelve o’clock” wouldn’t be missing the space (I had to combine two and one for this)
  • Highlighted the a in half for quarter-past and quarter-to, as per mattatwhoosh’s suggestion
The result is tested in IE (5.5–8), Safari, Chrome and Firefox. I hit a slight issue in IE6− (what a surprise) whereby it interprets a.sec.lit as a.lit (example); I got around it by making sec an ID rather than a class (yes, I know it’s dirty).

Have a look for yourself.

Mootools Hash.setFromPath

23 October 2009

MooTools More implements a getFromPath method in Hash.Extras, but doesn’t provide a corresponding setter. Here’s an implementation:

Hash.implement({
    setFromPath: function(path, value) {
        var source = this;
        var prop = '';

        path.replace(/\[([^\]]+)\]|\.([^.[]+)|[^[.]+/g, function(match) {
            if (!source) return;
            prop = arguments[2] || arguments[1] || arguments[0];

            if (!(prop in source)) source[prop] = {};
            lastSource = source;
            source = source[prop];
            return match;
        });

        lastSource[prop] = value;
        return this;
    }
});

Just to explain the lastSource part, it’s a fudge to maintain object references throughout.

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.

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?oldid=19631383
     */
    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?oldid=19631383
     */
    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.

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.

Firefox 3 World Record

30 May 2008

The Firefox team are going for a new world record — “Most Software Downloaded in 24 Hours.” The (currently beta) version 3 of their popular web browser is due to be launched in late June. Visit the Download Day 2008 page for the official date, and to make your pledge!

Dell & Linux

7 April 2008

I was never a big fan of Dell, mainly because it really annoyed me that they only shipped Windows with their machines. Reading The Microsoft File made it clearer, if no more acceptable; Microsoft bullied retailers to shipping tied processor–product bundles, effectively forcing other operating systems out of the market.

Dell redeemed themselves in my eyes when they announced that they would be offering Linux as an alternative, but it seems that’s not the whole story. To summarise the summary, it would appear that every time Dell offers some kind of alternative to Windows, there’s always something that means the Windows users get preferential treatment over everyone else… Now that doesn’t seem fair, does it?

Samba and Vista

4 February 2008

Vista’s lock-down strikes again…

In short, we have Samba v2.2.7a running here, and a new machine was just added running Vista, for some reason. It wouldn’t connect to our Samba shares, where my XP box had managed absolutely fine. The culprit? Vista’s security policies. Finally we found the fix:

  1. Open the Run command and type “secpol.msc”. Finding the Run command in Vista is fun in itself; we just used Windows Key + R.
  2. In the security policies dialogue, navigate to “Local Policies/Security Options”.
  3. Open the policy “Network Security: LAN Manager authentication level”.
  4. Change the option to “LM and NTLM — use NTLMv2 session security if negotiated”. Pre-3.0 Samba doesn’t support NTLMv2, hence the change from the default refusal.
Then, cry because you’ve “updated” to your shiny new operating system and you now have to search Google for “getting x to work in Vista” every time you want to install an application…