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 'generator' | |
fibs = Generator.new {|g| | |
a = 0 | |
b = 1 | |
loop { | |
g.yield a | |
a, b = b, a + b | |
} | |
} |
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.prototype.curried = function (that) { | |
var f = this, value; | |
var T = function () { | |
value = f.apply(that, arguments); | |
return T; | |
}; | |
T.valueOf = function () { | |
return value; | |
}; | |
return T; |
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 ValueFinder() { | |
} | |
ValueFinder.NotFoundError = function () { | |
Error.apply(this, arguments); | |
}; | |
ValueFinder.NotFoundError.prototype = new Error(); | |
ValueFinder.prototype.find = function (array) { | |
if (array.length == 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
Object.defineProperties(Object, { | |
seal: { | |
configurable: true, | |
enumerable: false, | |
value: function (object) { | |
var properties = Object.getOwnPropertyNames(object); | |
properties.forEach(function (name) { | |
var desc = Object.getOwnPropertyDescriptor(object, name); | |
desc.configurable = false; | |
Object.defineProperty(object, name, desc); |
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 srand, rand; | |
(function () { | |
const a = 16807, b = 0, m = 2147483647; | |
var x = 1; | |
srand = function (seed) { | |
x = seed; | |
}; | |
rand = function () { | |
x = (a * x + b) % m; |
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 abs(n) { | |
return n >= 0 ? 0+n : -n; | |
} |
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 querySelectorAll; | |
// multiple scoped selector not supported yet. e.g. ">embed,>object" | |
(function () { | |
var toArray = function (nodes) { | |
return [].slice.call(nodes, 0); | |
}; | |
var squeezers = { | |
">": function (node) { | |
return toArray(node.children); |
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
findElem elem [] = Nothing | |
findElem elem (x:xs) | |
| x == elem = Just 0 | |
| otherwise = findElem elem xs >>= Just . (1 +) |
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 Program () where | |
import Control.Monad | |
main :: IO () | |
main = let | |
a = [1..100] | |
fizz = do | |
s <- a | |
guard $ s `mod` 3 == 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 () { | |
function define(owner, prop, value) { | |
if (typeof owner[prop] !== "function") { | |
owner[prop] = value; | |
} | |
} | |
define(Object, "keys", function (object) { | |
var k, | |
result = []; |