Skip to content

Instantly share code, notes, and snippets.

/**
* @return string
**/
export default function Hello() {
return "Hello";
}
@zbinlin
zbinlin / work-queue.mjs
Created July 11, 2021 06:02
Work Queue
import { promisify } from 'util';
const sleep = promisify(setTimeout);
class WorkQueue {
#gen;
constructor() {
const gen = WorkQueue.#processor();
gen.next(); // ignore first call
this.#gen = gen;
find . -name '*.apk' -print0 | xargs -0 -i -n1 bash -c '
aapt dump badging ${0} | tac | grep --label=${0} --max-count 1 -HoP "(?<=application-label-zh-CN:).+|(?<=application-label:).+"
' {}
async function doRequest({ type }: { type: string }, { no }: { no: number }) {
}
type Unpacked<T> = T extends Promise<infer P> ? P : T;
function wrapper<T extends (...args: any[]) => any>(fn: T) {
return async function(...args: Parameters<T>): Promise<Unpacked<ReturnType<T>>> {
return await fn.apply(null, args);
};
}
class Scheduler {
add(promiseCreator) {
if (!Array.isArray(this._runnings)) {
this._runnings = [];
}
if (!Array.isArray(this._pendings)) {
this._pendings = [];
}
if (!this._tick) {
this._tick = function (idx) {
const fs = require('fs').promises;
const path = require('path');
async function main() {
const cache = {};
await readdir('.', cache);
console.log(JSON.stringify(cache));
}
async function readdir(dir, cache) {
@zbinlin
zbinlin / test.md
Last active July 13, 2018 08:11
test

[基础] 实现一个简单的闭包。

function count() {
    var i = 0;
    return function _next_() {
        return i++;
    };
}
/**
* For Google Voice
* @Author zbinlin <zbinlin@outlook.com>
*/
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());
@zbinlin
zbinlin / shared-session-storage.html
Last active December 7, 2016 03:16
shared session storage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button onclick="changeColor()">Change Color</button>
<script src="./shared-session-storage.js"></script>
<script>
/*
* 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) {