Skip to content

Instantly share code, notes, and snippets.

View eschwartz's full-sized avatar

Edan Schwartz eschwartz

View GitHub Profile
@eschwartz
eschwartz / typeHelpers
Last active August 29, 2015 13:56
Handlebars helpers for parsing object types for YUIDocs templates
var NATIVES = {
'Array': 1,
'Boolean': 1,
'Date': 1,
'decodeURI': 1,
'decodeURIComponent': 1,
'encodeURI': 1,
'encodeURIComponent': 1,
'eval': 1,
'Error': 1,
@eschwartz
eschwartz / MarkerCollections.html
Last active August 29, 2015 13:57
Aeris.js MarkerCollections
<!DOCTYPE html>
<html>
<head>
<title>Aeris.js MarkerCollection example</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
require.config({
paths: {
aeris: 'bower_components/aerisjs/src',
// Aeris.js dependencies
underscore: 'bower_components/underscore/underscore',
jquery: 'bower_components/jquery/jquery',
backbone: 'bower_components/backbone/backbone',
leaflet: '//cdn.leafletjs.com/leaflet-0.7.2/leaflet-src',
'leaflet-markercluster': 'bower_components/leaflet.markercluster/dist/leaflet.markercluster-src',
@eschwartz
eschwartz / SassMeister-input-HTML.html
Created December 3, 2013 15:23
Generated by SassMeister.com.
<a class="closeBtn">.closeBtn</a>
<div class="acme-app">
<a class="closeBtn">.acme-app .closeBtn</a>
</div>
<div class="acme-app">
<div class="reset">
<a class="closeBtn">.acme-app .reset .closeBtn</a>
</div>
@eschwartz
eschwartz / listenTo.js
Last active January 1, 2016 19:09
WireJS Plugin: ListenTo Facet
define([
'vendor/underscore',
'when'
], function(_, when) {
/**
* Helper class for
* the listenTo facet.
*
* @param proxy
@eschwartz
eschwartz / drag-drop.css
Last active January 15, 2016 16:06
Drag and Drop
/* Prevent the text contents of draggable elements from being selectable. */
[draggable] {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
/* Required to make elements draggable in old WebKit */
-khtml-user-drag: element;
-webkit-user-drag: element;
}
@eschwartz
eschwartz / promise-series
Created February 23, 2016 15:47
Promise Series: run an async fn in series an arbitrary number of times
const _ = require('lodash');
function series(count, asyncFn) {
return _.range(0, count)
.reduce((lastRun_, i) => {
return lastRun_.then(() => asyncFn(i))
}, Promise.resolve());
}
series(10, (i) => {
@eschwartz
eschwartz / assert-throws-async
Created March 29, 2016 19:36
Assertion that a promise-fn fails
const assert = require('assert');
const _ = require('lodash');
function throwsAsync(block, expectedError, message) {
return block()
.then(res => {
assert.fail(res, expectedError, message, 'is');
}, err => {
if (_.isFunction(expectedError)) {
// note that assert.throws doesn't work with custom Error constructors
@eschwartz
eschwartz / demo.js
Last active April 12, 2016 15:28
Using deferred to test async services
function mockReadFile(mockPath, content) {
// see https://gist.github.com/eschwartz/955a3f8925e24270550cb635dd49c12b
const deferred = Deferred();
sinon.stub(fs, 'readFile', _.wrap(fs.readFile, (origFn, path, encoding, cb) => {
if (path !== mockPath) {
return origFn.readFile(path, encoding, cb);
}
// Only resolve `fs.readFile` when deferred is resolved
@eschwartz
eschwartz / cluster.js
Last active May 2, 2016 17:10
Node cluster
#!/usr/bin/env node
/**
* Usage:
*
* node cluster.js ./worker-script.js
*/
const cluster = require('cluster');
const path = require('path');
function startCluster(runWorker, opts) {