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 interceptNetworkRequests(ee) { | |
const open = XMLHttpRequest.prototype.open; | |
const send = XMLHttpRequest.prototype.send; | |
const isRegularXHR = open.toString().indexOf('native code') !== -1; | |
// don't hijack if already hijacked - this will mess up with frameworks like Angular with zones | |
// we work if we load first there which we can. | |
if (isRegularXHR) { |
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.prototype.bind2 = function(context) { | |
const self = this; | |
const args = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
const args2 = Array.prototype.slice.call(arguments); | |
self.apply(context, args.concat(args2)); | |
} | |
} |
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
// determine if in-browser or using node.js | |
// thruthy | |
var _nodejs = ( | |
typeof process !== 'undefined' && process.versions && process.versions.node); | |
if (_nodejs) { | |
_nodejs = { | |
version: process.versions.node | |
}; | |
} |
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 datetime(date = new Date(), format) { | |
if (date && typeof date === 'string') { | |
const dateString = date; | |
date = new Date(Date.parse(date)); | |
if (isNaN(date.getTime()) && !format) { | |
format = dateString; | |
date = new Date(); | |
} | |
} | |
format = format || 'YYYY-MM-DD HH:mm:ss'; |
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 toJSON(node) { | |
node = node || this; | |
var obj = { | |
nodeType: node.nodeType | |
}; | |
if (node.tagName) { | |
obj.tagName = node.tagName.toLowerCase(); | |
} else | |
if (node.nodeName) { | |
obj.nodeName = node.nodeName; |
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://lib.baomitu.com/crypto-js/3.1.9-1/crypto-js.js | |
function encrypt(content, key) { | |
var encryptResult = CryptoJS.AES.encrypt( | |
content, | |
key, | |
{ | |
//iv: key, | |
mode: CryptoJS.mode.ECB, | |
padding: CryptoJS.pad.Pkcs7 | |
} |
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
let fs = require('fs'); | |
let crypto = require('crypto'); | |
let path = '/Users/lushijie/Pictures/day1.jpg'; | |
let start = new Date().getTime(); | |
let md5sum = crypto.createHash('md5'); | |
let stream = fs.createReadStream(path); | |
stream.on('data', function(chunk) { | |
md5sum.update(chunk); | |
}); |
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
let articleRequest = () => { | |
let f = function() { | |
// todo | |
}.bind(this)(); | |
return f; | |
}; | |
articleRequest(); | |
let articleRequest2 = function f() { | |
// todo |
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
let func = (function f(a) { | |
console.log(a); | |
return f; | |
})('hello world'); |
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 toUnicodeSequence(str) { | |
for(var i = str.length; i--;) { | |
str = str.slice(0, i) + '\\u' | |
+ ('000' + str.charCodeAt(i).toString(16)).slice(-4) | |
+ str.slice(i + 1); | |
} | |
return str; | |
} |
NewerOlder