Skip to content

Instantly share code, notes, and snippets.

View colingourlay's full-sized avatar

Colin Gourlay colingourlay

View GitHub Profile
@colingourlay
colingourlay / Y Combinator
Created January 6, 2014 03:55
Y Combinator in JavaScript
var Y = function (incubate) {
return function (scrutinize) {
return function (hacker) {
if (hacker.gender == 'male' || scrutinize(hacker)) {
incubate(hacker.startup);
}
return hacker;
};
};
};
@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
Last active October 22, 2021 15:16
Lodash / Underscore sort object keys. Like _.sortBy(), but on keys instead of values, returning an object, not an array. Defaults to alphanumeric sort.
var obj = {b: 3, c: 2, a: 1};
_.sortKeysBy(obj);
// {a: 1, b: 3, c: 2}
_.sortKeysBy(obj, function (value, key) {
return value;
});
// {a: 1, c: 2, b: 3}
@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!"