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 q = require('q') | |
| function generatorify(fn, context) { | |
| return function() { | |
| var deferred = q.defer(), | |
| callback = makeCallback(deferred), | |
| args = Array.prototype.slice.call(arguments).concat(callback); | |
| fn.apply(context, args); | |
| return deferred.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
| // based off of https://gist.github.com/creationix/5544019 | |
| // these could probably be condensed more, but I'm just doing this | |
| // quickly | |
| function call(func) { | |
| var args = Array.prototype.slice.call(arguments, 1); | |
| return function(callback) { | |
| args.push(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
| tim@touchsmart:~/Code$ nvm use v0.11.2-generators | |
| Now using node v0.11.2-generators | |
| tim@touchsmart:~/Code$ node --harmony testgen.js | |
| <Buffer 76 61 72 20 66 73 20 3d 20 72 65 71 75 69 72 65 28 27 66 73 27 29 3b 0a 66 75 6e 63 74 69 6f 6e 20 72 65 61 64 46 69 6c 65 28 70 61 74 68 2c 20 65 6e 63 ...> | |
| Sleeping for 2000ms... | |
| Done |
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 q = require('q') | |
| function generatorify(fn, context) { | |
| return function() { | |
| var deferred = q.defer(), | |
| callback = makeCallback(deferred), | |
| args = Array.prototype.slice.call(arguments).concat(callback); | |
| fn.apply(context, args); | |
| return deferred.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
| // clean and pure: | |
| function cons(x, y) { | |
| return function(pick) { | |
| return pick(x, y); | |
| } | |
| } | |
| // does more stuff: | |
| function cons(x, y) { | |
| var fn = function(pick) { |
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 cons(x, y) { | |
| return function(w) { return w(x, y) }; | |
| }; | |
| function car(z) { | |
| return z(function(x, y) { return x }); | |
| }; | |
| function cdr(z) { | |
| return z(function(x, y) { return y }); |
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
| /** | |
| * Educational Stack-based VM. | |
| * | |
| * See also Register-based VM example: https://gist.github.com/DmitrySoshnikov/6407781 | |
| * | |
| * by Dmitry Soshnikov <[email protected]> | |
| * MIT Stye License (C) 2015 | |
| */ | |
| var _stack = []; // main evaluation stack |
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
| // another kind of flattening; see: http://blog.vullum.io/javascript-flow-callback-hell-vs-async-vs-highland/ | |
| var express = require('express') | |
| var fs = require('fs') | |
| var app = express() | |
| app.post('/process-file', onProcessFile) | |
| function onProcessFile(req, res) { | |
| var inputFile = 'input.txt' |
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 express = require('express'); | |
| var _ = require('highland'); | |
| var fs = require('fs'); | |
| var app = express(); | |
| function chain(s, f) { | |
| return s.flatMap(_.wrapCallback(f)) | |
| } | |
| app.post('/process-file', function(req, res) { |
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
| // browserify | |
| var browserify = require('browserify'); | |
| var es6ify = require('es6ify'); | |
| // gulp stuff | |
| var gulp = require('gulp'); | |
| var livereload = require('gulp-livereload'); | |
| var source = require('vinyl-source-stream'); | |
| var jshint = require('gulp-jshint'); | |
| var livereload = require('gulp-livereload'); | |
| var watch = require('gulp-watch'); |