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 / 0_reuse_code.js
Created November 6, 2013 02:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@colingourlay
colingourlay / onlyWhen.js
Created November 4, 2013 02:03
onlyWhen - run a function with its original arguments once a condition is met.
/**
* Creates a wrapped version of a funtion that will run with the original
* arguments, once a condition is met. If the condition is not met, it will
* be checked on a set interval until it is met.
*
* @param {Boolean} condition function you expect to eventually return a truthy value
* @param {Function} func original function to resolve
* @param {Number} interval time to wait between checks
* @return {Function} wrapped function you call can call as it it was the original function
*/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Single-Column Responsive Email Template</title>
<style>
@media only screen and (min-device-width: 541px) {
.content {
@colingourlay
colingourlay / example.txt
Last active December 26, 2015 04:49
Grunt task for cycling through each item in a directory on an interval and creating a symlink which points to it. This is helpful for cycling through logs, or an archive of data captured over time. Coupled with a server, it serves as a good simulated data endpoint. This should be defined after grunt.initConfig inside your Gruntfile, or you can r…
$ grunt link-cycler --root=archive/json --interval=30000 --link=current --verbose --initial=10
Running "link-cycler" task
Cycling through last 3 of 12 children, 1 per 30000ms...
Child 10/12:
Linking archive/json/current to archive/json/2013-09-23_12-28-32
Child 11/12:
@colingourlay
colingourlay / index.js
Created February 16, 2013 08:57
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@colingourlay
colingourlay / location.txt
Created December 8, 2015 13:39
Poker Chip Values
data:text/html, <style>body{font-size:6rem;font-family:sans-serif;text-align:center;}div{display:inline-block;margin:2rem;width:10rem;height:10rem;line-height:10rem;padding:2rem;border-radius:50%;border:0.5rem solid black;}div+div{background-color:blue;color:white;}div+div+div{background-color:red;}div+div+div+div{background-color:black;}p{text-align:center;}</style><div>25</div><div>50</div><div>100</div><div>500</div><p>Total: $10,000</p>
@colingourlay
colingourlay / README.md
Last active November 23, 2015 14:09
Embeddable widget code preview bookmarklet

Embeddable widget code preview bookmarklet

Quickly preview embeddable widget code such as a Twitter card or Instagram post, before adding it to your website code.

Install

Copy the text of bookmarklet.txt (below) into a new bookmark with a memorable name like "Preview Embed Code" and place it on your bookmarks bar.

Usage

@colingourlay
colingourlay / roman.js
Created April 18, 2012 22:24
Roman numerals generator
(function () {
function romanify(value) {
var numbers, numerals, result, i, len;
numbers = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
numerals = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
result = "";
for (i = 0, len = numbers.length; i < len; i++) {
@colingourlay
colingourlay / namespace.js
Created April 14, 2012 09:06
JavaScript namespacing (depends on jQuery)
(function (global, $) {
global.namespace = function (nsName, obj) {
var level, names, name;
level = global;
names = nsName.split('.');
while(name = names.shift()) {
level[name] = level[name] || {};
level = level[name];
}
$.extend(level, obj);