Skip to content

Instantly share code, notes, and snippets.


Leroy Campbell artisonian

View GitHub Profile
View .gitignore
# For MacOS:
# For TextMate
# For emacs:
View gist:9354289
> winston-mongodb@0.4.3 test /Users/leroy/repos/git/winston-mongodb
> vows test/*-test.js --spec
♢ winston-mongodb
An instance of the MongoDB Transport when passed valid options
✓ should have the proper methods defined
An instance of the MongoDB Transport the log() method when passed primitive metadata
View sha256-test.js
'use strict';
var assert = require('assert');
var fs = require('fs');
var crypto = require('crypto');
var stream = require('stream');
var littleSha = crypto.createHash('sha256');
var message = new Buffer('this is a small message');
artisonian / shortid.js
Created Mar 14, 2014
Generate random strings with crypto.randomBytes
View shortid.js
'use strict';
var crypto = require('crypto');
var stream = require('stream');
function radixId (radix, callback) {
crypto.randomBytes(4, function (err, buf) {
if (err) { return callback(err); }
try {
artisonian / jsbin.dezig.css
Created May 28, 2014
React Starter Template
View jsbin.dezig.css
body { padding-top: 70px; }
artisonian / bashrc
Created Jun 6, 2014
Snippet of my .bashrc file
View bashrc
# Prompt colors
artisonian / index.js
Last active Aug 29, 2015
View index.js
// `replaceTokens` is a modification of Crockford's `String.prototype.supplant`
// which takes works on an object/array (if given as the second argument)
// or a variable number of replacements.
module.exports = function replaceTokens (tmpl/*, replacements... */) {
var args = [], 1);
if (args[0] != null && (Array.isArray(args[0]) || typeof args[0] === 'object')) {
args = args[0];
return tmpl.replace(/\{([^{}]*)\}/g, function (match, index) {
var result = args[index];
View flux-example.litcoffee

Flux Dispatcher Example

This code is a fleshed-out version of the example [here][flux-docs]. Make sure to build Flux before running this example:

cd node_modules/flux
npm install
cd ../..
npm start
artisonian / erudite.js
Created Aug 5, 2014
A JavaScript equivalent to Literate CoffeeScript
View erudite.js
'use strict';
var fs = require('fs');
var os = require('os');
var vm = require('vm');
var marked = require('marked');
var argv = require('minimist')(process.argv.slice(2));
var usage = function () {
var helpText = [
artisonian / sequence-promises.js
Last active Aug 29, 2015
Promise.all for parallel; this for series
View sequence-promises.js
'use strict';
var Promise = require('es6-promise');
// See
module.exports = function sequencePromises (promises, transformFn) {
function identity (x) { return x; }
return promises.reduce(function (sequence, promise) {
return sequence.then(function () {
return promise;