Skip to content

Instantly share code, notes, and snippets.

'use strict';
var assert = require('assert');
var regex = /^(\/?(([^/*]+\/)*(\*\*(\/|$))?)?)?([^/*]*(\*([^*/]*))?)$/;
regex.verify = function () {
var success = [
'/foo/bar',
'/foo/bar/',
'use strict';
var fez = require('fez');
module.exports.default = function (rule, done) {
setImmediate(function () {
rule.each('src/*.js', fez.mapFile('dst/*.js'), function () {});
done();
});
};
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('/**/'),
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) {
Setup:
// (actually this is module.exports)
var Prompt = new Blackbird(function (Promise) {
function Prompt(opts, ctx) {
this._opts = opts || { };
// copy over initialization variables
ctx = ctx || { };
for (var key in ctx) {
if (ctx.hasOwnProperty(key)) {
function circle(buffer, cx, cy, radius) {
var error = -radius,
x = radius,
y = 0,
lastY;
while (x >= y) {
lastY = y;
error += y;
#include <v8.h>
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
#include <unistd.h>
#include <string>
#include <map>
#include <exception>
#include <exiv2/image.hpp>
#include <exiv2/exif.hpp>
@myndzi
myndzi / gist:7164515
Last active December 26, 2015 14:19
Pseudo-code implementation of IRC-like flood control
var api = require('socket.io')
, io = null;
var Message = require('./message')
, User = require('./user');
var waitDelay = 1
, linePenalty = 2
, burstThreshold = 10
, numCharsPenalty = 120
* In 'funcs.js':
module.exports = {
generatePseudoRandomToken: generatePseudoRandomToken,
cookieWatcher: cookieWatcher
};
function generatePseudoRandomToken() {
require('crypto').randomBytes(48, function(ex, buf) {
var token = buf.toString('hex');
});
@myndzi
myndzi / gist:6101585
Last active December 20, 2015 08:39 — forked from anonymous/gist:6101412
Friend.findOne({
userId: req.signedCookies.userid
}, function (err, signedInUser) {
var friends = signedInUser.friends.map(
function (a) { return { user: a, type: 'friend' }; }
),
sentRequests = signedInUser.request_sent_to.map(
function (a) { return { user: a, type: 'sent' }; }
),