This file contains hidden or 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 = { | |
counter: {}, | |
count: function count(key) { | |
if (this.counter[key] === undefined) this.counter[key] = 0 | |
this.counter[key]++ | |
}, | |
output: function output() { | |
for (var key in this.counter) { | |
console.log(key + ' was called ' + this.counter[key] + ' times') | |
} |
This file contains hidden or 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 joinCalls(doneAfter, callback) { | |
var counter = 0 | |
return function wrapped() { | |
if (++counter === doneAfter) callback() | |
} | |
} | |
function joinCallsSingleValue(doneAfter, joinValuesFn, callback) { | |
var counter = 0 | |
var result = null |
This file contains hidden or 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
//fields have directions associated with their elements | |
//2d arrays of vectors | |
function makeBlankField(x, y) { | |
var map = [] | |
for (var i = 0; i < y; i++) { | |
var row = [] | |
for (var j = 0; j < x; j++) { | |
row.push({ | |
x: 0, | |
y: 0 |
This file contains hidden or 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 createMatrix(m, n) { | |
var res = [] | |
for (var i = 0; i < m; i++){ | |
var row = [] | |
for (var j = 0; j < n; j++) { | |
row.push({ | |
length: 0, | |
sequences: [] | |
}) | |
} |
This file contains hidden or 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
hammer () { | |
if [ -z "$1" ] | |
then | |
echo "an address is required for hammering" | |
else | |
echo "hammering ${1}"; | |
yes ${1} | xargs curl -s > /dev/null; | |
fi | |
} |
This file contains hidden or 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
bclement:primes bclement$ gcc -O666 primes.c | |
bclement:primes bclement$ time ./a.out | |
There is no sum for 0! | |
There is no sum for 1! | |
There is no sum for 2! | |
There is no sum for 3! | |
There is no sum for 4! | |
There is no sum for 5! | |
There is no sum for 6! | |
There is no sum for 7! |
This file contains hidden or 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
# max subsequence sum | |
def max_sub_value(li): | |
current_max = 0 | |
total_max = 0 | |
for x in li: | |
current_max = max(current_max + x, 0) | |
total_max = max(current_max, total_max) | |
return total_max | |
print max_sub_value([1, 2, 3, -4, 5]) |
This file contains hidden or 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 WIDTH = window.innerWidth - 20, | |
HEIGHT = window.innerHeight - 20; | |
var VIEW_ANGLE = 45, | |
ASPECT = WIDTH/HEIGHT, | |
NEAR = 0.1, | |
FAR = 10000; | |
var camera = | |
new THREE.PerspectiveCamera( |
This file contains hidden or 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 generateFunctions() { | |
return function () { | |
break bad; | |
} | |
bad: console.log("I'm alive!") | |
} | |
generateFunctions()() |
This file contains hidden or 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 inject(deps){ | |
with (deps) { | |
return function (output){ | |
print(output) | |
} | |
} | |
})({print:console.log})(1) |