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
| function * backTracking(...args) { | |
| const r = [[]]; | |
| while (r.length) { | |
| const t = r.shift(); | |
| if (t.length === args.length) yield t; | |
| else r.unshift(...args[t.length].map(i => [...t, i])); | |
| } | |
| } | |
| const iter = backTracking([true, false], [1, 2, 3], [3, 4, 5, 6, 7], ['a', 'b'], ['c']); | |
| [...iter]; |
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 args = [ | |
| [1,2,3], | |
| [1], | |
| ['a', 'b'], | |
| ['c', 'd', 'e'], | |
| [5], | |
| ]; | |
| const r = [[]] as any; | |
| let i = 0; |
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 createRangePagination = (page: number, limit: number, total: number, range: number) => { | |
| const size = range * 2 + 1; | |
| const maxPage = Math.ceil(total / limit); | |
| const start = range >= page ? 1 | |
| : maxPage - range < page ? maxPage - size + 1 | |
| : page - range; | |
| const end = size > page + range ? size | |
| : maxPage < page + range ? maxPage | |
| : page + range; | |
| return Array.from({length: end - start + 1}, (_, i) => i + start); |
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, RefObject } from 'react'; | |
| const useOutsideClick = <T extends HTMLElement>(f: (ev: MouseEvent) => void, ref: RefObject<T>) => { | |
| useEffect(() => { | |
| const upHandler = (ev: MouseEvent) => { | |
| ev.stopPropagation(); | |
| document.removeEventListener('click', upHandler, true); | |
| f(ev); | |
| }; | |
| const downHandler = (ev: PointerEvent) => { |
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 createPaginationIndex = (currentPage: number, total: number, limit = 10, listLength = 10) => { | |
| const totalPages = Math.ceil(total / limit); | |
| const startSetIndex = Math.floor((currentPage - 1) / listLength); | |
| const startList = listLength * startSetIndex + 1; | |
| const length = startList + listLength - 1 > totalPages ? | |
| listLength - (startList + listLength - 1 - totalPages) : | |
| listLength; | |
| return { |
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 fileSystemEntryParse = async (data: FileSystemEntry|DataTransferItemList) => { | |
| const entries = data instanceof DataTransferItemList ? [...data].map(dataTransferItem => dataTransferItem.webkitGetAsEntry()) : [data]; | |
| const stack = [...entries]; | |
| let target: FileSystemEntry; | |
| const result: File[] = []; | |
| while (target = stack.shift() as FileSystemEntry) { | |
| if (target.isDirectory) { | |
| const reader = (target as FileSystemDirectoryEntry).createReader(); |
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 type ParenthesisPosition = [number, number, ParenthesisPosition[]]; | |
| export const parenthesisParse = (str: string) => { | |
| let cursor = -1; | |
| const result: ParenthesisPosition[] = []; | |
| const stack: ParenthesisPosition[] = []; | |
| let error = ''; | |
| while (!error) { | |
| if (!stack.length) { | |
| const startIndex = str.indexOf('(', cursor + 1); |
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(' ')); |
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
| // 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; |