Skip to content

Instantly share code, notes, and snippets.

View fronterior's full-sized avatar
:electron:

Low Front fronterior

:electron:
View GitHub Profile
@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;
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);
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
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 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[]>);
import { useEffect, useRef } from "react";
const useDragHook = <T extends HTMLElement>(
{
down,
move,
up,
}: {
down?(ev: PointerEvent, extra: { ox: number; oy: number }): void;
move?(
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) ?? []);
}
}
// 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;
@fronterior
fronterior / electron-prevent-zorder-change.js
Last active January 26, 2022 01:05
WM_WINDOWPOSCHANGING Message Handler for Electron Application, which is always fixed on the floor.
// 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]
@fronterior
fronterior / backtracking-algorithm-iterative-solution.ts
Last active September 26, 2021 15:53
List all cases in which M of the numbers from 1 to N are selected without overlapping. If the order is different, even the same value is treated as different cases. (1 <= M <= N)
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(' '));