This file contains 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 printStackTrace = function(msg) { | |
try { | |
var ex = new Error(msg); | |
console.log(ex); | |
} catch (ex) {} | |
}; |
This file contains 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
window.jsonpCbs = {}; | |
var jsonp = function(uri, cb) { | |
var key = 'cb' + Math.floor( Math.random() * 100000 ); | |
var cb2 = function() { | |
delete window.jsonpCbs[key]; | |
cb.apply(null, arguments); | |
}; |
This file contains 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 ajax = function(uri, cb) { | |
var xhr = new XMLHttpRequest(); | |
//xhr.withCredentials = true; // uncomment to send cookies and stuff | |
xhr.open('POST', uri, true); // GET OR POST... | |
var cbInner = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
return cb(null, JSON.parse(xhr.response)); | |
} | |
cb('error requesting ' + uri); | |
}; |
This file contains 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 functionWithCallbackWorkflow = function(arg1, arg2, cb) { | |
try { | |
// DO STUFF, generating res | |
} catch (ex) { | |
return cb(ex); | |
} | |
cb(null, res); | |
}; |
This file contains 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(context) { | |
'use strict'; | |
var modName = 'stuff'; // used only if mod is a function and no CommonJS or AMD supported | |
// define your module here... can be a function or an object | |
var mod = {}; | |
// export | |
if (typeof module === 'object' && module.exports) { // CommonJS |
This file contains 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 minifyCss = function(s) { | |
s = s.replace('\n', ''); // remove newlines | |
s = s.replace(/\s+/g, ' '); // several whitespace to 1 spacebar | |
s = s.replace(/\s*([:;,{}])\s*/g, '$1'); // strips whitespace around :;,{} characters | |
s = s.replace(/\/\*(.|[\r\n])*?\*\//g, ''); // uses non-greedy matching *? to remove comments | |
return s; | |
}; |
This file contains 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
// https://github.com/learnboost/node-canvas | |
// https://github.com/LearnBoost/node-canvas/wiki | |
// sudo apt-get install libcairo2-dev | |
// npm install canvas | |
var http = require('http'); | |
var url = require('url'); | |
var Canvas = require('canvas'); | |
// http://stage.sl.pt:8080/?t=hi%20there |
This file contains 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
'\n'.charCodeAt(0); // 10 | |
String.fromCharCode(10); // '\n' |
This file contains 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 parseXSV = function(str, toObjects, sep) { | |
if (!sep) { sep = '\t'; } | |
var chars = str.split(''); | |
var lst = []; | |
var elem = []; | |
var field = []; | |
var inComplexField = false; |
This file contains 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
/** | |
* serves media files in the directory. | |
* by default won't refresh on file changes, use nodemon if you want that behavior | |
* 2014, [email protected] | |
*/ | |
var http = require('http'), | |
fs = require('fs'), |
OlderNewer