Skip to content

Instantly share code, notes, and snippets.

View ryanwilliamquinn's full-sized avatar

Ryan Quinn ryanwilliamquinn

View GitHub Profile
@ryanwilliamquinn
ryanwilliamquinn / Function.bind.bind
Created July 29, 2014 15:53
sorting out function.bind.bind
1. Function.bind.bind(Function.call) = Function.call.bind
2. Function.call.bind(someOtherFn) = someOtherFn.call
3. someOtherFn.call(newThisValue)
First you set up the 'binder' function. Note that 'binder' is not an official term, I just made it up:
var bb = Function.bind.bind(Function.call); // bb ends up as a function: Function.call.bind
then you can use it like so:
var boundfn = bb(someOtherFn); // boundfn is now a function: someOtherFn.call
@ryanwilliamquinn
ryanwilliamquinn / gist:434d6d5d0f921618af08
Created December 17, 2014 05:40
error catching machine
var BPromise = require('bluebird');
BPromise.try(function () {
console.log(1);
console.log(x.y);
console.log(2);
}).catch(function (err) {
console.log('caught an error with try', err);
});
'use strict';
var bpromise = require('bluebird'),
request = require('request'),
_ = require('lodash');
/* fn takes a phrase - may the force be with you
which word has the most synonyms */
var key = "TZlKw4gd1qFQhA2CbMLa";
const fs = require('fs')
// app.js has one line: console.log('this is app.js')
const appReadstream = fs.createReadStream('files/app.js')
// index.js has one line: console.log('this is index.js')
const indexReadstream = fs.createReadStream('files/index.js')
const out1 = fs.createWriteStream('files/outindexfirst.js')
const out2 = fs.createWriteStream('files/outappfirst.js')
indexReadstream.pipe(appReadstream.pipe(out1))
appReadstream.pipe(indexReadstream.pipe(out2))