This file contains hidden or 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
import Promise as "bluebird"; | |
function takesACb() { | |
process.nextTick(() => { throw new Error }); | |
} | |
Promise.promisify(takesACb)() | |
.then(function () { | |
console.log("woo"); | |
}).catch(function (err) { |
This file contains hidden or 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
import request from "request-promise"; | |
import {readFile, writeFile} from "mz/fs"; | |
let uri = "http://localhost:8917"; | |
async () => { | |
let body = await request.get({uri}); | |
await writeFile(__dirname + "/foo", body); | |
let contents = await readFile(__dirname + "/foo"); | |
await writeFile(__dirname + "/bar", contents.toString().split("").reverse().join("")); |
This file contains hidden or 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
class AsyncArray extends Array { | |
[Symbol.iterator]() { | |
let iter = super[Symbol.iterator](); | |
return { | |
next() { | |
let elem = iter.next(); | |
let promise = new Promise(resolve => setTimeout( | |
() => resolve(elem.value), 1000) | |
); | |
return {done: elem.done, value: promise}; |
This file contains hidden or 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
import {EventEmitter} from "events"; | |
let ee = new EventEmitter; | |
ee.on("evt", () => { | |
console.log("event emitted"); | |
}); | |
function emitEvent() { | |
console.log("about to emit event"); |
This file contains hidden or 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 request = require("request"); | |
var jar = request.jar(); | |
request({ | |
uri: "https://rink.hockeyapp.net/users/sign_in", | |
jar: jar | |
}, function (err, response, body) { | |
var authenticity_token = body.match(/name="authenticity_token".*?value="(.*?)"/)[1]; | |
request({ | |
uri: "https://rink.hockeyapp.net/users/sign_in", |
This file contains hidden or 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
let highland = require("highland"); | |
let Transform = require("stream").Transform; | |
let byline = require("byline"); | |
class AsyncTransformStream extends Transform { | |
_transform(chunk, encoding, callback) { | |
setImmediate(() => { | |
this.push(chunk + "\n"); | |
callback(); | |
}); |
This file contains hidden or 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
server { | |
listen 80; | |
server_name doge.explosionpills.com; | |
location / { | |
proxy_pass http://localhost:3001; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; |
This file contains hidden or 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 readline = require("mz/readline"); | |
const co = require("co"); | |
const userId = "blarg"; | |
co(function* () { | |
let rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); |
This file contains hidden or 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 Promise = require("bluebird"); | |
var readline = require("mz/readline"); | |
var userId = "blarg"; | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
rl.question("are you sure\nplease enter userId").then(function (answer) { | |
if (answer === userId) { |
This file contains hidden or 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
/* Continuation Passing | |
* Written in node pre-ES6 style */ | |
var readline = require("readline"); | |
var userId = "blarg"; | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
rl.question("Please re-enter the userId", confirmUserId); |