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 url = require('url'); | |
app.use(function(req, res, next) { | |
req.generateLink = function(pathname) { | |
return url.format({ | |
protocol: req.protocol, | |
host: req.get('Host'), | |
pathname: pathname | |
}); | |
}; | |
next(); |
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 path = require('path'); | |
var fs = require('fs'); | |
var cheerio = require('cheerio'); | |
var createTemplate = function(id, markup) { | |
var $ = cheerio.load('<script type="text/ng-template"></script>'); | |
$('script').attr('id', id).html(markup).html(); | |
return $.html(); | |
}; |
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 require = (function() { | |
var rComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s))/mg; | |
var rArguments = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; | |
var getArguments = function(fn) { | |
// https://gist.github.com/thebyrd/6924190 | |
var argNames = fn.toString().replace(rComments,'').match(rArguments)[1]; | |
return argNames ? argNames.split(/,/) : []; | |
}; | |
return function(dependencies, fn) { |
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
location.search.substr(1).split("&").reduce(function(o, pair) { | |
pair = pair.split("="); | |
o[pair[0]] = pair[1] && decodeURIComponent(pair[1]); | |
return o; | |
}, {}); |
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 isValidUrl = (function() { | |
var protocols = ["http", "https", "ftp"]; | |
var requireProtocol = false; | |
var requireTLD = true; | |
var pattern = new RegExp('^(?!mailto:)(?:(?:' + protocols.join('|') + ')://)' + (requireProtocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + (requireTLD ? '' : '?') + ')|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i'); | |
return function(str) { | |
return (typeof str === "string") && str.length < 2083 && pattern.test(str); | |
} | |
}()); |
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/felixge/node-mysql/blob/master/lib/protocol/SqlString.js | |
function escapeSqlString(text) { | |
return text.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { | |
switch(s) { | |
case "\0" : return "\\0"; | |
case "\n" : return "\\n"; | |
case "\r" : return "\\r"; | |
case "\b" : return "\\b"; | |
case "\t" : return "\\t"; | |
case "\x1a": return "\\Z"; |
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
_.mixin({ | |
whenOnline: function(fn, context) { | |
return function() { | |
var args = arguments; | |
context = context || this; | |
if (navigator.onLine) { | |
fn.apply(context, args); | |
} else { | |
window.addEventListener('online', function online() { | |
fn.apply(context, args); |
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 geolocate = function(callback) { | |
callback = typeof callback === "function" ? callback : function(){}; | |
if ('Geo' in window) { | |
callback(window.Geo); | |
} else { | |
var script = document.createElement('script'); | |
script.src = "https://geoiplookup.wikimedia.org/"; | |
script.onload = function() { callback(window.Geo) }; | |
document.head.appendChild(script); | |
} |
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
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<label for="uploadFile">UPLOAD</label> | |
<input type="file" id="uploadFile"/> | |
<script> | |
$("input[type='file']").on("keyup", function(e) { | |
if (e.keyCode === 27) this.blur(), e.stopPropagation(); | |
}); | |
$(document).on("keyup", function(e) { |
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
[ | |
{ | |
"uid": "keywordSELECT", | |
"subtext": "[FQL keyword]", | |
"text": "SELECT" | |
}, | |
{ | |
"uid": "keywordFROM", | |
"subtext": "[FQL keyword]", | |
"text": "FROM" |