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
//bad | |
var sequence = (function(data, temp){ | |
var len = data.length - 1; | |
for (var i = 0; i < len; ++i) { | |
temp.push(data[i+1] - data[i]); | |
} | |
return temp.join(','); | |
})((function(all, buf, user){ | |
var len = all.length; |
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
/** | |
* 估算有多少人投票 | |
*/ | |
Math.round([].slice.call( | |
document.querySelectorAll( | |
'tbody td[bgcolor="#ffffff"]:nth-child(2)' | |
), 1) | |
.map(function(n){ | |
return parseInt( | |
n.innerHTML.split(':(')[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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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
var Ring = (function() { | |
function Ring(list) { | |
this._list = [].slice.call(list, 0); | |
this._length = this._list.length; | |
this._curr = -1; | |
}; | |
Ring.prototype = { | |
rollTo: function(idx) { | |
this._curr = idx % this._length; | |
if (this._curr < 0) this._curr += this._length; |
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
/** | |
* Watch a directory recursively | |
* | |
* @param {String} dir | |
* @param {Function} cb | |
* | |
* watchRecursive('directory', function(current) { | |
* console.log(current, ' changed'); | |
* }); | |
*/ |
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
#!/usr/bin/env node | |
var fs = require('fs') | |
, path = require('path') | |
, exec = require('child_process').exec | |
, src_css = '../css/' | |
, target_css = '../../css/' | |
, src_js = '../js/' | |
, target_js = '../../js/' | |
, compiler = 'tools/compiler.jar'; |
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
#!/usr/bin/env node | |
var fs = require('fs') | |
, input = 'worklog.in' | |
, output = 'worklog.out'; | |
var spliters = { | |
block: 'Revision' | |
, field: [ |
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
#!/usr/bin/env node | |
/** | |
* Quick and dirty way to check if a website is gzipped | |
* Usage: | |
* ./isgzipped www.xxx.com | |
*/ | |
var exec = require('child_process').exec | |
, site = process.argv[2]; |
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
-- 第一印象:使用 Haskell 计算排列组合这样轻而易举。 | |
[ [a,b,c] | a <- [1..10], b <- [1..10], c <- [1..10] ] | |
[ [a,b,c] | a <- [1..10], b <- [1..a], c <- [1..b] ] | |
[ [a,b,c] | a <- "abc", b <- "abc", c <- "abc" ] | |
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
var fs = require('fs') | |
, http = require('http') | |
, path = require('path') | |
, cheerio = require('cheerio'); | |
var archive = 'http://apod.nasa.gov/apod/archivepix.html' | |
, base = path.dirname(archive) + '/' | |
, target = 'archive/english/'; |