Skip to content

Instantly share code, notes, and snippets.

View yuanchuan's full-sized avatar

Yuan Chuan yuanchuan

View GitHub Profile
/**
例如 prezero(200) 返回 0200
*/
var prezero = function(number) {
var str = number.toString(10);
var len = str.length;
while((len++) < 4) {
str = '0' + str;
@yuanchuan
yuanchuan / Contract Killer 3.md
Created November 7, 2012 13:33 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer 3

Revised date: 07/11/2012

Between us [company name] and you [customer name]

Summary:

We’ll always do our best to fulfil your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

@yuanchuan
yuanchuan / gist:3998675
Created November 2, 2012 04:13
Experimental problem solving with MongoDB
/**
* Experimental problem solving with MongoDB
*
* 描述:
*
* 假设现在有百万级的数据,每个数据存储着用户的信息(可以是简易的信息),
* 每个数据中含有一个用户的ID,还有一个特殊数据,我们可以将这个数据叫做“等级”。
* 现在 我们的需求是:
* 1,根据一个用户ID能快速找出该用户信息
* 2,根据一个用户ID能快速找出比该用户的“等级”低的最靠近他的10名别的用户,和找出比该用户“等级”高的10名用户
@yuanchuan
yuanchuan / program1.js
Created August 10, 2012 07:42
判断QQ在不在线
/*========================================
* API (普通的方式)
*=======================================*/
check(qq, function(on) {
if (on) {
} else {
}
@yuanchuan
yuanchuan / gist:3232510
Created August 2, 2012 02:12
download pages with nodejs
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/';
@yuanchuan
yuanchuan / one day later.hs
Created June 12, 2012 06:19
Learning Haskell
-- 第一印象:使用 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" ]
@yuanchuan
yuanchuan / gist:2761842
Created May 21, 2012 11:08
Quick and dirty way to check if a website is gzipped
#!/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];
@yuanchuan
yuanchuan / gist:2760768
Created May 21, 2012 06:20
filter log file with nodejs for fun
#!/usr/bin/env node
var fs = require('fs')
, input = 'worklog.in'
, output = 'worklog.out';
var spliters = {
block: 'Revision'
, field: [
@yuanchuan
yuanchuan / gist:2653472
Created May 10, 2012 14:39
in favor of nodejs
#!/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';
@yuanchuan
yuanchuan / gist:2586540
Created May 3, 2012 15:33
Watch a directory recursively
/**
* Watch a directory recursively
*
* @param {String} dir
* @param {Function} cb
*
* watchRecursive('directory', function(current) {
* console.log(current, ' changed');
* });
*/