What Steve Jobs Knew That the Rest of Us Didn't🔗

Michael E. Gerber, on Steve Jobs:

What did he know that the rest of us did not? My answer was simply that Jobs didn’t actually know more than the rest of us; he simply cared more.


★  Apple Watch In Review

It’s been around 6 weeks since I’ve had my Apple Watch. Whilst not perfect, I’m still very happy with it. Here’s a rundown of my thoughts.

I’ve got the 38mm Sport edition, with the black sports band. It’s a lot smaller than I imagined it would be, which is for the better. This means that it doesn’t have the bulk of other smart watches, and after the first few days I don’t feel conspicuous at all.

Not only does it look good, it feels really nice too. In fact, you forget it’s even there. There is a bulge at the bottom where the sensors sit, which I thought may be a problem, but that isn’t the case at all.

This is something I never thought would be said in a watch review: the sports band is really quite soft too. It’s firm enough to feel secure, but also smooth so that the last thing you’re thinking as you put it on is “I’m basically wearing a rubber band around my wrist”.

I have to admit, the box was a little bigger than I was expecting: the Watch comes in a case just like any other watch on the market. Unlike other smart watches, this is not a gadget. Apple clearly wants this to be an accessory: using technology to change how we think of watches.

And what a watch it is. Granted, this isn’t something that is kept for generations – I expect the Watch to have an update cycle of about five years – but I truly think that this is a watch wearer’s watch. Unlike the Pebble, which doesn’t really have much in terms of quality watchfaces, the Apple Watch has carefully designed faces that look beautiful and are genuinely useful.

But what makes this better than a regular watch, and indeed other smart watches, is the notifications. Within minutes I had muted all sounds, and had turned off both sound and vibration on my phone. The taptic engine is very subtle, and it really does feel like someone tapping you on the wrist. It feels nice, and it doesn’t disturb you or anybody else.

One thing, however, that does make it frustrating as a watch is Activation on Wrist Raise. With a classic watch, the time is always there for you to glance at. The Apple Watch requires you move your wrist, then wait, to see the time. The gesture detection isn’t quite right either, and so you find yourself exaggerating your arm movement, especially when wearing a coat.

The slight sluggishness is a problem in other areas, too. Apps can often take a noticable time to load; even the glances can take time for the data to appear. But being a first generation device I can’t see this being a problem for too long.

Sluggishness aside, compatibility with apps and services is at a high level, especially considering the watch has only been on general sale for a couple of months. Requiring a pairing with an iPhone has been a really smart move: Watch apps can talk to Phone apps, which means that any data you can access on your phone you can access on your wrist.

However, the best integration so far in my book has to be with Health. I put the activiy rings as a complication on my watchface, and whenever I look at my Watch, I know how active I am being, and how close I am to my goal. This is the feature which I’m sure I would miss if I had to do without my Apple Watch.

So, would I recommend it? Absolutely. Especially if you are a watch wearer and a heavy user of iPhone apps, the Apple Watch is a genuinely useful second screen, and turns the timepiece on your wrist into a “Watch Plus”.

It’s a purchase I don’t regret at all. I wouldn’t go back to my Pebble Watch, and certainly wouldn’t go back to a regular watch. The Apple Watch gives me far too many advantages that improves my life in small ways.

But then again, I’m a gadget lover. And if you’re not into gadgets, I’m not sure that you will see the point behind the Apple Watch. And that’s ok: it’s not for everybody.

Achieving the Ken Burns effect using CSS

The Ken Burns effect is a common technique used in video-making where a photograph or image is zoomed in and panned across, to make for more interesting visuals.

This effect can now be achieved using CSS’s animations properties. I’ve made up some example code to give a basic demonstration of what can be achieved.

To be able to pan across an image, we would need to use a size that’s bigger (either taller or wider) than we’ll be showing on the page, and we need to use CSS to tell the browser not to try and squeeze the image to the size we gave it. We use the object-fit property alongside setting a width, height, and overflow property to do this:

img:hover {
    object-fit: cover;
    overflow: hidden;
    width: 300px;
    height: 300px;

Once we’ve done that, we need to do the effect! This is achieved using CSS animations. Here, I’ve used CSS classes which I give the image to create two different animations depending on whether the image is a landscape or portrait image: each will pan in a different direction (across or up).

.portrait {
    animation: portrait 30s;
@keyframes portrait {
    from {
        object-position: bottom;
    } to {
        object-position: top;

    animation: landscape 30s;
@keyframes landscape {
    from {
        object-position: left;
    } to {
        object-position: right;

Notice that I’ve used unprefixed attributes here, but some browsers may need to be prefixed, or may not support either animations or object-fit.

Mocking in phpunit

To test a class in PHPUnit, it’s easier if you use dependency injection which enables you to mock other classes that we aren’t interested in testing (such as your database layer). So for example, instead of writing code like this to test a made-up User class:

class User() {
    private $db;

    function __construct()
        $this->db = new Database;

    function getUserData()
        return $this->db->getUserData();

$user = new User();

We can pass in the database class instead:

class User() {
    private $db;

    function __construct($db) {
        $this->db = $db;

    function getUserById($userid) {
        return $this->db->getUserData($userid);

$db = new Database; $user = new User($db);

This means that we can mock the Database object when we’re testing the User class, and pass the former into the latter. We do this as PHPUnit won’t override the new keyword.

In PHPUnit, it’s a case of creating the class but in place of using the new keyword we use a slightly longer one instead:

$mockDb = $this->getMock( 'Database', array('getUserData') );
                          array('userid' => 'joebloggs', 'name' => 'Joe Bloggs')

$user = new User($mockDb);
$this->assertEquals( $user->getUserById('joebloggs'), array('joebloggs', 'Joe Bloggs') )

In a nutshell, those two commands says what the class should be, and what the method should expect and return respectively. To break down what each bit of the two commands do:

  • getMock() is saying mock the class given in the 1st parameter, and we want to return given values for the methods given in the array in the 2nd parameter

  • The second command has a bit more too it. expects($this->any()) will mean that it doesn’t matter whether the method gets called or not: changing it to expects($this->once()) will mean that if the method isn’t called (or is called more than once) the test will fail

  • with() is the parameters that you should expect to be passed in (which is a good way to check that the parameters that’s being passed into a particular method are sensible), and will($this->returnValue()) is what you want to give as the known return value, for when you do your test

Of course, there’s much more you can do with PHPUnit mocking. The documentation is a pretty good start to find out what else is there.

Setting the proxy for command-line OS X

In OS X, it’s pretty simple to set a Location to set a proxy for whenever you’re somewhere you need to use one

However, this doesn’t affect some commandline applications, such as Homebrew. If you want to send this through a proxy, you’ll have to edit .curlrc to read something like

proxy = proxy.example.com:8080

Files not loading in a Virtualbox virtual machine

Every so often, randomly I see a problem where a virtual machine will only partly load a CSS or Javascript file, and when you load it in the browser it will have a bunch of strange unicode characters in there

We even saw it in joind.in

The fix is fairly simple - just edit your vhost configuration and add the following lines:

EnableMMAP Off
EnableSendfile Off

Switching branches in Subversion without losing changes

The problem: you want to switch branches in Subversion, but you’ve got changes in your local code that you’re not ready to commit

The solution: export a patch that you can store somewhere safe (or even commit into the repo so others can see it or work on it)

To export all changes, use svn diff to create a patch file:

svn diff > fix-that-annoying-bug.diff

As a sidenote, if I’m using a bug tracker, I like to put the bug ID in the filename: not only does this keep all the different projects together, it makes it easy to know what exactly the code changes does:

svn diff > myproject-1234-fix-that-annoying-bug.diff

From there I can revert all changes and switch branch:

svn revert -R . svn switch http://svn.example.com/my-new-branch/

Once I’m done with the new branch and want to go back, and assuming I’ve committed all my changes I switch back to my old branch:

svn switch http://svn.example.com/my-original-branch/

And I import my original changes patch file to start work again, carrying on from where I left off:

patch -p0 -i fix-that-annoying-bug.diff

Problems with attributes not working in IE and Opera?

So, what did I do with my bank holiday weekend? I was intrigued by some odd Opera and IE behaviour — that’s what.

I was presented with a site whose styling wasn’t working for certain tags. It was an odd one. I thought it might be an absolute positioning bug, but testing was bringing up nothing – why on earth would simple CSS styling, nothing special, fail completely in Opera?

Then I took a closer look at the source — and something caught my eye. There was some malformed HTML:

<h1 title="test""style="background-color: #ccc">Test</h1>

Gotcha! Removing that innocent looking multiple quote fixed the problem. But I still wasn’t happy. Browsers should recognise and fix badly formed HTML, no? It’s not like a closing tag was completely missing. So I made a basic HTML template with little more than the h1 tag you see above, and just enough HTML5 to make it validate.

Then I played around with it. What happens if I add a space?

<h1 title="test"" style="background-color: #ccc">Test</h1>

That fixed it. Hm. Why on earth would the lack of space break things? Lacking a space is completely fine in both HTML and XHTML. Let’s remove the space again, and test some more. What if I replace the rogue “ with another character – say $?

<h1 title="test"$style="background-color: #ccc">Test</h1>

Wait — that’s a turnout for the books — it now breaks in Chrome. Then it dawned on me. If I replace that dollar sign with a normal alphanumeric character — the character ‘a’:

<h1 title="test"astyle="background-color: #ccc">Test</h1>

That’s it! Without the space between attributes, Opera and Internet Explorer are treating "style as the attribute, with Webkit and Gecko being smart and removing the extra quote. Add the space, and Webkit does the same. Obvious when you think about it, isn’t it?

So that’s what I did with my bank holiday weekend. What did you do?

Reusing primary keys in MySQL

I’ve recently had need to reuse the primary key for a table whenever a row gets deleted, for example if a row of ID 5 gets deleted, the next entry will re-use the ID of 5. Usually this causes problems with foreign keys, but as no other table had a foreign key linked to this table, it would cause no problems.

The biggest hurdle was finding what the first missing primary key actually is. This takes a bit of SQL, but the following almost gets it:

SELECT MIN(table.id + 1) AS nextID FROM table LEFT JOIN table t1 ON table.id + 1 = t1.id WHERE t1.id IS NULL

I say almost, because if row/id 1 is deleted, the above code won’t catch it. I’m afraid that you’ll have to use SELECT to check for this:

SELECT count(id) FROM table WHERE id = 1

If the value is 0, then you know you need to create row id 1.

And that’s it. All you need to do is throw this together into a MySQL function (or a php function if you’re not feeling adventurous), and you have the lowest unused primary key all ready for you to put into your INSERT line.