Skip to content

Instantly share code, notes, and snippets.

View colingourlay's full-sized avatar

Colin Gourlay colingourlay

View GitHub Profile
@colingourlay
colingourlay / debounce.js
Created February 7, 2014 05:23
Debounce
function debounce(fn, wait) {
var timeout;
return function() {
var context = this, // preserve context
args = arguments, // preserve arguments
later = function() { // define a function that:
timeout = null; // * nulls the timeout (GC)
fn.apply(context, args); // * calls the original fn
};
@colingourlay
colingourlay / package.json
Last active August 29, 2015 13:56
unpackage.json - The crazy self-initialising opinionated app project. Put this into an empty directory and run `npm start`.
{
"dependencies": {
"browserify": "~3.30.1"
},
"devDependencies": {
"clean-css": "~2.1.1",
"gazer": "0.0.3",
"myth": "~0.3.0",
"rework-npm-cli": "0.0.1",
"st": "~0.3.1",
@colingourlay
colingourlay / app.jsx
Created February 26, 2014 23:58
Using react-router-component to drive the routing of a Cordova app (while still working as a web app).
function init() {
var HomePage = React.createClass({
render: function() {
return <div>Home</div>;
}
});
var NotFoundPage = React.createClass({
render: function() {
@colingourlay
colingourlay / keybase.md
Last active August 29, 2015 13:57
keybase.md

Keybase proof

I hereby claim:

  • I am colingourlay on github.
  • I am colingourlay (https://keybase.io/colingourlay) on keybase.
  • I have a public key whose fingerprint is E4F2 CB27 99F8 1373 51B1 DABD 39B2 C95F 4463 07A3

To claim this, I am signing this object:

@colingourlay
colingourlay / bind.js
Created August 13, 2014 03:21
Bind a function, with a reference to its target
/* Raynos' function.bind module, edited to add __target__ property */
/* Original: https://github.com/Raynos/function-bind/blob/master/index.js */
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;
var funcType = '[object Function]';
module.exports = bind;
@colingourlay
colingourlay / computed.js
Created August 13, 2014 04:32
ES3 Observable
var Observable = require("./index.js")
module.exports = computed
function computed(observables, lambda) {
var values = []
function listener(i) {
return function (value) {
values[i] = value
@colingourlay
colingourlay / index.js
Created September 12, 2014 00:30
requirebin sketch
var d = require('date.js');
console.log(d('tomorrow afternoon at 4:30pm 1 month from now'));
@colingourlay
colingourlay / example.js
Created November 4, 2014 05:43
Simple text substitution
var format = require('./format');
console.log(format('%s, %s!', 'Hello', 'World'));
// > "Hello, World!"
@colingourlay
colingourlay / index.js
Last active August 29, 2015 14:19
Soft page load script
// This script applies an is-loading class to the html element,
// which is then replaced by an is-loaded class after a timeout
// of 2 seconds. This can be triggered prematurely by calling
// window.KILL_LOADING_STATUS (while it exists).
// Combined with the injected style, this sets the opacity of
// the body content to 0, then fades it back to 1.
// This is useful for pages that heavily modify the page after
// rendering, and you want to hide the reflows from visitors.
(function (htmlEl) {
@colingourlay
colingourlay / transform-data.js
Last active August 29, 2015 14:21
kgo task queue example
#!/usr/bin/env node
var PATH = require('path')
.resolve(__dirname, '../src/data') +
'/comm_metadata.';
require('kgo')
({
_read: PATH + 'csv',
_parse: {auto_parse: true, columns: true},