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 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 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
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 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 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 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 abs(n) { | |
return n >= 0 ? 0+n : -n; | |
} |
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 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 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
findElem elem [] = Nothing | |
findElem elem (x:xs) | |
| x == elem = Just 0 | |
| otherwise = findElem elem xs >>= Just . (1 +) |
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 Program () where | |
import Control.Monad | |
main :: IO () | |
main = let | |
a = [1..100] | |
fizz = do | |
s <- a | |
guard $ s `mod` 3 == 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 () { | |
function define(owner, prop, value) { | |
if (typeof owner[prop] !== "function") { | |
owner[prop] = value; | |
} | |
} | |
define(Object, "keys", function (object) { | |
var k, | |
result = []; |
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
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
inline int bit2(char *bits) { | |
int n = 0; | |
assert(*bits); | |
for (; *bits != '\0'; bits++) { | |
assert(*bits == '0' || *bits == '1'); |
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
isqrt :: Integer -> Integer | |
isqrt n | n >= 0 = f n 0 | |
| otherwise = error "domain error" | |
where | |
f n i | n < 0 = i - 1 | |
|otherwise = f (n - (i * 2 + 1)) (i + 1) |