The MacBook Pro’s not so bad…

Two years after moaning about my MacBook Pro I figure it’s time for an update:

It’s not so bad…

Thanks to various blog comments I managed to solve most of the niggles I had with the laptop:

muted the startup sound
This was pretty straight forward: download StartupSound.prefPane and choose the appropriate settings (I ticked the “Mute” box next to “Startup Volume” which seems to work fine.)
reconfigured keyboard layout using Ukulele
(definitely a personal preference) I configured a keyboard layout to match UK PC keyboards: backtick (`) to the left of 1, hash# and tilde~ next to return, at@ and double-quote” reversed (double-quote via Shift+2) and finally (I think) putting backslash\ and pipe| to the left of Z) If you want it, you can download my British PC keyboard layout (if I remember right, you have to move the file into /System/Library/Keyboard Layouts/ and may need to restart before you can choose it in System Preferences / International / Input Menu – and if you want a decent icon you’ll need the flag icon to bung in the Keyboard Layouts folder too.)

There is still one rather annoying aspect of the keyboard layout: it changes back to a Mac layout whenever I use Opera and tab into a password field – god knows what that’s all about!? I’ve got used to it now though and can quickly change back with Apple+Space

Better sleep & hibernate
Apple must have distributed a software update including fixes so waking up from sleep became a lot faster and more reliable. I’ve been months without shutting my Mac down, though I’ve recently changed my power settings so it goes into stand-by if I close the lid while plugged in, but goes into deep sleep if I close the lid while running off battery. What I’d really like is a way to say “go into stand-by for 15 minutes, then go into deep-sleep” – I think that’d be better when you’re running of battery and carting your computer from room to room – but want it to go into deep-sleep if you hit the motorway for 2 hours.
Region-free DVD
Hackers are great. About 8 months on from writing my bitch-post someone pointed out some a forum thread pointing to new firmware. Upgrading the firmware and installing Region X means I can actually view DVDs I paid for… (Is that a “w00t!” I hear at the back?)

It’s nice to have been pointed to solutions by readers, but there were a couple of physical issues readers couldn’t fix: the position of the drive slot, and the crappy return key.

( I realise I’m only one of a million voices shouting in the wind, but) Apple have redesigned the new MacBook Pros to put the DVD slot where it should be (on the side) and they’ve added an option to let you specify a US keyboard when you order a Mac online (giving chunky Return and Shift keys, and proper labelling to say META, ALT and OPTION)

I need to test-drive the new chicklet keyboard before deciding whether I’d be happy using a new MacBook Pro, but with the US keyboard layout and another region-free DVD hack, I think I’d quite happily upgrade. Of course Apple have made some changes that put me off too:

  1. you have to pay more for a matte display (it used to be the other way round: glossy screens cost more, but designers prefer matte displays for better colour accuracy, so Apple made the most common and desirable option the one that costs a premium. That’s business!)
  2. unremovable battery. On some days that doesn’t sound so bad: the pro (long battery life) outweighs the con (high one-off replacement cost after 3-4 years.) But… I’ve been through the experience of defective batteries: my original MBP battery got burning hot and buckled over the course of a few months. I’d hate to think what would happen if the battery was wrapped around the PCB and pushing against all edges of a one-piece case.
  3. non-upgradeable memory. Well, kinda. This is a consequence of a non-removable battery – the option to upgrade from 4 to 8GB looks like it has to be done at the point of ordering, and for a hefty charge. Then again… 4GB of memory ought to be just fine, and (if it really comes down to it) I’m sure there’ll be a 32-step upgrade guide to replace the memory modules as soon as a memory supplier begins to sell them.

All in all, I’m pretty happy with my MacBook Pro these days. I get on better with OS X then Windows for a couple of reasons. I prefer Apple subtle nudge reminding you there’s a monthly / bi-monthly software update ready to install – compare that to Microsoft’s randomly timed “I’m gonna restart your computer in 5 minutes” auto-upgrade annoyance (and yes, I’m well aware of “net stop wuauserv” to stop the nagging – I can’t remember how many times I’ve had to type that in.) Plus, the BSD / *nix nature of OS X allows me to setup a development environment that behaves much closer to our live CentOS servers than Cygwin on Windows does.

I bought a Mac Mini last summer while rumours of a new revision were reaching fever pitch – I’m glad I didn’t wait. The Mini’s been an absolute pleasure – running damn-near silently and without issues. But that’s wandering off track.

I do have a new hate though: Sky HD. Compared to my recently deceased TiVo, SkyHD is one of the most incompetent PVRs I’ve ever had the displeasure of using. The only reason I haven’t cancelled my Sky subscription completely is because (as far as I know) there’s no other way to get Sky 1 – and I do like Lost, 24, Battlestar Gallactica and all the big American productions that come to Sky first…

And now I’m really off track. Sky HD’s a gripe for another day…

Posted in JavaScript

Concatenating arrays in PHP

Just a quick post so I know where to look the next time I forget how to concatenate arrays in PHP.

Use array_merge to concatenate two numerically-indexed arrays; not array_push and not the array union operator: +.

$first = array('doh', 'ray', 'me');
$second = array('fah', 'soh', 'lah', 'te', 'do');

echo "Union: ", var_export($first + $second, true), "\n";
echo "Merge: ", var_export(array_merge($first, $second), true), "\n";

// array_push returns int, not an array:
array_push($first, $second);
echo "Push: ", var_export($first, true), "\n";

The output:

Union: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'te',
  4 => 'do',
Merge: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'fah',
  4 => 'soh',
  5 => 'lah',
  6 => 'te',
  7 => 'do',
Push: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 
  array (
    0 => 'fah',
    1 => 'soh',
    2 => 'lah',
    3 => 'te',
    4 => 'do',
Posted in JavaScript

Refactoring vs Rewriting (preamble)

The say the path to recovery starts with admitting you have a problem.

I wish our problem was code-rot, or a simple case of a good design gone horribly wrong through bodged maintenance and hacks. (If only we’d managed to achieve such lofty goals to start with.)

Let’s just rephrase: the path to recovery starts with acceptance.

Think of this as an acceptance speech, or a first-time introduction at Incontinence Anonymous. “Hi. My name is Ash, and I’ve made a mess.”

I’m admitting to a problem (in public) because I want to move on. I want to get the feeling of acceptance, figure out the six-step plan to recovery, and start climbing out of this pile of manure one shitty handful at a time.

This is going to be public and painful, but I’ve checked with my partner and extracted a grumbling murmur to go ahead.

What are we talking about here?

We’ll be talking about our price comparison site: That’s the beast waiting for a handy dollop of TLC, or a lethal injection (I leave it to you to make your own call on that.)

The code-base is a nightmare. From tier-to-tier, front-to-back; a full blown living nightmare. Every day I sit down to code I debate whether to poke it a little more, or pronounce the code dead and rewrite the whole thing from scratch.

Not good.

More haste, less speed

For a two-man team, we managed to rack-up an impressive tally of mistakes very early on, starting with how we chose a language:

I was a Java aficionado, and my partner came from a Microsoft background. Neither of us wanted to cross-train – not out of loyalty or hate, but because neither platform seemed like the best way to get stuff out the door quickly.

Without ruminating obsessively, we decided scripting was the path to follow and quickly short-listed the three P’s (perl, python and PHP), ruby and lua. Python and Perl were quickly ruled out for the most immature reasons (the partner hates perl’s stereotypical punctuation-heavy style – and I hate python’s space-sensitivity.) A brief foray into installing Lua on OS X convinced me it was too unpopular and risky to use. With high hopes for Ruby (and Rails) that option quickly hit a wall too due to immense confusion and a complete absence of “mod_ruby” (I know, things have moved on.)

So we ended up with PHP. I think its important (to me) to realize we ended up with PHP by default, not on its merits. PHP, of all things. PHP with it’s “magic” methods. PHP with its retarded unicode support. PHP with its piss-poor objects.

In case you missed the subtle undertone there: I don’t like PHP. But at the time, we’d ruled out all other options and talked ourselves into PHP with the convincer “Facebook runs it… it’s gotta scale!”

Design? What design?

A two-man team: both degree educated, both experienced with languages from Ada to Eiffel and Lisp to Miranda. Both with industry experience working on small, medium and large teams. Both smart enough to know better.

Of course, it’s different when you’re your own boss. When there’s no client. No timescale. No requirements.

We got sucked into the ‘agile’ cult, taking on all their bad practices, and failing to follow any of the good. Very soon we were banging out code with gay abandon. We never planned a proper object model, and felt more productive banging out procedural code instead of implementing class hierarchies – this has lead directly to inefficient, inelegant code with a more than a touch of the cut’n’pastes.

To his credit, my partner introduced unit-testing with SimpleTest quite early-on. To our detriment, we never grouped tests into test-suites, only ever running tests in isolation. With human-error at play we’d regularly introduce code that broke a test, and not notice till weeks later. It wasn’t long before we were so used to having broken tests around that on we’d actual revel in the rare occasion when a test went green again.

Stupid, stupid, stupid, stupid…

The way forward…?

Though I’m sorely tempted to throw our code out the window together with PHP, I’m driven by the hope step-by-step refactoring can lead us to safety, breathing new life into the code, and new momentum into the site – without the unavoidable stagnation a total rewrite-from-scratch would entail.

We have a ton of work ahead of us, and its hard deciding what to focus on first:

Unit Tests
  • remove/update outdated tests
  • fix failing tests
  • organize into suites and then into a one-click “run all tests”
  • integrate “run all tests” into the build process: no pass, no deploy
  • general tuning (setting caching and buffer sizes)
  • query optimizations (using High Performance MySQL [])
  • finish class design using ActiveRecord / ActiveObject
  • solve bottlenecks with caching (where possible)
  • simplify/rewrite semantic HTML
  • break-up & organize CSS

That’s simply a list of things to refactor and fix, excluding all the new things we want to do (total front-end redesign, better ajax, more features…)

I’ve no doubt this is going to be a slow and painful process, but I’m hopeful the end results will be worth it. It’s been said that the only way to understand something is to try and explain it (hence this waffling preamble) – I’m planning to write follow-up articles as we go along, sharing the best-practices we discover, as well as pitfalls to avoid.

Please excuse me, I have some work to do.

Posted in Backstage

Google: Where art thou time conversion?

I love the fact you can use Google to perform basic calculations and conversions.

Once you know your currency codes, currency conversion couldn’t be simpler: 100 USD in GBP

And Maths? As well as your basic arithmetic operators, it also handles has pretty natural syntax for “to the power of”. e.g. (2143/22) ^ (1/4). Trigonometry function use radians, so it also lets you use PI as a constant: sin(PI/6)

They’ve even got a (really) nice way of handling percentages – you can even keep your commas and currencies in place – so calculating VAT is as simple as £4,399.99 * 17.5% (Note: I switched to the UK site for that one… If you run it on the answer automatically gets converted to US dollars! Of course, they let you override that by adding ” in GBP” to the query string.)

You can do weight conversions, distances, storage capacity… the list goes on.

So how come they don’t do time conversion? I don’t mean minutes into days, I mean converting one time zone into another.

I’m looking forward to reading about Apple’s new Macbooks, and I know there’s a conference at 10AM Pacific Time, or 1PM Eastern Time… but I don’t know what time that is where I am. I’m gutted Google can’t handle 10AM PST IN GMT.

Oh well… I guess I’ll just have to wait.

Update: I’ve just discovered Google’s things-to-do page (UK only?) Amongst other things, it explains how to get the current time for any location: simply prefix the place-name with “time ” – e.g. time london. That may be helpful if you know your geography? Personally, I’ve no idea which cities are in PST, and I’d only be guessing that maybe New York is in EST? (Google says EDT for New York – is it daylight savings time at the moment?)

Posted in Tip

Bloody hosting providers

Choosing a hosting provider can be a difficult process, especially when you’re on a budget.

I’m heavily involved with ewelike, a product information and price-comparison site that we’re slowly improving as we integrate more price and information feeds.

Of course you can’t actually see ewelike right now, as our hosting provider‘s been trying to commit hari kari for the last 3 days.

On-demand computing? Not quite.

Update: 2008-09-01 ewelike came back to life on Friday night. Aside from some recoverable table-corruption, I think we’ve emerged relatively unscathed – and possibly a little bit wiser.

Decisions on a shoe-string

We didn’t have the option of cloud-computing when we started, and we definitely didn’t have the venture capital to buy our own hardware. Our choice was between shared-hosting and private-servers.

We chose shared-hosting with dreamhost. Compared to service providers in England, dreamhost offered an enticing package with plenty of storage and bandwidth included. We’d got a good feel about them as we knew plenty of designers, developers and bloggers that used or recommended them.

Setup was simple, and we were pleasantly surprised by the freedom offered for a shared-hosting platform – they even allowed users to install custom-compiled copies of PHP to run on.

Sadly, we suffered a few reliability issues, and we never had any guarantee of performance. Once our database started to grow and performance dropped, we realized we need to look around at someone else (at this point, we’d had too many reliability issues to give dreamhost’s private servers a go.)

There were so many options for private-servers that we suffered a touch of analysis-paralysis. Should we rent or buy? Build our own server, or let someone else do it? Which flavor of Linux should we go for?

And then cloud-computing took off.

Cloud computing

After looking at various grid services, we narrowed our options to Amazon’s Elastic Compute Cloud and Flexiscale. Running a price-comparison site using Amazon’s platform just felt wrong – including Amazon is price-comparison is almost mandatory, but storing their competitor’s prices, product images and information within Amazon’s data-centers? That’s just weird.

The FlexiScale service is provided by xcalibre, a UK-based company I use to host the hexmen site, run by a team I’ve found supportive and responsive in the past. The most enticing things about FlexiScale were fast setup times, low startup costs, and simple methods for improving (virtual) server performance – with straight-forward billing costs.

We’ve been running on a Flexiscale for a few months without any problems. Until a few days ago.

Your risk or mine?

When Amazon’s EC2 service had an outage earlier this year, I asked a friend “would you rather deal with regular outages yourself, or put-up with occasional problems completely out of your control?”

We’d been thinking about hosting something ourselves: our own PCs in our own homes, using our own broadband connections. The hardware would probably be the most reliable piece of the puzzle, and the broadband the least. In fact, we worked on the assumption that we’d probably be missing for an hour or so every week, with the occasional issue where we’d be gone for a few hours (and ranting down the phone at our ISP.)

The risks of home-hosting seemed too great. Much better to go with a professional outfit with monitoring and procedures in place to resolve the inevitable problems as quickly and painlessly as possible.


Ewelike’s been down 3 days now. Three days! I know we’ve still got a lot of work to do to build-up traffic and a loyal user-base, and that’s probably a saving grace at this point. I’d hate to be clock-watching thinking “that’s another thousand pounds lost… And another…”.

I’m going to crawl off and figure out how to handle fail-over in future. Do we need to go so far as having the app ready to run on two different clouds? Would we be paranoid enough to have primary and secondary name-servers pointing to different services, just in-case one goes down?

It’s time to stop wallowing and crack on with things – but first I’ll get my English on and make a nice cup of tea. That’ll fix it.

Posted in Rant, Servers