Random order
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
'use strict'; | |
const jscodeshift = require('jscodeshift'); | |
const { MemberExpression, Property } = jscodeshift; | |
jscodeshift.registerMethods({ | |
// exports.a => exports.b | |
// | |
// jscodeshift(source) | |
// .find(jscodeshift.Identifier, { name: 'a' }) |
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
[{ | |
"name": "milestone", | |
"color": "0052cc" | |
}, { | |
"name": "task", | |
"color": "009800" | |
}, { | |
"name": "feature", | |
"color": "009800" | |
}, { |
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 urllib = require('urllib'); | |
// 乱码 | |
urllib.request('http://static.alipayobjects.com/build/js/arale.js', {}, function (err, data, res) { | |
console.log(data.toString()); | |
}); | |
// 正常 | |
urllib.request('https://a.alipayobjects.com/build/js/arale.js', {}, function (err, data, res) { | |
console.log(data.toString()); |
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 esprima = require('esprima'); | |
var code = []; | |
// Literal | |
code.push('1;'); | |
code.push('true;'); | |
code.push('"a";'); | |
code.push('/a/g;'); | |
code.push('null;'); |
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 bench = require('bench'); | |
var compare = {}; | |
var data = {}; | |
// 先安装 bench | |
// 10^5 基本小于 1 ms,所以对比 10^5 到 10^6 之间的数 | |
for (var i = 1; i <= 10; i++) { | |
var count = 100000 * i; | |
(function(count) { | |
var content = createContent(count); |
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
# install gist by `brew install gist` | |
# | |
# create gist on first time | |
# update gist when .gistid exists | |
function gist() { | |
local gistid | |
args=$@ | |
if [ -f .gistid ]; then | |
gistid=$(cat .gistid) |
可使用这个快速上传文件
注意:公司外部是无法使用
确保已经配置好 node 环境 http://aralejs.org/docs/installation.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
Array.prototype.uniq = function() { | |
return this.filter(function(item, index, arr) { | |
return index === arr.indexOf(item); | |
}); | |
}; | |
// test | |
[1,2,3,2,1,2,4,6,8,3,2].uniq(); |
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 readDirs(dir) { | |
var result = []; | |
fs.readdirSync(dir) | |
.forEach(function(file) { | |
var sub = path.join(dir, file); | |
if (fs.statSync(sub).isDirectory()) { | |
result = result.concat(readDirs(sub).map(function(subFile) { | |
return path.join(file, subFile); | |
})); | |
} else { |
NewerOlder