Skip to content

Instantly share code, notes, and snippets.

@lyuehh
lyuehh / obj.js
Created November 4, 2012 14:36
遍历js object
// 遍历可枚举的自身属性 Ojbect.keys
(function () {
var propertys = Object.keys(window);
alert(propertys.length); //3
alert(propertys.join("\n")); //window,document,InstallTrigger,除了最后一个是火狐私有的属性,原来window对象只有两个可枚举的自身属性.window属性指向window对象自身,一般没什么用.
})();
// 遍历所有的自身属性
(function () {
var propertys = Object.getOwnPropertyNames(window);
@lyuehh
lyuehh / vagrant.sh
Created November 13, 2012 15:17
vagrant ruby env
sudo vi /etc/apt/source.list
:%s/us/cn/g
sudo apt-get update
sudo apt-get install git-core
sudo apt-get install curl
sudo apt-get install build-essential zlib1g zlib1g-dev libreadline5 libreadline5-dev libssl-dev
curl -L https://get.rvm.io | bash -s stable
source /home/vagrant/.rvm/scripts/rvm
rvm install 1.9.3
@lyuehh
lyuehh / js_example.js
Created December 12, 2012 10:43
js examples
/*
demo1: do not repeat yourself
*/
$.ajax({
'url': '/user',
'data': 'dept=aaa&active=true&_=' + Math.random(),
'dataType': 'json',
'headers': {
'X-CSRF-Token': $('#csrf').attr('content');
/*
* array_list
*/
'use strict';
function ArrayList() {
this.data = [];
this.length = 0;
}
function add_1(x, y) {
return x + y;
}
console.log(add_1(1,2));
function add(x, y) {
var oldx = x, oldy = y;
if(typeof y === 'undefined') {
return function(newy) {
(define (abs x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) (- x))))
(define (sequare x) (* x x))
(define (sqrt-iter guess x)
(if (good-enough? guess (improve guess x))
(improve guess x)
(define (factor n)
(if (= n 1)
1
(* n (factor (- n 1)))))
(define (factor2 n)
(factor-iter 1 1 n))
(define (factor-iter product counter max-count)
(if (> counter max-count)
function fib(n) {
return fib_iter(1, 0, n);
}
function fib_iter(a, b, count) {
if(count === 0) {
return b;
} else {
return fib_iter(a + b, a, count - 1);
}
北京,101010100|北京海淀,101010200|北京朝阳,101010300|北京顺义,101010400|北京怀柔,101010500|北京通州,101010600|北京昌平,101010700|北京延庆,101010800|北京丰台,101010900|北京石景山,101011000|北京大兴,101011100|北京房山,101011200|北京密云,101011300|北京门头沟,101011400|北京平谷,101011500|上海,101020100|上海闵行,101020200|上海宝山,101020300|上海嘉定,101020500|上海南汇,101020600|上海金山,101020700|上海青浦,101020800|上海松江,101020900|上海奉贤,101021000|上海崇明,101021100|上海徐家汇,101021200|上海浦东,101021300|天津,101030100|天津武清,101030200|天津宝坻,101030300|天津东丽,101030400|天津西青,101030500|天津北辰,101030600|天津宁河,101030700|天津汉沽,101030800|天津静海,101030900|天津津南,101031000|天津塘沽,101031100|天津大港,101031200|天津蓟县,101031400|重庆,101040100|重庆永川,101040200|重庆合川,101040300|重庆南川,101040400|重庆江津,101040500|重庆万盛,101040600|重庆渝北,101040700|重庆北碚,101040800|重庆巴南,101040900|重庆长寿,101041000|重庆黔江,101041100|重庆万州,101041300|重庆涪陵,101041400|重庆开县,101041500|重庆城口,101041600|重庆云阳,101041700|重庆巫溪,101041800|重庆奉节,101041900|重庆巫山,101042000|重庆潼南,101042100|重庆垫江,101042200|重庆梁平,101042300|重庆忠县,101042400|重庆石柱,101042500|重庆大足,101042600|重庆荣昌,101042700|重庆铜梁,101042800|重庆璧山,101042900|重庆丰都,1010
@lyuehh
lyuehh / vimrc
Created February 18, 2013 11:16
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" TODO: this may not be in the correct place. It is intended to allow overriding <Leader>.
" source ~/.vimrc.before if it exists.
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc.before
endif