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
function stringifyJSON(obj) { | |
var keyValuePair = []; | |
switch(Object.prototype.toString.call(obj)) { | |
case '[object Object]': | |
for(var i in obj) { | |
if(obj.hasOwnProperty(i)) { | |
keyValuePair.push('"' + i + '":' + stringifyJSON(obj[i])); | |
} | |
} |
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, sys | |
def convert(filepath, in_encode = "GBK", out_encode = "UTF8"): | |
try: | |
in_content = open(filepath).read() | |
out_content = in_content.decode(in_encode).encode(out_encode) | |
open(filepath, 'w').write(out_content) | |
print "[OK] Convert " + filepath | |
except: | |
print "[ERROR] Convert " + filepath |
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
function assert(expectation, fn) { | |
var args = Array.prototype.slice.call(arguments, 2); | |
var ret = fn.apply(fn, args); | |
if(ret === expectation) { | |
return ret; | |
} else { | |
throw new TypeError("调用" + fn.name + | |
"函数时,返回值" + ret + "与预期的" + expectation + "不同"); | |
} |
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
function benchmark (times) { | |
var index = Math.floor(Math.random()*times); | |
function fn (elem, i, array) { | |
array[i] = Math.sqrt(array[i]); | |
return true; | |
} | |
var a = []; | |
var b = []; |
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
function fibonacci (n) { | |
if (n < 2) { | |
return n; | |
} else if (fibonacci.cache) | |
fibonacci.cache[n] = fibonacci.cache[n] || fibonacci(n-1) + fibonacci(n-2); | |
return fibonacci.cache[n]; | |
} else { | |
return fibonacci(n-1) + fibonacci(n-2); | |
} | |
} |
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 solves = []; | |
var ans = []; | |
function solve_eight_queens (ans, line) { | |
if(line >== 8) { | |
solves.push(ans); | |
return true; | |
} else { | |
for (var row = 0; row < 8; ++row) { | |
var fine = true; |
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
/* | |
* 根据GB11643-1999的规则对身份证号码正确性进行校验 | |
* 如果身份证中的日期信息在系统时间之后,也不能通过校验 | |
*/ | |
function checkChineseID(id) { | |
id += ''; | |
if(/^\d{15}(\d\d[0-9X])?$/.test(id)) { | |
var year = 0, | |
month = 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
<html> | |
<head> | |
<title>test rotation</title> | |
<meta charset='utf-8'> | |
<script> | |
var PI_2 = Math.PI * 2; | |
var alpha = Math.PI / 180; | |
var cx = 400; | |
var cy = 300; | |
var ctrlRotation = 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
(function(){ | |
var canvas = document.getElementById('c'); | |
var ctx = canvas.getContext('2d'); | |
var mouse = { | |
x: 0, | |
y: 0, | |
fx: 0, | |
fy: 0, | |
left: false, |
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
<html> | |
<head> | |
<title>chrome arc</title> | |
<meta charset='utf-8'> | |
</head> | |
<body> | |
<canvas id='c' width='2000' height='1500'></canvas> | |