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
unless Function::bind? | |
Function::bind = (scope, args...) -> | |
target = this | |
if typeof target isnt "function" then throw new TypeError | |
bound = -> | |
unless this intanceof bound | |
return target.apply scope, [args..., arguments...] | |
F = -> | |
F.prototype = target.prototype | |
self = new F |
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
__extends = function(parent, child) { | |
var ctor = function(){}; | |
ctor.prototype = parent.prototype; | |
child.prototype = new ctor; | |
child.prototype.constructor = child; | |
if(typeof parent.extended === 'function') parent.extended(child); | |
child.__super__ = parent.prototype; | |
return child; | |
}; |
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
arrayEq = (a, b) -> | |
if a is b | |
# 0 isnt -0 | |
a isnt 0 or 1/a is 1/b | |
else if a instanceof Array and b instanceof Array | |
return no unless a.length is b.length | |
return no for el, idx in a when not arrayEq el, b[idx] | |
yes | |
else | |
# NaN is NaN |
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
forkNode = -> | |
args = process.argv[1..] | |
nodeArgs = [] | |
while (idx = args.indexOf '--nodejs') > -1 | |
nodeArgs = nodeArgs.concat args.splice(idx,2)[1].split(/\s+/) | |
spawn process.execPath, nodeArgs.concat(args), | |
cwd: process.cwd() | |
env: process.env | |
customFds: [0, 1, 2] |
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 F = function(){}; | |
F.prototype = klass.prototype; | |
var o = new F(); | |
klass.apply(o,arguments) | |
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
require 'openssl' | |
def hmac key, message | |
sha = OpenSSL::Digest::SHA256.new | |
blocksize = 64 # SHA256 uses a 64 byte (512 bit) block size | |
def xor str0, str1 # assuming strings are of equal length | |
b0 = str0.bytes.to_a | |
b1 = str1.bytes.to_a | |
result = [] |
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
// compute factorial of 5 | |
Y(function(self){ | |
return function(x){ | |
return x == 0 ? 1 : x * self(x - 1); | |
}; | |
})(5); // === 120 |
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
int random(int min, int max) { | |
if(min == max) return min; | |
if(min > max) { | |
int tmp = max; | |
max = min; | |
min = tmp; | |
} | |
int range = max - min + 1; | |
int randMax = RAND_MAX - ((RAND_MAX - range + 1) % range); |
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
// Lack of tail call optimization in JS | |
var sum = function(x, y) { | |
return y > 0 ? sum(x + 1, y - 1) : | |
y < 0 ? sum(x - 1, y + 1) : | |
x | |
} | |
sum(20, 100000) // => RangeError: Maximum call stack size exceeded | |
// Using workaround |
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
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
OlderNewer