This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |