scotfl.ca

Jan 2010 Apple Event Prediction Score Card

yes no yes no yes yes
no yes no yes yes yes no yes yes no no yes
no yes yes no no no no sadly-no no no yes yes no no
no no no no no

Personally, I’m hoping Apple reaches back in time, naming-wise: Apple Macintosh Tablis 4220. With different CPU/storage combinations as the 4225, 4235, and 4250.

Key

Posted on 25 January 2010 in uncategorized

1 Comment »

PHP 5.3: Now With 40% Less Ugh!

C’est functional programming:

array_walk($line, function (&$i) { $i = trim($i); });

Or, at least, close enough. Either way, a vast improvement over the old method.

Also nifty: the ternary shortcut: ($a ?: $b) is just like ($a ? $a : $b), but without the double evaluation.

It’s a nice little update.

Posted on 27 September 2009 in uncategorized

Comments Off

Of Slugs and Permalinks and PHP Redux

Around three years ago I posted a simple slugification function that used iconv() to coerce a string into URL-friendly ASCII. It had a couple of drawbacks in that it dropped characters rather than transliterating them (oops) and it fell flat on its face if iconv() wasn’t available.

Thus, I present here an improved version.

/**
    Clean up a string and make it suitable for inclusion in a url.


    @param $str The (UTF-8) string to be slugified

    @return a string containing a sanitized, url-safe version of $str
*/
function slugify ($str)
{
    if (function_exists('iconv')) {
        $old_level = error_reporting(0);
        $old_locale = set_locale(LC_ALL, '0');
        setlocale(LC_ALL, 'en_US.UTF-8');
        $slug = iconv('UTF-8', 'UTF-8//IGNORE', $str);
        $slug = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $slug);
        set_locale(LC_ALL, $old_locale);
        error_reporting($old_level);
    } else {
        $slug = preg_replace('/\s+/', ' ', $str);
        $slug = preg_replace("/[^a-z0-9 ]/i", "", $slug);
    }
    $slug = preg_replace('/\W+/', ' ', $slug);
    $slug = trim($slug);
    $slug = strtolower($slug);
    $slug = preg_replace('/\ +/', '-', $slug);

    return $slug;
}

The basic mechanism is to take a string, remove non-ASCII characters, strip punctuation, collapse whitespace and replace it with hyphens. Which will (ideally) turn “I lìke: Icé Crëam!” into “i-like-ice-cream”.

The non-iconv() path doesn’t quite live up to that goal. It collapses white space and then strip anything that isn’t an alphanumeric ASCII character or ASCII space. This means it turns the previous example into “I lke Ic Cram”. I’m not too worried about that as it’s intended solely as a fallback. I added it because had a development machine without iconv() and a server with it, and didn’t want to waste time installing it on the development machine at that moment.

The iconv() path is much nicer, and I’ll take it step by step. First error reporting is disabled because iconv() loves to spew errors even when everything is operating as expected. The old reporting level is recorded so that it can be restored once iconv() is done spewing errors. Next the current locale is set to a UTF-8 value. The function assumes its input is UTF-8 and this ensures iconv()’s transliteration works properly. As with the error level, the current locale is recorded for later restoration.

Now comes the heart of the function, in which the input string is first stripped of invalid UTF-8 byte sequences (just in case $str is composed of random gibberish), then bounced down from UTF-8 to ASCII. It’s the second iconv() call, with the ‘TRANSLIT’ command, that makes up the real magic, transliterating accented character into non-accented versions. That is, it turns “ß” into “ss” and “é” into “e”. Unfortunately it doesn’t do much for non-European scripts, merely converting the characters into question marks. At this point the example has been transformed into “I like: Ice Cream!”.

After the string has been converted, the error reporting level and locale are restored.

The remainder of the function is the same for both paths from this point. All runs of non-word characters (i.e., whitespace, control characters, punctuation) are replaced with spaces (I like Ice Cream ). Then leading and trailing whitespace is stripped (I like Ice Cream), and the string is lowercased (i like ice cream). Finally, the remaining runs of whitespace are replaced by hyphens (i-like-ice-cream or i-lke-ic-cram for the non-iconv() path) and the string is returned to the caller.

My original function was adapted from an early version of Rick Olsen’s permalink_fu.rb but there has been significant divergence since.

Posted on 17 September 2009 in uncategorized

Comments Off

Programming (And Markup) Languages I’ve Learned

Grabbing a meme from Glyph, here’s my list in rough chronological order:

The boldface entries are languages I consider myself proficient in. And Pascal, as always, remains very near and dear to my heart.

Languages I intend to learn in the near future:

Edit: Forgot about NewtonScript!

Posted on 15 October 2008 in uncategorized

Comments Off

BBEdit Lite

Since Bare Bones seems to have eliminated the legacy versions from their servers, it took me a few hours to scrape copies together from other sources. So I thought I’d share my findings with the world. Just in case anyone else needs a good text editor for an old System 6 machine…

For Mac OS X 10.3.5 and better, BBEdit’s current free text editor TextWrangler is the better choice. At least until Bare Bones deems it discontinued and unsupported, at which point the lack of a redistribution clause in its license is going to hurt.

While I’m on the topic of ancient software, I might as well point out that NoLobe has full collection of Anarchie versions available (appropriately enough) on their File Transfer Protocol server. And, likewise, iCab is available for every system all the way back to Mac OS 7.5.5.

Edit: fixed link to 6.1.2

Posted on 12 October 2008 in uncategorized

Comments Off

Stallman and Negroponte

In my values, freedom is more important than “serving users” in a mere practical sense. Of course, in many cases we can achieve both, so we do not need to choose between them. But once in a while that isn’t so. — Richard Stallman, 2000 (source)

That is my favourite Richard Stallman quote because it, to my mind, perfectly encapsulates why he is largely irrelevant to day-to-day software development. If I want to write a document I will choose and suggest Microsoft Word over a GPL-licensed Hello World program. I suppose that makes me philosophically unclean to the Free Software community, but I can’t shake the idea that the only reason software exists is to serve users in a mere, practical sense.

I view Nicholas Negroponte in much the same way, though Negroponte’s philosophical contribution is as a futurist, rather than an ethicist. I think “Being Digital” was what cemented Negroponte in that role for me.

Do not misunderstand me, both Negroponte and Stallman have immense value to the software industry. Without people publishing proclamations and nailing manifestos to doors nothing truly innovative, and thus nothing better, ever happens. The MIT Media Lab, emacs, the OLPC, and the GNU Project all represent huge contributions to the state of the art. Both in their practical effects and in the fainter ripples of opinion and thought they cause.

Today, it was with little surprise that I read Ivan Krstić’s insider view of the OLPC project. And it was with even less surprise that I read RMS’s response to the news of the OLPC switching to Windows.

Respect these men, value their contributions, and give serious thought to their ideas. But when it’s time to actually write code, concentrate on what you can do for users today.

Posted on 14 May 2008 in uncategorized

Comments Off