View serveMedia.js
/** | |
* serves media files in the directory. | |
* by default won't refresh on file changes, use nodemon if you want that behavior | |
* 2014, jose.pedro.dias@gmail.com | |
*/ | |
var http = require('http'), | |
fs = require('fs'), |
View queryString.js
var parseQueryString = function(url) { | |
var aParams = {}; | |
if (url.match(/\?(.+)/i)) { | |
var queryStr = url.replace(/^(.*)\?([^\#]+)(\#(.*))?/g, '$2'); | |
if (queryStr.length > 0) { | |
var i, I, pairVar, aQueryStr = queryStr.split(/[;&]/); | |
I = aQueryStr.length; | |
for (i = 0; i < I; ++i) { | |
pairVar = aQueryStr[i].split('='); | |
aParams[decodeURIComponent(pairVar[0])] = (typeof(pairVar[1]) !== 'undefined' && pairVar[1]) ? decodeURIComponent(pairVar[1]) : ''; |
View example.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JSONTree example</title> | |
<link type="text/css" rel="stylesheet" href="jsontree.css"></link> | |
<script type="text/javascript" src="jsontree.js"></script> | |
</head> | |
<body> |
View cp-credentials.js
module.exports = { | |
"email": "<your email here>", | |
"password": "<your pass here>" | |
}; |
View parallelCbs.js
// process items in parallel thingy | |
var parallelCbs = function(items, itemFn, cb) { | |
var left = items.length; | |
var res = new Array(left); | |
var cb2 = function(err, res) { // to enforce the main cb is not called more than once | |
if (this.called) { return; } | |
this.called = true; | |
this.cb(err, res); | |
}.bind({cb:cb, called:false}); |
View getMyIPs.js
var os = require('os'); | |
var getMyIPs = function() { | |
var ips = {}; | |
var ifaces = os.networkInterfaces(); | |
var onDetails = function(details) { | |
if (details.family === 'IPv4') { | |
ips[ dev ] = details.address; | |
} |
View removeCycles.js
var removeCycles = function(o) { | |
var seen = []; | |
var s = JSON.stringify(o, function(k, v) { | |
if (v !== null && typeof v === 'object') { | |
if (seen.indexOf(v) !== -1) { | |
//return; | |
v = '[removed]'; | |
} | |
else { |
View argumentsSnippet.js
var ctx = this; // this can be skipped if you don't care about the context | |
var argsL = arguments.length; | |
var args = new Array(argsL); // optimizable arguments-to-array | |
for(var i = 0; i < argsL; ++i) { | |
args[i] = arguments[i]; | |
} |
View myCoExperiment.js
'use strict'; | |
/*jshint esnext:true */ | |
let log = function(msg) { console.log(msg); }; | |
let now = function() { return Date.now(); }; |