Skip to content

Instantly share code, notes, and snippets.

View colingourlay's full-sized avatar

Colin Gourlay colingourlay

View GitHub Profile
@colingourlay
colingourlay / flat.js
Last active June 15, 2019 22:42
The `flat` function allows you to write then-able functions without explicitly creating your own Promises, and instead receiving the promise resolution/rejection functions as a destructure-able object as a first argument.
function flat(fn) {
return function (...args) {
return new Promise((resolve, reject) => {
fn.call(this, {resolve, reject}, ...args);
});
};
}
@colingourlay
colingourlay / index.css
Last active August 1, 2017 00:40
Use the fully qualified path of stylesheets you control to discover relative asset paths, no matter where your assets are deployed.
[xyz] { content: url(../); }
@colingourlay
colingourlay / index.js
Last active October 26, 2016 06:00
Using the Y combinator to immutably apply a series of operations to a value, using outputs as inputs. A "Function Centipede", if you will.
const Y = f => (x => x(x))(x => f(y => x(x)(y)));
const manufacture = Y(f => x => x.length > 1 ? f([x[1](x[0])].concat(x.slice(2))) : x[0]);
const stage = x => y => manufacture([y].concat(x));
const operations = [
x => x + 1,
x => x * 3,
x => x - 2
];
const transform = stage(operations);
@colingourlay
colingourlay / index.js
Created October 25, 2016 23:57
requirebin sketch
require('pointer-css-variables')(true);
var height;
var nextHeight = window.innerHeight;
window.requestAnimationFrame(function updateHeight () {
if (nextHeight !== height) {
height = nextHeight;
document.documentElement.style.setProperty('--window-inner-height', height);
}
@colingourlay
colingourlay / index.js
Last active October 25, 2016 12:35
requirebin sketch
require('pointer-css-variables')();
// Look at <head> tab to see CSS using variables
// to display coordinates at the cursor
@colingourlay
colingourlay / index.js
Created October 7, 2016 03:53 — forked from yoshuawuyts/index.js
requirebin sketch
const chooet = require('chooet');
const html = require('chooet/html');
chooet(choo => {
app = choo();
app.model({
state: { title: 'Not quite set yet' },
reducers: {
update: (data, state) => ({ title: data })
@colingourlay
colingourlay / index.js
Created October 6, 2016 16:02
requirebin sketch
const chooet = require('chooet');
const html = require('chooet/html');
chooet(choo => {
app = choo();
app.model({
state: { title: 'Not quite set yet' },
reducers: {
update: (data, state) => ({ title: data })

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 B491 C16D 2665 A596 4678 1F39 A05D E064 F67F 672F

To claim this, I am signing this object:

@colingourlay
colingourlay / .block
Last active September 18, 2016 22:55 — forked from mbostock/.block
World Map
We couldn’t find that file to show.
@colingourlay
colingourlay / idle-analytics.js
Created September 7, 2016 07:41
Defer the standard Google Analytics script until the page is idle, in supported browsers.
(function(x,y,z){(x[y]&&x[y](z))||z()})(window,'requestIdleCallback',function(){
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-X', 'auto');
ga('send', 'pageview');
});