This file contains hidden or 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 parseHtmlTarg = (function(){ | |
//解析页面html字符串 | |
var _RegExp = /<(\/)*([a-zA-Z]+)([^>\w]+[^>]*)*>/ig; | |
var _attrRegExp = /[^>\w]+([a-zA-Z]+)=[\"\']?([^\"\']*)[\"\']?/ig; | |
var cssRegExp = /(expression)+/ig | |
var URL_EXP = new RegExp("((news|telnet|nttp|file|http|ftp|https)://)(([-A-Za-z0-9]+(\\.[-A-Za-z0-9]+)*(\\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\\.[0-9]{1,3}){3}))(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*)*", "g"); | |
//var IMG_EXP = /([^'"]+)[^>]*/ig | |
var filtterTags = { | |
'script' : true, | |
'iframe' : true, |
This file contains hidden or 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
// `this` in javascript functions points to the object called it!! | |
function f() { | |
undefined !== this.x ? this.x ++ : (this.x = 1); | |
} | |
var o = { | |
f: f | |
}; |
This file contains hidden or 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 http = require('http'); | |
var fs = require('fs'); | |
var cp = require('child_process'); | |
var getSocketPath = function(cpu) { | |
return __dirname + '/' + cpu + '.sock'; | |
}; | |
var cpu = 0; | |
// node process was bound to the first cpu in this demo. | |
var socketPath = getSocketPath(cpu); |
This file contains hidden or 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
/** | |
example: | |
function async(n, callback) { | |
setTimeout(function() { | |
callback(n); | |
}, n); | |
} | |
queue([100, 200], async, function(err, r) {console.log(r);}); // => [100, 200] | |
**/ |
This file contains hidden or 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 dispatcher = function() { | |
var pools = {}; | |
// { | |
// 'foo': [fn1, fn2], | |
// 'bar': [fn3, fn4] | |
// } | |
return { | |
on: function(action, handle) { | |
var actions = pools[action] || (pools[action] = []); |
This file contains hidden or 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 s = '$0abc\\$1 $2 $3[$2]gr $4[x][1]'; // => $0, $2, $3[$2], $4[x][1] | |
s.replace(/((?!\\)\$\d+(\[[^\[\]]+\])*)/g, function(m, $1, $2, index) { | |
console.log(m, $1, $2, index); | |
}); |
This file contains hidden or 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 dateFormat(date, formatString) { | |
/* | |
* eg:formatString="YYYY-MM-DD hh:mm:ss"; | |
*/ | |
var o = { | |
'M+' : date.getMonth()+1, //month | |
'D+' : date.getDate(), //day | |
'h+' : date.getHours(), //hour | |
'm+' : date.getMinutes(), //minute | |
's+' : date.getSeconds(), //second |
This file contains hidden or 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
// see => https://github.com/kriskowal/q/blob/v1/q.js#L83 | |
// Use the fastest possible means to execute a task in a future turn | |
// of the event loop. | |
var nextTick =(function () { | |
// linked list of tasks (single, with head node) | |
var head = {task: void 0, next: null}; | |
var tail = head; | |
var flushing = false; | |
var requestTick = void 0; | |
var isNodeJS = false; |
This file contains hidden or 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
// see => http://jsperf.com/postmessage | |
var echoSetTimeout = (function() { | |
return function(msg, cb) { | |
setTimeout(cb, 0); | |
} | |
})(); | |
var echoWorker = (function() { | |
var code = 'onmessage = function(e) { postMessage(e.data) };'; | |
var blobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; |
This file contains hidden or 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
//比如在下列A、B、C、D三处转义方式均有细节差异。 | |
//<a href="http://www.qq.com" title="<?=$A?>"><?=$B?></a> | |
//<script>var name="<?=$C?>"</script> | |
//<textarea> | |
//<?=$D?> | |
//</textarea> | |
//进行pre的只能是D,而且还要做其他转义,比如 < 转为 < |
OlderNewer