Skip to content

Instantly share code, notes, and snippets.

View beetcb's full-sized avatar
:octocat:
contributing

beet beetcb

:octocat:
contributing
View GitHub Profile
@beetcb
beetcb / eventLoop.js
Last active May 14, 2022 23:46
Explain event loop in JS Runtime with pseudocode
// The if-else pattern is replaced by if-only expressions for consisitency and clarity.
// A new JavaScript program or subprogram is executed, a initial task is created
taskQueue.enqueue(initParse())
// Event Loop
while everyTick {
if !callstack.isEmpty() {continue}
taskQueue.dequeue().excuteStepsByJSEngine()
while !microTaskQueue.isEmpty() {
@beetcb
beetcb / util.ts
Last active August 18, 2023 09:30
Exclude number type from typescript `keyof` string indexed signature
// see -> https://www.typescriptlang.org/docs/handbook/2/keyof-types.html
type ExcludeUnexpectedNumIdxSigKeyof<T> = keyof T extends number
? keyof T
: Extract<keyof T, string>;
type MapishMixed = { [k: number | string]: boolean };
type M = ExcludeUnexpectedNumIdxSigKeyof<MapishMixed>;
// ^? M will be of type string | number
type MapishNumber = { [k: number]: boolean };
@beetcb
beetcb / proxy.pac
Last active February 6, 2024 08:27
// see -> https://en.wikipedia.org/wiki/Proxy_auto-config#:~:text=A%20proxy%20auto%2Dconfig%20(PAC,for%20fetching%20a%20given%20URL.
// 定义 findProxyForURL 函数,它接受初始化状态和配置文件
const findProxyForURL = (init, profiles) => (url, host) => {
let result = init;
const scheme = url.substr(0, url.indexOf(":"));
do {
result = profiles[result];
if (typeof result === "function") {
result = result(url, host, scheme);
#!/usr/bin/env pwsh
# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
$ErrorActionPreference = 'Stop'
if ($v) {
$Version = "v${v}"
}
if ($Args.Length -eq 1) {