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
/* | |
二维接雨水 | |
1. 假设存在 n * m 矩形随机山体(类似泰拉瑞亚) | |
2. 雨水从山体顶部开始流动,流动到山体底部,灌满所有空腔 | |
3. 当雨水停止流动后,山体中的水会漏出来达到平衡 | |
4. 最后求出山体中的留下来的水的总量 | |
*/ | |
import 'colors'; |
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
// 基本运算 | |
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> = |
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
// ===================== 解析器 ==================== | |
// 分成三步,避免爆栈 | |
type Reject = never; | |
type Node = Token | Node[]; | |
type Token = string | number; | |
type Spaces = ' ' | '\n'; | |
type Pairs = '(' | ')'; | |
type Splits = Spaces | Pairs; |
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
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; | |
} |
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 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'); |
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
type CommandFunc = ( | |
target: any, | |
key: string, | |
value: any, | |
commands: Commands, | |
) => object; | |
type Commands = { | |
[key: string]: CommandFunc; | |
}; |
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
/* 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})); |
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
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, { |
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
import React, { createContext, useContext, useEffect } from 'react'; | |
import './App.css'; | |
interface LogData { | |
[key: string]: number | string; | |
} | |
interface LogLayerData { | |
name?: string; | |
log: LogData; | |
} |
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
// ==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== |
NewerOlder