Skip to content

Instantly share code, notes, and snippets.

Avatar

Leroy Campbell artisonian

View GitHub Profile
View .gitignore
# For MacOS:
.DS_Store
# For TextMate
*.tmproj
tmtags
.tm_properties
# 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
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
artisonian / jsbin.dezig.css
Created May 28, 2014
React Starter Template
View jsbin.dezig.css
body { padding-top: 70px; }
@artisonian
artisonian / bashrc
Created Jun 6, 2014
Snippet of my .bashrc file
View bashrc
# Prompt colors
RESET_COLOR="\[\e[0m\]"
RED="\[\e[31m\]"
GREEN="\[\e[32m\]"
YELLOW="\[\e[33m\]"
BLUE="\[\e[34m\]"
MAGENTA="\[\e[35m\]"
CYAN="\[\e[36m\]"
WHITE="\[\e[37m\]"
BOLD_GRAY="\[\e[30;1m\]"
@artisonian
artisonian / index.js
Last active Aug 29, 2015
replace-tokens.js
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 = [].slice.call(arguments, 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
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
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 http://www.html5rocks.com/en/tutorials/es6/promises/
module.exports = function sequencePromises (promises, transformFn) {
function identity (x) { return x; }
return promises.reduce(function (sequence, promise) {
return sequence.then(function () {
return promise;