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
module.exports.doSomething = function() { | |
return function(req, res, next) { | |
console.log('do something...'); | |
//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
function parenthesesAreBalanced(s) | |
{ | |
var parentheses = "[]{}()", | |
stack = [], //Parentheses stack | |
i, //Index in the string | |
c; //Character in the string | |
for (i = 0; c = s[i++];) | |
{ | |
var bracePosition = parentheses.indexOf(c), |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta name="description" content="minimal PDK player example" /> | |
<meta name="tp:EnableExternalController" content="true" /> | |
<meta charset="utf-8"> | |
<title>minimal PDK player</title> | |
</head> | |
<body> |
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
async = require("async"); | |
var results = []; | |
async.each(states, | |
function(state, callback){ | |
var url = baseUrl + state.name; | |
request(url, function(err, res, body){ | |
results.push(data); | |
callback(); | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="adaptive img solution for above the fold images - using inline js" /> | |
<meta charset="utf-8"> | |
<title>Adaptive Img - JS Bin</title> | |
</head> | |
<body> | |
<img class="js-adaptive-img" src='//:0' | |
data-bp0='http://media2.s-nbcnews.com/j/newscms/2014_41/708631/141009-liberia-ebola-jsw-1158a_b58372304e3003a1bed177b8d90e126d.nbcnews-fp-320-320.jpg' |
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
//input: [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []] | |
function flatten(list) { | |
return list.reduce(function (acc, val) { | |
return acc.concat(val.constructor === Array ? flatten(val) : val); | |
}, []); | |
} | |
// output: [1, 2, 3, 4, 5, 6, 7, 8] |
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
/* input | |
---------- Ice and Fire ------------ | |
fire, in end will world the say Some | |
ice. in say Some | |
desire of tasted I've what From | |
fire. favor who those with hold I | |
... elided paragraph last ... | |
Frost Robert ----------------------- |
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
String.prototype.repeat = function(n) { | |
return new Array(1 + (n || 0)).join(this); | |
} | |
console.log("ha".repeat(5)); // hahahahaha | |
// this is built-in to ES6 |
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
// quick hack to track iframe clicks (for pdkPlayer) | |
$('iframe').each(function (i,el) { | |
var iframe = el; | |
function addIframeClickEvent() { | |
//console.log('### found iframe', iframe.id); | |
$(iframe).contents().find('body').on('click', function (event) { | |
console.log('### click iframe', new Date().getMinutes()+'m', new Date().getSeconds()+'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
function delayedIterator(array, interval, callback, done) { | |
var index = 0; | |
var iterator = function iterator() { | |
setTimeout(function () { | |
if(array[index]) { | |
callback(array[index], index); | |
index++; | |
iterator(); | |
} | |
else { |