Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
matthewmueller / gen.js
Last active August 29, 2015 13:56
understanding generators
/**
* Excerpt from: Analysis of generators and other async patterns in node
* URL: http://spion.github.io/posts/analysis-generators-and-other-async-patterns-node.html#a-gentle-introduction-to-generators
*
* When next is invoked, it starts the execution
* of the generator. The generator runs until it
* encounters a yield expression. Then it pauses
* and the execution goes back to the code that
* called next.
@matthewmueller
matthewmueller / flow-based-programming.md
Last active August 29, 2015 14:05
Some quick notes on flow-based programming

Flow-based Programming is all about reacting to event sources. Event sources in the browser might be:

  • A DOM event
  • AJAX call
  • Onload initial data passing
  • Local DB fetch (local storage, indexdb)

In order to build larger systems, nodes need to be chainable and flows need to be composable. I think the best way to do this in Javascript may look something like this:

@matthewmueller
matthewmueller / gulpnduo.js
Last active August 29, 2015 14:06
Duo gulp integration
/**
* Module Dependencies
*/
var debug = require('debug')('lapwing:build');
var relative = require('path').relative;
var resolve = require('path').resolve;
var extname = require('path').extname;
var uglify = require('gulp-uglify');
var Batch = require('better-batch');
@matthewmueller
matthewmueller / flow.js
Created November 25, 2014 01:32
Generator Flow
function *something(msg) {
msg += yield msg; // yields "a", returns "b"
msg += yield msg; // yields "ab", returns "c"
msg += yield msg; // yields "abc", returns "d"
return msg; // returns "abcd"
}
var gen = something('a');
console.log(gen.next().value); // a
console.log(gen.next('b').value); // ab

Keybase proof

I hereby claim:

  • I am matthewmueller on github.
  • I am matthewmueller (https://keybase.io/matthewmueller) on keybase.
  • I have a public key whose fingerprint is BFED 49E4 15E0 9C6E C008 3E7F 490F 7168 F0D0 85EB

To claim this, I am signing this object:

@matthewmueller
matthewmueller / inject.js
Created May 1, 2015 06:18
Testing injection mad science
var script = document.currentScript;
var sheet = script.getAttribute('sheet');
var el = document.createElement('div');
el.textContent = 'hi world!';
script.parentNode.replaceChild(el, script);
console.log('lol');
@matthewmueller
matthewmueller / promise.js
Last active August 29, 2015 14:27
Runthrough of Promise control flow
var a = new Promise(function (resolve, reject) {
reject(1)
})
function b_success() {
console.log('b: success', err);
// not called...
@matthewmueller
matthewmueller / Underscore templating with Express
Created March 25, 2011 01:52
Javascript: Use underscore templating to parse HTML files in Express
// Express with Underscore templating
app.register('.html', {
compile : function(str, options) {
return function(locals) {
return _.template(str, locals);
};
}
});
@matthewmueller
matthewmueller / gist:2018660
Created March 11, 2012 23:25
Javascript: step(fns...) - Tiny, flexible step function for running async functions in series
/*
Step - tiny, but flexible step library
Usage:
var first = function(next) {
...
return next(null, name, date);
}
@matthewmueller
matthewmueller / gist:2018609
Created March 11, 2012 23:18
Javascript: after(len) - counter used for async iteration
/*
Counter used for async calls
Example:
var files = ['a', 'b'];
finished = after(files.length);
finished() // false
finished() // true