Skip to content

Instantly share code, notes, and snippets.

/*
二维接雨水
1. 假设存在 n * m 矩形随机山体(类似泰拉瑞亚)
2. 雨水从山体顶部开始流动,流动到山体底部,灌满所有空腔
3. 当雨水停止流动后,山体中的水会漏出来达到平衡
4. 最后求出山体中的留下来的水的总量
*/
import 'colors';
// 基本运算
export type NArray<T, N extends number> = N extends N ? (number extends N ? T[] : _NArray<T, N, []>) : never
type _NArray<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _NArray<T, N, [T, ...R]>
type NArrayNumber<L extends number> = NArray<number, L>
// 加法
export type Add<M extends number, N extends number> = [...NArrayNumber<M>, ...NArrayNumber<N>]['length']
// 减法
export type Subtract<M extends number, N extends number> =
// ===================== 解析器 ====================
// 分成三步,避免爆栈
type Reject = never;
type Node = Token | Node[];
type Token = string | number;
type Spaces = ' ' | '\n';
type Pairs = '(' | ')';
type Splits = Spaces | Pairs;
import { VisitorKeys } from 'estraverse';
import * as ESTree from 'estree';
type Cursor = [number, number];
function init(node: ESTree.Node): Cursor | null {
const keys: string[] | undefined = (VisitorKeys as any)[node.type];
if (!keys || keys.length <= 0) {
return null;
}
function guard<T0, T1>(
v: T0,
...conditions: [(v: T0) => boolean, (V: T0) => T1][]
) {
for (const [condition, func] of conditions) {
if (condition(v)) {
return func(v);
}
}
throw new Error('Condition not match');
type CommandFunc = (
target: any,
key: string,
value: any,
commands: Commands,
) => object;
type Commands = {
[key: string]: CommandFunc;
};
/* eslint-disable */
import React, { useMemo, useState } from "react";
function createHooksFromClass(_class) {
return function (props) {
const instance = useMemo(() => new _class(props), []);
const [state, setState] = useState(instance.state);
instance.state = state;
instance.props = props;
instance.setState = (newState) => setState(oldState => ({...oldState, ...newState}));
const acorn = require("acorn");
const astring = require("astring");
const estraverse = require("estraverse");
function withCancel(func) {
const signalName = "__$isCancel__";
const shouldCancelName = "__$shouldCancel__";
function transform(node) {
return estraverse.replace(node, {
import React, { createContext, useContext, useEffect } from 'react';
import './App.css';
interface LogData {
[key: string]: number | string;
}
interface LogLayerData {
name?: string;
log: LogData;
}
// ==UserScript==
// @name lark-doc-lock
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://bytedance.feishu.cn/*
// @require https://github.com/bramblex/MonkeyBox/raw/master/monkey-box.user.js
// ==/UserScript==