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
(function (root, factory) { | |
if(typeof define === "function" && define.amd) { | |
// Now we're wrapping the factory and assigning the return | |
// value to the root (window) and returning it as well to | |
// the AMD loader. | |
define(["postal"], function(postal){ | |
return (root.myModule = factory(postal)); | |
}); | |
} else if(typeof module === "object" && module.exports) { | |
// I've not encountered a need for this yet, since I haven't |
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
function isInteger(x) { return (x^0) === x; } | |
function isInteger(x) { return Math.round(x) === x; } | |
function isInteger(x) { return (typeof x === 'number') && (x % 1 === 0); } |
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'), | |
Buffer = require('buffer').Buffer; | |
fs.readFile('base.tpl', function(err, data) { | |
if (err) return; | |
var srcArray = data.toString().split('\r\n'), | |
destArray = []; | |
srcArray.forEach(function(content) { | |
destArray.push(content.replace(/(\t*).*/, function(match, $1, offset, string) { |
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
// path需以斜杠结尾 | |
var fs = require('fs'), | |
path = 'base/base/base/'; | |
path.split('/').reduce(function(prev, next) { | |
if (!fs.existsSync(prev)) | |
fs.mkdirSync(prev); | |
return prev + '/' + next; | |
}); |
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
(function () { | |
if (window.ActiveXObject) { | |
var ua = navigator.userAgent.toLowerCase(); | |
var ie = ua.match(/msie ([\d.]+)/)[1]; | |
if (ie == "6.0") { | |
var oBox = document.createElement('div'); | |
var oBack = document.createElement('div'); | |
oBox.id = "noie6-wrap"; | |
oBox.innerHTML = '<div class="box"><div class="ico fl"></div><div class="text fl"><p class="px1"></p><p class="px2"></p><div class="link ovl"><a class="fl" href="http://www.firefox.com.cn/download/" id="ff-link" title="下载火狐浏览器"></a><a class="fl" href="https://www.google.com/chrome/" id="chrome-link" title="下载Chrome浏览器"></a><a class="fl" href="http://www.apple.com.cn/safari/" id="safari-link" title="下载Safari浏览器"></a><a class="fl" href="http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie" id="ie-link" title="下载新版IE浏览器"></a><a class="fl" href="http://www.opera.com/" id="opera-link" title="下载Opera浏览器"></a></div></div></div>'; | |
oBack.id = 'SB-overlayer'; |
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
//使g()(‘al’)返回字符串”goal”; | |
//g()()(‘al’)输出”gooal”; | |
//代码g()()()(‘al’)返回goooal; | |
// 各个语言版本参考链接 https://github.com/eatnumber1/goal | |
// 一开始自己想的一个版本 | |
function g() { | |
var stack = ['g']; | |
if (arguments.length === 0) { |
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
# 查看当前目录文件总数 | |
find ./ -name "*.js" | wc -l | |
# 查看当前目录文件总行数 | |
find ./ -name "*.js" | xargs cat | wc -l | |
# 查看当前目录文件总行数,不包含空行 | |
find ./ -name "*.js" | xargs cat | grep -v ^$ | wc -l |
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
curl -w "TCP handshake: %{time_connect}, SSL handshake: %{time_appconnect}\n" -so /dev/null https://www.alipay.com | |
#上面命令中的w参数表示指定输出格式,timeconnect变量表示TCP握手的耗时,timeappconnect变量表示SSL握手的耗时(更多变量请查看文档和实例),s参数和o参数用来关闭标准输出。 | |
#摘自http://www.ruanyifeng.com/blog/2014/09/ssl-latency.html |
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
// 摘自Secrets of the JavaScript Ninja | |
Function.prototype.partial = function() { | |
var fn = this, args = Array.prototype.slice.call(arguments); | |
return function() { | |
var arg = 0; | |
for (var i = 0; i < args.length && arg < arguments.length; i++) { | |
if (args[i] === undefined) { | |
args[i] = arguments[arg++]; | |
} | |
} |
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://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html | |
function globalEval(data) { | |
data = data.replace(/^\s*|\s*$/g, ""); | |
if (data) { | |
var head = document.getElementsByTagName("head")[0] || | |
document.documentElement, | |
script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.text = data; | |
head.appendChild(script); |
OlderNewer