function count() {
var i = 0;
return function _next_() {
return i++;
};
}
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
/* | |
* *: alnum | |
* #: digit | |
* @: alpha | |
*/ | |
var alpha = [...("a").repeat(6)].map((c, i) => String.fromCharCode(c.charCodeAt(0) + i)).sort(() => Math.random() - 0.5); | |
var digit = [...("0").repeat(10)].map((c, i) => String.fromCharCode(c.charCodeAt(0) + i)).sort(() => Math.random() - 0.5); | |
var alnum = [].concat(alpha, digit).sort(() => Math.random() - 0.5); | |
var collect = { | |
"*": alnum, |
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
/** | |
* Auto Currying | |
* @param {Function} fn | |
* @return {Function} | |
*/ | |
function curring(fn) { | |
var fnLength = fn.length; | |
return (function next(argv) { |
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
let permut = (arr) => { | |
if (typeof arr === "string") { | |
arr = arr.split(""); | |
} | |
if (arr.length === 1) { | |
return arr; | |
} | |
let rst = []; | |
for (let i = 0, len = arr.length; i < len; i++) { | |
let newArr = arr.slice(); |
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
"use strict"; | |
let http = require("http"); | |
let url = require("url"); | |
let server = http.createServer(); | |
server.on("request", function (req, res) { | |
let headers = {}; | |
for (const key of Object.keys(req.headers)) { |
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
"use strict"; | |
const format = date => date.toTimeString().split(" ")[0]; | |
/** | |
* @param {string} [name=fn.displayName||fn.name||"UNKNOW"] task name | |
* @param {(Function|*)} fn task function | |
* @param {...} [...args] task function's arguments | |
* @returns {} | |
*/ |
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
"use strict"; | |
function sum(buffer) { | |
let checksum = 0x0000; | |
let parity = buffer.length % 2; | |
for (let i = 0, len = buffer.length - parity; i < len; i += 2) { | |
checksum += buffer.readUInt16BE(i); | |
} | |
if (parity) { | |
checksum += buffer.readUInt8(buffer.length - 1) << 8 | 0x00; |
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
/* | |
* version: 0.0.4 | |
* | |
* infiniteScrolling(document.querySelector("ul"), function (el, done) { | |
* // 在此可通过 ajax 去获取分页的数据,然后可以把数据插入到 el 内(el 即是 document.querySelector("ul")) | |
* // 当插入数据完成后,如果不是最后一页,必须调用 done()。 | |
* }, 100); // 100 表示 ul 距离视口 100px 触发 callback 函数,此参数可以省略,如果省略,则距离 ul 的最后一个元素 | |
*/ | |
;(function (root, factory) { |
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
/** | |
* For Google Voice | |
* @Author zbinlin <[email protected]> | |
*/ | |
var sleep = delay => new Promise(resolve => setTimeout(resolve, delay)); | |
var composeClick = function x(btn) { | |
var rect = btn.getBoundingClientRect(); | |
var x = Math.floor(rect.clientX + rect.width * Math.random()); | |
var y = Math.floor(rect.clientY + rect.height * Math.random()); |