Skip to content

Instantly share code, notes, and snippets.

View callumlocke's full-sized avatar

Callum Locke callumlocke

View GitHub Profile
@callumlocke
callumlocke / postcode.js
Created June 5, 2017 16:26
Functions for validating and normalising postcodes
const postcodeRegex = /^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i;
const incodeRegex = /\d[a-z]{2}$/i;
const isValidPostcode = (p) => postcodeRegex.test(p.replace(/\s/g, ''));
const normalisePostcode = (p) => {
if (!isValidPostcode(p)) throw new Error('Invalid postcode');
const spaceless = p.replace(/\s/g, '');
@callumlocke
callumlocke / modernizr-track-element-test.js
Last active December 30, 2015 03:19
Modernizr test for "track" element (part of HTML5 video element, for captions/subtitles etc)
Modernizr.addTest('track', function () {
var t = document.createElement('track');
return t.track && t.track.kind;
});
@callumlocke
callumlocke / item.rb
Created October 18, 2013 11:50 — forked from Darep/item.rb
# app/models/item.rb
require 'concerns/sortable'
class Item < ActiveRecord::Base
include Sortable
attr_accessible :title
end
@callumlocke
callumlocke / .bowerrc
Last active December 24, 2015 11:49
Helper function to get the spreadsheet key from a URL in FT IG projects.
{
"directory": "bower_components",
"json": "bower.json"
}
@callumlocke
callumlocke / README.md
Last active December 19, 2015 00:09
Mocha Spec Runner Spec

Mocha Spec Runner Spec

This is a spec to verify that your Mocha Spec Runner page can actually load all its script tags.

Paste it into your Spec Runner page as an inline script, just before mocha.run();.

Why?

If one of your source scripts fails to load (e.g. due to a malformed URL), you usually don't get any error message. This can cause confusing test failures that are hard to debug.

@callumlocke
callumlocke / job.sh
Last active December 18, 2015 21:39 — forked from kavanagh/job.sh
function job() {
if [[ -z "$1" ]]; then
echo "You must specify a project name!"
return;
fi
mkdir $1 && cd $1 \
&& yo ig-job \
&& subl . && subl ./app/scripts/main.js && subl ./app/scripts/config.js \
&& osascript -e 'tell application "Terminal" to activate' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
$ grunt
Running "jshint:all" (jshint) task
>> 2 files lint free.
Running "clean:server" (clean) task
Running "coffee:dist" (coffee) task
File .tmp/scripts/hello.js created.
Running "coffee:test" (coffee) task
@callumlocke
callumlocke / rAF.js
Created February 8, 2013 16:44 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@callumlocke
callumlocke / README.md
Last active October 26, 2015 14:50
Importing lodash functions from lodash-es categories
import {chunk, zipObject} from 'lodash-es/array';

console.log(zipObject(chunk(['a', 'b', 'c', 'd'], 2)));
$ rollup -f=iife demo.js > output.js
@callumlocke
callumlocke / README.md
Created October 26, 2015 14:33
Importing lodash functions from lodash-es
import {chunk, zipObject} from 'lodash-es';

console.log(zipObject(chunk(['a', 'b', 'c', 'd'], 2)));
$ rollup -f=iife demo.js > output.js