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
//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){ |
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
// callback-nested | |
Database.connect("db",function(db){ | |
db.open("table",function(table){ | |
table.select("name",function(val){ | |
console.log(val); | |
}); | |
}); | |
}); | |
// un-nested |
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
Object.clone(obj,deep){ | |
if(obj == null || typeof(obj) != 'object') | |
return obj; | |
if(deep){ | |
var temp = obj.constructor(); // changed | |
for(var key in obj) | |
temp[key] = clone(obj[key]); | |
return temp; | |
}else{ |
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
<script type="text/javascript"> | |
var disqus_shortname = 'madscript'; // required: replace example with your forum shortname | |
/* * * DON'T EDIT BELOW THIS LINE * * */ | |
(function() { | |
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | |
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | |
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | |
})(); | |
</script> |
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 fs = require("fs"); | |
var path = require("path"); | |
// mian code, 请替换路径地址 | |
ncp('./path/to/source', './path/to/dest', function(){ | |
rmrf('./path/to/source'); | |
}) | |
// copy from ncp, 请折叠 | |
function ncp (source, dest, options, callback) { |
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
// http://getfirebug.com/wiki/index.php/Console_API | |
// https://developers.google.com/chrome-developer-tools/docs/console-api#consolelogobject_object | |
// https://developer.mozilla.org/en-US/docs/Web/API/console | |
console.log("%cRed text, %cgreen text, %cblue text", "color:red", "color:green", "color:blue"); | |
console.log("%c", | |
"font-size: 1px; padding: 130px 232px; line-height: 260px;background: url(http://i.imgur.com/oGiMR.gif); background-size: 464px 260px; color: transparent;") | |
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 template = 'hi'; | |
exports.run = function(){ | |
template('hi') | |
} | |
exports.template = function(hi){ | |
console.log(hi) | |
} |
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
'.source.ruby': | |
'describe (String)': | |
'prefix': 'des' | |
'body': 'describe "${1:subject}" do\n $0\nend' | |
'describe (type)': | |
'prefix': 'dest' | |
'body': 'describe ${1:Type} do\n $0\nend' | |
'describe (type, string)': | |
'prefix': 'dests' | |
'body': 'describe ${1:Type}, "${2:description}" do\n $0\nend' |
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
alias fixow='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;echo "Open With has been rebuilt, Finder will relaunch"' |
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
on run {input, parameters} | |
do shell script "" with administrator privileges | |
set the rootPwd to text returned of (display dialog "请输入您的管理员密码:" default answer "" with hidden answer) | |
try | |
do shell script "echo " & rootPwd & "|sudo -S killall coreaudiod" | |
do shell script "echo " & rootPwd & "|sudo -S kextunload /System/Library/Extensions/AppleHDA.kext" | |
do shell script "echo " & rootPwd & "|sudo -S kextload /System/Library/Extensions/AppleHDA.kext" | |
do shell script "sudo -k" --logout root | |
display dialog "操作已经成功完成,您的系统应该能够恢复声音。 | |
如果问题依旧,请直接重启系统。" buttons {"好"} with icon 1 with title "成功" |
OlderNewer