Skip to content

Instantly share code, notes, and snippets.

View myndzi's full-sized avatar

Kris Reeves myndzi

  • Sigma Bold
  • Olympia, WA
View GitHub Profile
var Promise = require('bluebird');
Promise.extend = function(method, fn) {
var Promise = this;
Promise.prototype[method] = function Promise$_Proxy() {
var $_len = arguments.length;
var args = new Array($_len + 1); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i + 1] = arguments[$_i];}
var bound = this._isBound() ? this._boundTo : null;
return this._then(function(obj) {
function makeOutputDir(inWC, outWC, dir) {
if (outWC.indexOf('/**/') === -1) return outWC;
var outMask = path.basename(outWC);
inWC = path.dirname(inWC)+'/';
outWC = path.dirname(outWC)+'/';
dir = path.normalize(dir);
var inSplit = inWC.split('/**/'),
'use strict';
var fez = require('fez');
module.exports.default = function (rule, done) {
setImmediate(function () {
rule.each('src/*.js', fez.mapFile('dst/*.js'), function () {});
done();
});
};
'use strict';
var assert = require('assert');
var regex = /^(\/?(([^/*]+\/)*(\*\*(\/|$))?)?)?([^/*]*(\*([^*/]*))?)$/;
regex.verify = function () {
var success = [
'/foo/bar',
'/foo/bar/',
var prompt = require('promised-prompt'),
Promise = prompt.Promise;
prompt({
required: true
}).ask('db type?', {
key: 'db',
type: 'multi',
default: 'pg',
validator: [ 'pg' ]
var Promise = require('bluebird'),
ie = require('int-encoder'),
crypto = require('crypto');
var alpha = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()[{]}/?=+\\|-_\'",<.>;:';
function getRandomPass(len) {
var deferred = Promise.defer();
var bytes = Math.ceil(Math.log(alpha.length)/Math.log(256)*len);
'use strict';
module.exports = function (app, opts) {
var fs = require('fs'),
path = require('path'),
join = path.join,
Promise = require('bluebird'),
extend = require('jquery-extend'),
dust = opts.helpers ?
require('dustjs-helpers') :
@myndzi
myndzi / gist:8940959
Created February 11, 2014 18:28
Don't know if useful
'use strict';
var Promise = require('bluebird');
module.exports = getStreamData;
// return ascii character value from two ascii character values in hex representation
function fromHex(b1, b2) {
b1 -= 48; if (b1 > 9) { b1 -= 7; } // A -> 10
b2 -= 48; if (b2 > 9) { b2 -= 7; }
@myndzi
myndzi / gist:8985931
Last active August 29, 2015 13:56
Generically pass a config object into the body of an HTML document rendered by Dust
// in the app setup:
dust.helpers.config = function (chunk, ctx, bodies, params) {
var data = ctx.get('config');
if (!data) return chunk;
var str = JSON.stringify(data).replace("</script>", "<'+'/script>");
str = "<script>function CONFIG() { return JSON.parse('"+str+"'); }</script>";
return chunk.write(str);
};
@myndzi
myndzi / gist:9026516
Last active August 29, 2015 13:56
React state update propagation helper
/* Call initially with arguments as a path from this.state
* to the key you want a callback to update:
*
* this will return a function to update this.state.foo:
* this.update('foo')
*
* and this will return one to update this.state[0].bar:
* this.update('state', 0, 'bar')
*
* All arguments are optional; this returns a callback