Skip to content

Instantly share code, notes, and snippets.

@yuanyan
yuanyan / un-nested
Created September 8, 2011 15:18
un-nested callback
// callback-nested
Database.connect("db",function(db){
db.open("table",function(table){
table.select("name",function(val){
console.log(val);
});
});
});
// un-nested
@yuanyan
yuanyan / poisson.js
Created May 29, 2011 06:12
Poisson distribution
//Poisson distribution
//http://en.wikipedia.org/wiki/Poisson_distribution
function poisson(expectvalue){
var n = 0, //循环计数
limit = Math.exp(-expectvalue), // e -v, 其中v是期望值
x = Math.random(); //生成 0-1之间随机数
while(x > limit){