Skip to content

Instantly share code, notes, and snippets.

Shijie Lu lushijie

Block or report user

Report or block lushijie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View node-or-browser.js
// 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
};
}
@lushijie
lushijie / cubeDebug.js
Last active Nov 1, 2018
storage 调试
View cubeDebug.js
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';
@lushijie
lushijie / getFuncArgName.js
Last active Aug 24, 2018
获取函数形参名, 反射中使用到
View getFuncArgName.js
function getFuncArgName(func) {
// 正则表达式出自http://krasimirtsonev.com/blog/article/Dependency-injection-in-JavaScript
var paramNames = func.toString().match(/^function\s*[^\(]*\(\s*([^\)]*)\)/m)[1];
paramNames = paramNames.replace(/ /g, '');
paramNames = paramNames.split(',');
return paramNames;
}
@lushijie
lushijie / dom-to-json.js
Created May 6, 2018 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
View dom-to-json.js
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;
View encrypt.js
// 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
}
View fileMd5.js
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);
});
@lushijie
lushijie / runAtOnce.js
Created Dec 29, 2017
第一次声明执行并绑定this
View runAtOnce.js
let articleRequest = () => {
let f = function() {
// todo
}.bind(this)();
return f;
};
articleRequest();
let articleRequest2 = function f() {
// todo
@lushijie
lushijie / declareAndRun.js
Created Dec 28, 2017
声明一个函数并接着执行一次
View declareAndRun.js
let func = (function f(a) {
console.log(a);
return f;
})('hello world');
View toUnicodeSequence.js
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;
}
@lushijie
lushijie / getThirdResoure.js
Created Dec 25, 2017
获取本网站引用的第三方资源
View getThirdResoure.js
function getThirdResoure() {
var resp = null;
var tags = document.querySelectorAll('iframe[src],frame[src],script[src],link[rel=stylesheet],object[data],embed[src]');
for(var i = 0; i < tags.length; i++){
var tag = tags[i];
var a = document.createElement('a');
a.href = tag.src||tag.href||tag.data;
if(a.hostname != location.hostname){
resp = resp || [];
resp.push({name: tag.localName, href: a.href});
You can’t perform that action at this time.