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.tr = function (search, replace) { | |
var pattern = new RegExp('[' + search + ']', 'g'); | |
return this.replace(pattern, function (m) { | |
return replace[search.indexOf(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
import os; os.kill(os.getpid(), 9) |
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 randint = function (min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}; | |
var swap = function (obj, i, j) { | |
var tmp; | |
tmp = obj[i]; | |
obj[i] = obj[j]; | |
obj[j] = tmp; |
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
class Unsafe | |
{ | |
static unsafe void Main() | |
{ | |
int a = 100; | |
int *p = &a; | |
*p = 200; | |
System.Console.WriteLine("{0}", a); |
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.defineProperty(Array.prototype, 'toString', { | |
value: (function () { | |
var start = '['; | |
var end = ']'; | |
var delimiter = ', ' | |
function toString() { | |
var index = 0; | |
var len = this.length; | |
var 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
var divmod = function (base, exp, mod) { | |
var result = 1; | |
while (exp > 0) { | |
if ((exp & 1) === 1) { | |
result = result * base % mod; | |
} | |
exp >>= 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
var obj = Object.create(Object.prototype, { | |
prop: { set: undefined } | |
}); | |
console.log(obj.prop); // => undefined | |
obj.prop = 5; | |
console.log(obj.prop); // => undefined |
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 add = function (x, y) { | |
return x + y; | |
}; | |
var add5 = partial(add, 5); | |
add5(10); // => 15 | |
// 素直に Function#bind を使いましょう | |
var add5 = add.bind(null, 5); | |
add5(10); // => 15 |
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> | |
#include <stdarg.h> | |
int sum(int n, ...) { | |
int i; | |
int result = 0; | |
va_list args; | |
va_start(args, 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
s = 'ABCD' | |
# 1 | |
i = 0 | |
result = [] | |
while True: | |
if i >= len(s): | |
break | |
result.append((i, s[i])) |