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; |
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
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
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 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
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
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
// Focusrite-Novation Launchpad Mini | |
const midiDeviceMap = {}; | |
const midi = await navigator.requestMIDIAccess(); | |
midi.inputs.forEach(entry => { | |
const key = entry.manufacturer+entry.name+entry.version; | |
if (!midiDeviceMap[key]) midiDeviceMap[key] = {}; | |
midiDeviceMap[key].input = entry; | |
}); | |
midi.outputs.forEach(entry => { | |
const key = entry.manufacturer+entry.name+entry.version; |
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
// Node.js & Electron reference : https://stackoverflow.com/a/58473299 | |
// C++ reference : https://stackoverflow.com/a/65052538 | |
// Environment: | |
// - Windows 10 | |
// - Nodejs v14.17.6 | |
// Dependencies: | |
// - [email protected] | |
// - [email protected] | |
// - [email protected] | |
// - [email protected] |
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 [N,M] = [5, 2]; | |
const contextStack: number[][] = []; | |
const stack = Array.from({length: N}, (_,i) => i + 1); | |
const result: number[] = []; | |
let target: number; | |
let isEnd = false; | |
while (1) { | |
// When one case is completed | |
if (result.length === M) { | |
console.log(result.join(' ')); |
OlderNewer