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
# ref. http://stackoverflow.com/a/6521513 | |
Array::longest = -> | |
return @reduce ((prev, curr) -> return if prev > curr.length then prev else curr.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
String::ljust = (len = @length, ch = ' ') -> | |
result = this | |
while result.length < len | |
result += ch | |
return 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
randint = (max = 2) -> | |
return Math.floor Math.random() * max | |
[s, i] = [[], 10] | |
s.push randint() while i-- > 0 | |
console.log s.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
#include <stdio.h> | |
int main(void) { | |
int a[5] = { | |
1, 0, 5 | |
}; | |
int b[5] = { | |
[0] = 1, | |
[2] = 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
p %r...source |
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
Number.prototype.step = function (limit, step, callback) { | |
var n = Number(this); | |
if (typeof step === 'function') { | |
callback = step; | |
step = 1; | |
} | |
while (n <= limit) { | |
callback(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
#include <stdio.h> | |
int _abs(int n) { | |
return n & (1 << (sizeof(int) << 3 - 1)) ? ~n + 1 : n; | |
} | |
int main(void) { | |
printf("_abs(%d) = %d\n", -12, _abs(-12)); | |
return 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
'abs acos asin atan atan2 ceil cos exp floor log pow round sin sqrt tan'.split(' ').forEach(function (name) { | |
var slice = [].slice; | |
Number.prototype[name] = function () { | |
return Math[name].apply(null, [this].concat(slice.call(arguments))); | |
}; | |
}); |
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
Number.prototype.times = function (fn) { | |
Array.apply(null, { length: this }).forEach(fn); | |
}; | |
5..times(function (_, n) { | |
console.log(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
} if (1) { console.log('hoge'); // => 'hoge' |