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 function* dfs<T>(root: T) { | |
| const stack: T[] = [root]; | |
| let target: T|undefined; | |
| while (target = stack.shift()) { | |
| const cb: DFSNext<T> = yield target; | |
| stack.unshift(...cb?.(target) ?? []); | |
| } | |
| } |
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 { useEffect, useRef } from "react"; | |
| const useDragHook = <T extends HTMLElement>( | |
| { | |
| down, | |
| move, | |
| up, | |
| }: { | |
| down?(ev: PointerEvent, extra: { ox: number; oy: number }): void; | |
| move?( |
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
| const groupBy = <T, K extends keyof any>(f: (p: T) => K, arr: T[]) => arr.reduce((acc, val) => { | |
| const key = f(val); | |
| acc[key]?.push(val) ?? (acc[key] = [val]); | |
| return acc; | |
| }, {} as Record<K, T[]>); |
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
| const h = (t, o) => Object.assign(document.createElement(t), o); | |
| const c = h('canvas', {width: 400, height: 300, style: 'background: black;'}); | |
| const ctx = c.getContext('2d'); | |
| document.body.appendChild(c); | |
| const s = new Set(); | |
| requestAnimationFrame(function draw(time) { | |
| s.forEach(f => f(time)); | |
| requestAnimationFrame(draw); | |
| }); |
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
| const {execSync} = require('child_process'); | |
| const COMMAND = 'DIR'; | |
| const cp949Decoder = new TextDecoder('windows-949'); | |
| const bytes = new Uint8Array(execSync(COMMAND)); | |
| console.log(cp949Decoder.decode(bytes)); | |
| // https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder | |
| // https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings |
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
| bracketParse = str => { | |
| let cursor = 0; | |
| let depth = 1; | |
| const stack = []; | |
| const subStack = []; | |
| while (cursor < str.length) { | |
| const si = str.indexOf('(', cursor); | |
| const nsi = str.indexOf('(', si + 1); | |
| const ei = str.indexOf(')', cursor); |
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
| 'use strict'; | |
| var utils = require('axios/lib/utils'); | |
| var settle = require('axios/lib/core/settle'); | |
| var buildFullPath = require('axios/lib/core/buildFullPath'); | |
| var buildURL = require('axios/lib/helpers/buildURL'); | |
| var http = require('http'); | |
| var https = require('https'); | |
| var httpFollow = require('follow-redirects').http; | |
| var httpsFollow = require('follow-redirects').https; |
NewerOlder