feature | Promises | streams | generators |
---|---|---|---|
asynchronous (can push from inner callbacks) |
true | true | false |
multiple push | false | true | true |
error catch | true | false | false |
error forwarding | true | false | true |
external dependency is a must | false | true | false |
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
private double det(IEnumerable<IEnumerable<double>> matrix) | |
{ | |
return | |
matrix.Any() | |
? | |
matrix | |
.Select((row, i) => | |
(i % 2 == 0 ? +1 : -1) | |
* row.First() | |
* det(matrix.Where((curRow, curI) => curI != i).Select(curRow => curRow.Skip(1))) |
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
console.log('Usage: phantomjs render.js URL [width=1024] [height=768] [out=render.png]'); | |
var args = require('system').args; | |
if (args.length < 2) { | |
phantom.exit(); | |
} | |
var page = require('webpage').create(); | |
var rect = page.clipRect = { |
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
function part(name, exec, deps) { | |
console.log(name + '...'); | |
var code = exec.toString(); | |
if (deps) { | |
exec = new Function(deps, 'return(' + code + ')()'); | |
} else { | |
deps = | |
code |
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 reportedHash = 'reported' in localStorage ? JSON.parse(localStorage.reported) : {}; | |
(function reportTweets() { | |
var newTweetsBar = document.querySelector('.new-tweets-bar'); | |
newTweetsBar && newTweetsBar.click(); | |
Array.prototype.map.call( | |
document.querySelectorAll('.original-tweet'), | |
function (tweet) { | |
return tweet.dataset |
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
function when(value, func) { | |
var promise = Promise.cast(value); | |
if (func) { | |
promise = promise.then(function (value) { | |
return Promise.cast(func(value)).then(function (newValue) { | |
return newValue === undefined ? value : newValue; | |
}); | |
}); | |
} |
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 stream = require('stream'); | |
var Rx = require('rx'); | |
var util = require('util'); | |
function ObservableStream(transform) { | |
stream.Duplex.call(this, {objectMode: true}); | |
this.subject = new Rx.Subject(); | |
this.observable = transform(this.subject); | |
this.subscription = null; |
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
// just for RequireBin | |
console.log = function () { | |
var pre = document.createElement('pre'); | |
pre.textContent = Array.prototype.map.call(arguments, function (arg) { | |
return typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg; | |
}).join(' '); | |
document.body.appendChild(pre); | |
}; | |
var esprima = require('esprima-fb'), ast; |
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
function Template(str, data) { | |
return str.replace(/\${([^}]+)}/g, (_, name) => data[name]); | |
} | |
var answer = 42; | |
(function () { | |
var answer = 60; | |
console.log(Template('Answer is ${answer}', {answer})); | |
})(); |
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
### Keybase proof | |
I hereby claim: | |
* I am RReverser on github. | |
* I am rreverser (https://keybase.io/rreverser) on keybase. | |
* I have a public key whose fingerprint is 3456 B5A0 0E7F 67D8 A049 5B85 7634 8879 1722 011A | |
To claim this, I am signing this object: |
OlderNewer