Skip to content

Instantly share code, notes, and snippets.

View bmeck's full-sized avatar

Bradley Farias bmeck

View GitHub Profile
@bmeck
bmeck / es7-async-await.sweet.js
Last active August 29, 2015 13:55
sweet.js macro for async function, and the potential async function*
//
// This assumes the runner supports
// - generators (for a transpiler see http://facebook.github.io/regenerator/)
// - Promises (for a polyfill see https://github.com/petkaantonov/bluebird)
//
// This does not need outside libraries to be loaded
//
// This survives direct eval semantics, unless you use regenerator, in which case the unwinding will cause variable renaming
//
@bmeck
bmeck / spawn-case.js
Created February 10, 2014 05:56
plug this into regenerator: the transpiled argument to spawn matches the interface to generators 1-1 so it has no issues
// spawn() taken unmodified from https://gist.github.com/Benvie/8327917
// See http://taskjs.org for the original.
function spawn(thunk) {
return new Promise(function(resolve, reject) {
var gen = thunk();
function _next(v) {
return handle(gen.next(v));
}
@bmeck
bmeck / run_it.sh
Last active August 29, 2015 13:57
Can't say how long I wanted to do this
#
# Still a lot to do, but it works!
# Been looking at how to do this for a long time
#
# Todo: good quality ecryption
# Todo: in memory resources (right now it is self extracting)
# Todo: check windows, should work but probably needs some tweaking
//
// Code to update bootstrap
//
var fs = require('fs');
var path = require('path');
var zlib = require('zlib');
var MAX_COMMENT_SIZE = 65535;
var CENTRAL_DIRECTORY_HEADER_SIZE = 22;

These are 2 different ideas about generating output in an async manner for generators.

I may be misunderstanding the problem though.

Array based iteration

function* mappedIterator() {
  var arr = [1,1,2,3];
 var results = [];
@bmeck
bmeck / flatter.js
Created May 30, 2014 22:35
needs testing (aka I need a remotely functional windows box)
//
// # flatter.js
//
// ## usage
//
// run `node flatter.js` in a node module directory
//
// generates commands to flatten a nested directory structure using symlinks
// flattened directories become named `node_modules/f~{{id}}`
// this does not run the commands, it merely prints them
env NAME=taco_service_1_Worker
env DESC=
env NODE_ENV=development
export NODE_ENV
env PORT=1032
export PORT
start on runlevel [2345]
stop on runlevel [!2345]
@bmeck
bmeck / evil.js
Last active August 29, 2015 14:06
making the world of JS a slightly worse place
;(function () {
// random is ... less random
var _random = Math.random.bind(Math);
Math.random = function random() {
return _random() / 1;
}
// setInterval becomes nested setTimeout
var _setTimeout = setTimeout;
@bmeck
bmeck / echoHttpRequest.js
Last active August 29, 2015 14:08 — forked from Marak/echoHttpRequest.js
Transparent log http req
module['exports'] = function echoHttp (hook) {
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
hook.req.pipe(hook.res);
Async Stack Traces in Chromium:
===
These are only turned on once the debugger starts up due to performance hits!
Implementing this requires the ability to integrate with V8 on a C++ level or a suitable debugging agent for the V8 debug APIs
### Setup