Jimmy Breck-McKye

A lazy programmer

Testing Knockout.js Web Applications

I’ve been working with Knockout.js for a few months now. I’m impressed, but one thing I’ve found lacking is much community documentation on how to test Knockout apps. I thought I’d write an introductory post on testing Knockout.js applications for those new to the idea – like I myself was, a few moons ago.

The State of JavaScript in 2015

The JavaScript world seems to be entering a crisis of churn rate. Frameworks and technologies are being pushed out and burned through at an unsustainable speed. But I think the community will adapt and adopt new practices in response. Developers will move, I believe, from monolithic frameworks like Angular.js and Ember to a ‘pick n mix’ of small, dedicated libraries to mitigate the risk of churn and to allow solutions to different concerns to compete separately.

Some Thoughts on Knockout.js

I’ve been working with Knockout.js on a commercial project for a couple of months now and think I have a decent sense of its capabilities. However, I’ve never worked with any other web application frameworks before and wondered how others felt Knockout compared to them.

So far I’ve been really impressed, but I’m not certain how much that is to do with Knockout and how much that is to do with not having to use jQuery to perform templating and update a ‘model’ that’s actually just a bunch of scattered global variables. Obviously, I’d been trying to keep a model – view distinction even with just jQuery, but the data binding alone is extremely onerous when you’re doing it manually.

pSX Emulator Mirror

It looks as though the original host of the excellent pSX PlayStation One emulator – psxemulator.gazaxian.com – has gone down. The site hadn’t been maintained in a while and I fear it may have been forever abandoned. As such, I’ve added the most recent version of the emulator to this site. You can find it here.

Besides being easier to configure than ePSXe, pSX comes with a rather handy MIPS R3000a debugger that’s very handy in reversing work. I used it extensively in writing my Long range enemy attack mod for Final Fantasy VII.

A Simple Group Checkbox for Knockout.js

I’ve been using Knockout for the first time on a new project and have been pretty impressed. Recently, I had a need to implement a simple ‘group checkbox’. The Knockout documentation already provided an example of a ‘select / deselect all’ checkbox, but the behaviour I wanted was slightly different. I wanted a checkbox that would be unchecked when its children were disabled, checked when any were enabled and would select / deselect all if I toggled it. With a little research into ‘computed properties’, it turned out this is quite easy to do.

Style Only Part of a Line Path With Raphael.js

If you have a vector line path in Raphael.js and would like to style part of it – highlighting a section of a line graph, for example – you can achieve this easily using the path.getSubPath() interface to get part of your path, then adding a new shape on top based on that pathstring.

Octopress Makes Blogging About Programming a Cinch

Are you a programmer? Do you want to blog about your ideas, but want it to be as simple as possible? Octopress might be the tool for you.

As a software engineer working on a particular problem or technology, you probably find yourself making observations about what does and doesn’t work. But what happens to these insights? Writing them down in blog format can help consolidate your ideas, and it allows you to show your engagement to future potential employers. I want to talk a little about the blogging solution that I use, Octopress, and why I think it’s a great choice for software engineers in particular.

Using jsPerf: A How-to Guide

If you’re interested in testing the performance of a particular piece of JavaScript, you might be interested in jsPerf.

jsPerf allows you to run and compare the speed of arbitrary snippets of JavaScript against a blob of HTML of your choice. This means you can test not just pure JavaScript, but DOM manipulation and jQuery calls too.

Slideshow: Breaking the 1000ms ‘Time to Glass’ Mobile Barrier

I found a nice slideshow by Google’s Ilya Grigorik a few weeks ago, taking an overview of the essential issues in optimizing initial web page render time. The talk was mobile-oriented, but many of the same concerns apply to desktop sites. You can find the slides on Ilya Grigorik’s blog

Some key points:

  • 4G is not a ‘magic bullet’ for mobile performance problems. Our customers are going to be stuck with 3G for quite some time, and TCP-slow-start imposes harsh bottlenecks.
  • Waking up the radio on mobile devices is slow. Radio is typically turned off after idling for 100ms; subsequent requests suffer a significant warm-up penalty, even on 3G (where it can be up to 2.5 seconds)
  • Rendering is blocked as the browser constructs the DOM and CSSOM. Inlining ATF (above-the-fold) styles and bootstrapping further styles asynchronously may be a useful strategy
  • Inlining styles for above-the-fold content might be a wise strategy

Protected Members in JavaScript

If you’ve done much OOP in JavaScript, you can probably already simulate private member variables, by putting variables in a constructor’s closure (if not, go read this summary by Douglas Crockford). But you may not know that you can also emulate the protected status of C++ and Java — variables shared between parent and child classes, yet not exposed as public. This is occasionally useful, but is a little obscure to implement in JS if you don’t know how.

The basic idea is use the ‘parasitic constructor’ pattern — where a child constructor directly calls the parent constructor — and passing in an object defined in the context of the child constructor. The parent constructor decorates this object, and because JavaScript object arguments are effectively passed by reference, the members of this object are visible within the child constructor. As such, your child and parent constructors have a ‘shared secret’ object that effectively acts as a map of all the protected members.