Skip to content

Instantly share code, notes, and snippets.

View artisonian's full-sized avatar

Leroy Campbell artisonian

View GitHub Profile
# For MacOS:
.DS_Store
# For TextMate
*.tmproj
tmtags
.tm_properties
# For emacs:
*~
> 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
@artisonian
artisonian / sha256-test.js
Created March 14, 2014 15:23
SHA-256 example
'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 March 14, 2014 15:27
Generate random strings with crypto.randomBytes
'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 23:03
React Starter Template
body { padding-top: 70px; }
@artisonian
artisonian / bashrc
Created June 6, 2014 19:15
Snippet of my .bashrc file
# 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 August 29, 2015 14:02
replace-tokens.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];

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 August 5, 2014 21:57
A JavaScript equivalent to Literate CoffeeScript
'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 August 29, 2015 14:05
Promise.all for parallel; this for series
'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;