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
export enum Units { | |
B = 1, | |
KB = 1 * 1024, | |
MB = 1 * 1024 * 1024, | |
GB = 1 * 1024 * 1024 * 1024, | |
TB = 1 * 1024 * 1024 * 1024 * 1024, | |
} | |
const UnitsName = ['B', 'KB', 'MB', 'GB', 'TB']; |
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
/** | |
* 实现任意 increment 的任意数字的 rounding 操作; | |
* 比如 Math.round(n) 其实就是 genericRound(n, 1) 的特化 | |
*/ | |
export function genericRound(n: number, inc: number): number { | |
if (inc === 0) return n; | |
const d = (n % inc); | |
if (d >= (inc / 2)) return n + (inc - d); | |
return n - d; | |
} |
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
(define (list->tree elements) | |
(car (partial-tree elements (length elements)))) | |
(define (partial-tree elts n) | |
(if (= n 0) | |
(cons '() elts) | |
(let ((left-size (quotient (- n 1) 2))) | |
(let ((left-result (partial-tree elts left-size))) | |
(let ((left-tree (car left-result)) | |
(non-left-elts (cdr left-result)) |
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
# Resolve VSCode Win7 Extension XHR Failed | |
run vscode with command line flag `--ignore-certificate-errors` | |
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
import Foundation | |
fileprivate var counter = 0 | |
func withTimeoutUnsafeContinuation<T>( | |
_ labelName: String = "NoName", | |
_ timeout: TimeInterval = 2.0, | |
_ fn: @escaping (UnsafeContinuation<T?, Never>) -> Void | |
) async -> T? { | |
let nth = counter + 1 |
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
/* | |
* https://github.com/netnr/workers | |
* | |
* 2019-10-12 - 2022-05-05 | |
* netnr | |
* | |
* https://github.com/Rongronggg9/rsstt-img-relay | |
* | |
* 2021-09-13 - 2022-05-29 | |
* modified by Rongronggg9 |
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
// 从三个参数中选择一个 | |
type Selector<T> = | |
(v: T, l?: Tree<T>, r?: Tree<T>) => undefined | T | Tree<T>; | |
// 定义树 | |
type Tree<T> = ( | |
<S extends Selector<T>>(selector: S) => ReturnType<S> | |
); | |
// 构造 Tree |
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
// export {} | |
const canvas = document.getElementById('canvas')! as HTMLCanvasElement; | |
const gl = canvas.getContext('webgl')!; | |
// 定义顶点着色器 | |
const vertexShaderSource = ` | |
attribute vec4 a_position; | |
void main() { | |
gl_Position = a_position; |
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
type Task<T> = () => (T | Promise<T>); | |
type UnLock = () => void; | |
class ProcessLock { | |
private count = 0; | |
private queue: UnLock[] = []; | |
constructor(public capacity: number) {} | |
request = async (): Promise<UnLock> => { | |
if (this.count >= this.capacity) { | |
await new Promise<void>((resolve) => { |
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
echo 'hello' > ./a.log 2>&1 # merge stdout & stderr and redirect it to a.log | |
echo "$?" # outout the process exitCode of last executed command (L1's exitCode in this case) |