Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Gourlay colingourlay

View GitHub Profile
View debounce.js
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 Aug 29, 2015
unpackage.json - The crazy self-initialising opinionated app project. Put this into an empty directory and run `npm start`.
View package.json
{
"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 Feb 26, 2014
Using react-router-component to drive the routing of a Cordova app (while still working as a web app).
View app.jsx
function init() {
var HomePage = React.createClass({
render: function() {
return <div>Home</div>;
}
});
var NotFoundPage = React.createClass({
render: function() {
View 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:

View computed.js
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 / bind.js
Created Aug 13, 2014
Bind a function, with a reference to its target
View bind.js
/* 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 / index.js
Created Sep 12, 2014
requirebin sketch
View index.js
var d = require('date.js');
console.log(d('tomorrow afternoon at 4:30pm 1 month from now'));
@colingourlay
colingourlay / example.js
Created Nov 4, 2014
Simple text substitution
View example.js
var format = require('./format');
console.log(format('%s, %s!', 'Hello', 'World'));
// > "Hello, World!"
@colingourlay
colingourlay / index.js
Last active Aug 29, 2015
Soft page load script
View index.js
// 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) {
View markdown.css
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}