Skip to content

Instantly share code, notes, and snippets.

View fronterior's full-sized avatar
:electron:

fronterior fronterior

:electron:
View GitHub Profile
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) ?? []);
}
}
import { useEffect, useRef } from "react";
const useDragHook = <T extends HTMLElement>(
{
down,
move,
up,
}: {
down?(ev: PointerEvent, extra: { ox: number; oy: number }): void;
move?(
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[]>);
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);
});
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
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);
@fronterior
fronterior / axios-http.js
Created January 12, 2021 08:09
[email protected] http adapter for electron
'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;