Skip to content

Instantly share code, notes, and snippets.

@grncdr
grncdr / README.md
Created February 18, 2014 02:40
Minimal listener/event notifier for JavaScript

event-emitter-minus

EventEmitter without a base class or string event names. Supports adding, removing, and one-shot listeners.

Synopsis

var listeners = require('listeners')

var onEvent = listeners()
@grncdr
grncdr / patch-project.pbxproj.diff
Created March 13, 2014 19:53
Patch for graphviz homebrew formula
--- macosx/graphviz.xcodeproj/project.pbxproj.orig 2012-08-13 15:14:54.000000000 -0500
+++ macosx/graphviz.xcodeproj/project.pbxproj 2012-08-14 13:59:30.000000000 -0500
@@ -380,12 +380,10 @@
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
- ../lib/cdt/.libs,
- ../lib/cgraph/.libs,
- ../lib/gvc/.libs,
+ "$(PREFIX)/lib",
@grncdr
grncdr / example.js
Created June 14, 2014 21:38
testing API's with buster
'use strict';
var buster = require('buster');
var testApi = require('./test-http');
function exampleApp () {
return function (req, res) {
res.setHeader('content-type', 'text/plain');
res.setHeader('content-length', req.url.length);
res.end(req.url);
@grncdr
grncdr / custom-error.js
Last active August 29, 2015 14:05
Custom JS errors
var inherits = require('inherits');
inherits(CustomError, Error);
function CustomError () {
this.constructor.super_.apply(this, arguments);
this.name = this.constructor.name;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
@grncdr
grncdr / deferred-proxy.js
Last active August 29, 2015 14:05
Promise-based generic deferred proxy
/**
* Create a proxy object with the given prototype that caches all method calls to be applied to a target later.
*
* Example of proxying an asynchronously obtained Result object
*
* function Client (transport) {
* this._transport = transport;
* }
*
* Client.prototype.query = function (query) {
@grncdr
grncdr / why-wont-you-die.js
Created October 4, 2014 16:17
Sometimes it's hard to know who's keeping your process alive
var timeouts = [];
var intervals = [];
var sockets = [];
var setTimeout_ = setTimeout;
var clearTimeout_ = clearTimeout;
var setInterval_ = setInterval;
var clearInterval_ = clearInterval;
var Socket = require('net').Socket;
var emit = Socket.prototype.emit;
@grncdr
grncdr / formatter.js
Created November 7, 2014 22:58
Prototype of formatter for tcomb errors
'use strict';
var xtend = require('xtend');
var op = require('object-path');
var isMeta = /^meta\./;
module.exports = function formatErrors (errors, options) {
options = options || {};
var byPath = options.paths || {};
var byType = options.types || {};
@grncdr
grncdr / hook.js
Last active August 29, 2015 14:08
Collect untranslated fields in a contentful entry and forward them elsewhere.
var hyperquest = require('hyperquest');
module.exports = checkForUntranslatedFields;
module.exports.schema = {
access_token: 'string',
translation_url: 'string',
space_id: 'string',
entry_id: 'string'
};
@grncdr
grncdr / mergeHooks.js
Last active August 29, 2015 14:09 — forked from Marak/mergeHooks.js
Merge multiple Hooks into a single Hook
var http = require('http');
module['exports'] = function recieveHttp (hook) {
var hook2 = hook.open('http://hook.io/Marak/echo?foo=bar');
var hook3 = hook.open('http://hook.io/Marak/echo');
var hooks = 2;
function complete() {
@grncdr
grncdr / contentful2gengo.js
Last active August 29, 2015 14:09
Turn Contentful webhooks into Gengo jobs
var Bluebird = require('bluebird');
var createContentfulClient = require('contentful-management').createClient;
var createGengoClient = require('gengo');
var collectStream = Bluebird.promisify(require('collect-stream'));
var keys = Object.keys;
module.exports = checkForUntranslatedFields;
module.exports.schema = {
cmaAccessToken: {