Skip to content

Instantly share code, notes, and snippets.

View ljharb's full-sized avatar
🔜
working on that thing you asked about

Jordan Harband ljharb

🔜
working on that thing you asked about
View GitHub Profile
@ljharb
ljharb / grid.js
Last active August 29, 2015 14:15 — forked from getify/grid.js
function formatValue(x) {
var ret;
if (typeof x == "string") {
return "'" + x.replace(/\n/g,"\\n") + "'";
}
if (typeof x == "number" && x === 0 && (1/x === -Infinity)) {
return "-0";
}
if (Array.isArray(x)) {
@ljharb
ljharb / gist:6321587
Last active December 21, 2015 14:39 — forked from getify/gist:6315505
// because of declaration hoisting, wherever we put `filter()`, it
// will be declared for a longer lifetime than is necessary.
//
// inline function expression (or arrow function) inside the loop
// isn't the answer, because then you recreate the function over
// and over again.
function doSomething() {
var items = [], i, ret = 0;
@ljharb
ljharb / Queue.js
Last active December 12, 2015 05:58 — forked from WebReflection/Queue.js
/*global setTimeout */
var Queue = function Queue(q) {
"use strict";
// (C) WebReflection - Mit Style License
var callback,
next = function next() {
callback = q.shift();
if (callback) { callback(q); }
return !!callback;
};
var EventEmitter = require("events").EventEmitter;
var emitter = new EventEmitter();
var foo = function () {
console.log("foo");
};
emitter.once("foo", foo);
var bar = function () {
Function.prototype.within = function (millis) {
var that = this;
return function () {
var args = Array.prototype.slice.call(arguments); // if sinful present, slice(arguments)
return window.setTimeout(function () { that.apply(null, args); }, millis); );
};
};