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 debounce(func, wait, immediate) { | |
var timeout; | |
return function() { | |
var context = this, | |
args = arguments; | |
clearTimeout(timeout); | |
timeout = setTimeout(function() { | |
timeout = null; | |
if (!immediate) { | |
func.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
// cross browser window width | |
var winWidth = function() { | |
var w = 0; | |
// IE | |
if (typeof( window.innerWidth ) != 'number') { | |
if (!(document.documentElement.clientWidth === 0)) { |
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 ack(m,n) { | |
return (m == 0) ? | |
n + 1 : | |
(m > 0 && n==0) ? | |
ack(m-1,1) : | |
(m > 0 && n > 0) ? | |
ack(m - 1, ack(m,n-1)) : | |
undefined; | |
} |
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("ack(3, 4):", ack(3, 4)) | |
} | |
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 findIds(arr, filterFn) { | |
var results = arr.filter(filterFn); | |
results.timestamp = new Date(); | |
return result; | |
} | |
var ids = [0, 1, 2, 8, 4, 4, 5, 6, 7, 8, 9]; | |
var filtered = findIds(ids, function(x) { | |
return (x == 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
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
var array = [0, 1, 2]; | |
var weekDays = ['sun','mon','tues','wed','thurs','fri','sat']; | |
var str = "test"; | |
var obj = {}; | |
for (var i = 0; i < array.length; i++) { | |
var test = array[i]; | |
} |
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
// iterative approach | |
function binarySearch(arr, searchElement) { | |
var minIndex = 0; | |
var maxIndex = arr.length - 1; | |
var currentIndex; | |
var currentElement; | |
while (minIndex <= maxIndex) { | |
currentIndex = (minIndex + maxIndex) / 2 | 0; |
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> |