Enable App Groups for both targets

With the NSUserDefaults class, you can save settings and properties related to application or user data.

While developing extensions in iOS, you may find a need to share application or user data between the host app and the extension.

To do so, you can enable the `App Groups` Capability.

  1. In Xcode’s Project Navigator, Click the `Project Icon`
  2. Select the `Host App` Target
  3. Select the `Capabilities` Tab on the top menu
  4. Toggle the `App Groups` capability
    - If you have not associated a development team you will be prompted to.
  5. Select `+` icon and enter a unique group name such as…

Consider this rather lengthy approach to error checking:

if (errors.length > 0) {
next(errors);
} else {
next();
}

Typically, you would use a ternary operator to express this more tersely:

next(errors.length > 0 ? errors : null);

However, this often becomes ugly and cumbersome with symbols littering themselves thought the code, for example:

next(errors.length > 0 ? errors.length < 10 ? errors : null);

My prefered approach is as follows:

next(errors.length && errors || null);

This uses short-circuit evaluation to return null if there are zero errors and implicit conversion to return the errors if there are any.

To create an animation by using an HTML5 canvas you need to display a sequence of 2D elements by using the API provided by the canvas object. This is typically something you achieve through iteration, where in each repeated cycle you replace the element drawn previously with a new element. One way to achieve this is to create a game loop.

In Javascript you can use the setInterval method to set up this game loop.

(function (window) {
function gameLoop() {
// Do stuff
}
window.setInterval(gameLoop, 1000 / 60); // 60fps
} (window));

Note: the second parameter of the setInterval…

Recently I've been doing a lot of with HTML5 canvas and Javascript; much of the time including an Ajax request that may take some time to request and process the returned data. Needless to say the requirement to provide some meaningful feedback that ‘things are happening’ often needs to be implemented. With that in mind here’s my take on an HTML5 Canvas loading spinner.

I’d like a number of spokes in a circle around a centre point. This can easily be done using rotate transforms. Draw a line, rotate the canvas, draw another line, rinse and repeat until enough spokes…

Back in 2001, after an idle browse I wrote a basic javascript universe that animating images around the screen, with respect to their gravitational influences on each other. The code is now long lost but I was recently reminded of it while thinking of ideas for mobile phone games. So here’s my recreation.

We'll need some particles that have size, position & velocity. Velocity (which is speed in a given direction) will be represented with an x and y speed giving us the direction and overall speed.

var particles = [
{
size: { radius: 40, mass: 1000 },
position…

There is no native method to draw an ellipse on a HTML5 canvas, and there are many different ways to accomplish it. In the past I’ve needed to draw a symmetrical ellipse, and thankfully there’s an easy way using scale transforms. After all an ellipse just a skewed\scaled circle.

To draw a circle using the HTML5 canvas API you would arc around a center point at a specific radius from 0° to 360° degrees. Written in code this looks as follows;

var start = 0;
var end = 2 * Math.PI; // 360 degrees is equal to 2π radians

context.beginPath();
context.arc(centerX, centerY, radius…

A Raspberry Print Server

This is part of a short series of posts that i’m writing shortly after getting my hands on a Raspberry Pi In which i want to;

Making a print server

The good thing here is that you're not going to have to install any drivers on the Pi.We'll use a printing service called CUPS a unix printer service with excellent sharing features. …

without a password

This is part of a short series of posts that i'm writing shortly after getting my hands on a Raspberry Pi In which i want to;

Setting up your SSH keys

You can skip this section; Assuming you already have set up your SSH keys, in order to use something like Heroku or GitHub.If you haven't here’s a good article from GitHub.

Get your SSH key to the Pi

After setting you your SSH key (above) you should find that you have the following…

now what?

I’d been looking forward to getting a Raspberry Pi for a quite some time now, and today it’s arrived — Yay! But what to do next? Well, that’s what this post is all about.

So, after giving it a static ip address and the obligatory update.

$ ssh pi@<ip address>
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get clean

My intentions are to;

Creating a browser action that toggles content scripts. 

Recently I decided to learn how to create a Chrome extension. In typical fashion, rather than go for the simplest method I decided to splunk into one of the more esoteric techniques of having code that executes within another pages context depending on interactions with the extension button itself. In other words; Clicking on the Extension button causes code to execute within the page in order to render additional UI. Which you may have seen in my WhatColor extension.

So to lets jump straight to some codes;

Firstly the script running as part of the extension, wired up in `background.js`

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store