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
next = (x) -> | |
x.next().value |
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
iter = (x) -> | |
yield from x |
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
crc32 = do -> | |
table = | |
for n in [0..255] | |
for [0..7] | |
if n & 1 | |
n = 0xEDB88320 ^ n >>> 1 | |
else | |
n >>>= 1 | |
n | |
(str, crc = -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
str2hex = do -> | |
hex = ['0', '1', '2', '3', '4', '5', '6', '7', | |
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'] | |
hex = (hex[x >> 4] + hex[x & 15] for x in [0..255]) | |
(str) -> | |
(hex[c.charCodeAt()] for c in str).join '' | |
hex2str = (hex) -> | |
(String.fromCharCode parseInt hex[i...i + 2], 16 for i in [0...hex.length] by 2).join '' |
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
# Array sum helper function. | |
sum = (array) -> | |
array.reduce (x, y) -> x + y | |
md5 = do -> | |
# Per-round shift amounts. | |
s = [738695, 669989, 770404, 703814] | |
s = (s[i >> 4] >> i % 4 * 5 & 31 for i in [0..63]) | |
# Constants cache generated by sine. |
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
rotl = (a, b) -> | |
a << b | a >>> 32 - b |
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
sum = (arr, start = 0) -> | |
arr.reduce (x, y) -> | |
x + y | |
, start |
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
# Converts UCS2 to UTF8 | |
utf8_encode = (s) -> | |
unescape encodeURIComponent s | |
# Converts UTF8 to UCS2 | |
utf8_decode = (s) -> | |
decodeURIComponent escape s |
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
# Returns [hue, sat, value] when given red, green, blue. All 6 values are between 0...1. | |
rgb2hsv = (r, g, b) -> | |
v = Math.max r, g, b | |
x = v - Math.min r, g, b | |
[ | |
( if x is 0 | |
0 | |
else if v is r | |
(g - b) / x | |
else if v is g |
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
// Returns [hue, sat, val]. All 6 values are between 0...1. | |
function rgb2hsv(r, g, b) { | |
var v = Math.max(r, g, b), | |
x = v - Math.min(r, g, b); | |
return [ | |
( x == 0 ? 0 : | |
v == g ? (b - r) / x + 2 : | |
v == b ? (r - g) / x + 4 : | |
(g - b) / x + 6 |