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
#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 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 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 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 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 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 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 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.prototype.n文字ごとに文字列を挿入する = function (n, str) { | |
if (n == null || str == null) { | |
return String(this); | |
} | |
return this.replace(new RegExp('.{' + n + '}', 'g'), function (m) { | |
return m + str; | |
}); | |
}; |
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
String.prototype.title = function () { | |
return this.replace(/[A-Za-z]+/g, function (m) { | |
return m[0].toUpperCase() + m.slice(1).toLowerCase(); | |
}); | |
}; |
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
'hoge'.charAt(3); // => 'e' | |
'hoge'[3]; // => 'e' | |
'hoge'.charAt(4); // => '' | |
'hoge'[4]; // => undefined |