This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toDate(str) { | |
// To map months to their numeric equivalent | |
var months = { | |
January : 0, | |
Feburary : 1, | |
March : 2, | |
April : 3, | |
May : 4, | |
June : 5, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatten(arry) { | |
var result = []; | |
for (var i = 0; i < arry.length; i++) { | |
if (typeof arry[i] === 'number') { | |
result.push(arry[i]); | |
} else { | |
result = result.concat(flatten(arry[i])); | |
} | |
} | |
return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function log() { | |
var stack; | |
try { | |
throw new Error(); | |
} catch (e) { | |
stack = e.stack.split('\n')[2].match(/\s+at\s+(.+)/)[1] + ':\n\t'; | |
} | |
var args = Array.prototype.slice.call(arguments); | |
args.unshift(stack); | |
console.log.apply(console, args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cwd = process.cwd(); | |
var reg = new RegExp(/([^()]+)/); | |
var colors = { | |
black : '0', | |
red : '1', | |
green : '2', | |
yellow : '3', | |
blue : '4', | |
magenta : '5', | |
cyan : '6', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $q = require('q'); | |
function catchIfNeeded(name) { | |
var caught = false; | |
var promise = $q.try(function() { | |
throw new Error('Catch me!'); | |
}).catch(function(err) { | |
// This function is executed on the next "tick" of the event loop | |
if (caught) { | |
throw err; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PubSub = (function PubSub() { | |
var subscriptions = {}; | |
var publications = {}; | |
var index = 0; | |
function sub(event, callback) { | |
// If already subbed, return the id | |
var subId = getSubId(callback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"segredo": { | |
"key": "1234567890", | |
"secret": "asdfghjkl" | |
}, | |
"port": 3000, | |
"db": { | |
"path": "db.connection.string" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.dbCreate('test'); | |
r.db('test').tableCreate('one'); | |
r.db('test').tableCreate('two'); | |
r.db('test').tableCreate('three'); | |
r.range(300).forEach(function(i) { | |
return r.db('test').table('one').insert({ uid: 'a1' }) | |
}); | |
r.range(300).forEach(function(i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Redis pubsub</title> | |
</head> | |
<body> | |
<button id="add">Add 1</button> | |
<p><span id="count">?</span> click(s)</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<form action="/upload" method="post" enctype="multipart/form-data"> | |
<input type="file" name="upload-file"> | |
<input type="submit" value="Upload"> |