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 numBegArr = ["-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
| const numBegSet = new Set(numBegArr); | |
| const isNumericBeginning = char => numBegSet.has(char); | |
| const isNumericBeginning2 = char => numBegArr.includes(char); | |
| const isNumericBeginning3 = char => | |
| char === "-" || | |
| char === "0" || | |
| char === "1" || | |
| char === "2" || |
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
| type AtLeast<N extends number, T> = AtLeastRec<N, T, T[], []>; | |
| type AtLeastRec<Num, Elm, T extends unknown[], C extends unknown[]> = { | |
| 0: T; | |
| 1: ((arg: Elm, ...rest: T) => void) extends ((...args: infer T2) => void) | |
| ? ((arg: unknown, ...rest: C) => void) extends ((...args: infer T3) => void) | |
| ? AtLeastRec<Num, Elm, T2, T3> | |
| : never | |
| : never; | |
| }[C extends { length: Num } ? 0 : 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
| type Digged<T, Keys extends string[]> = DigFunI<T, (...args: Keys) => void>[0]; | |
| interface DigFunI<T, F> extends Array<F extends (()=>void) ? T : | |
| F extends ((key: infer K, ...rest: infer Rest) => void) ? | |
| K extends keyof T ? (DigFunI<T[K],((...args: Rest)=>void)> extends Array<infer E> ? E : unknown) | |
| : unknown : unknown>{ | |
| } | |
| function dig<T, Keys extends string[]>(obj: T, ...keys: Keys): Digged<T, Keys> { | |
| let result: any= obj; |
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
| // Builderオブジェクトの型 | |
| type Builder<Props, Result> = ({} extends Props | |
| ? { | |
| build: () => Result; | |
| } | |
| : {}) & | |
| { [P in keyof Props]-?: SetFunction<Props, P, Result> }; | |
| type SetFunction<Props, K extends keyof Props, Result> = ( | |
| value: Exclude<Props[K], undefined> |
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
| console.log('Test 1: raw EventTarget'); | |
| const et = new EventTarget(); | |
| // add handler of 'foo' event | |
| et.addEventListener('foo', (e)=> { | |
| console.log('foo event emitted:', e.detail); | |
| }); | |
| // dispatch 'foo' event | |
| et.dispatchEvent(new CustomEvent('foo', { detail: 123 })); | |
| console.log('Test 2: subclass of EventTarget'); |
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* perm(arr, prefix=[]){ | |
| if (arr.length <= 1){ | |
| yield [...prefix, ...arr]; | |
| return; | |
| } | |
| for (const [i, x] of arr.entries()) { | |
| const arr2 = [...arr.slice(0, i), ...arr.slice(i+1)]; | |
| yield* perm(arr2, [...prefix, x]); | |
| } | |
| } |
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
| #! /usr/bin/env node | |
| 'use strict'; | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const crypto = require('crypto'); | |
| const child_process = require('child_process'); | |
| // parse args |
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
| #!/bin/bash | |
| CHAP= | |
| ALLFLAG=0 | |
| while getopts ac: OPT | |
| do | |
| case $OPT in | |
| a) ALLFLAG=1;; | |
| c) CHAP=$OPTARG;; |
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 svg = document.querySelector('svg'); | |
| const svg2 = cl(svg); | |
| const gs = svg2.querySelectorAll('g'); | |
| for (let i=0; i < gs.length; i++){ | |
| const g = gs[i]; | |
| const cl = g.getAttribute('class'); | |
| if (cl){ | |
| const c = g.getAttribute('class').split(' '); | |
| if (c.some(x=>/__states$/.test(x))){ |
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 PORT = 8080; | |
| const net = require('net'); | |
| const srv = net.createServer(sock=>{ | |
| console.log('New connection'); | |
| sock.on('data', buf=>{ | |
| console.log('---------- data start ----------'); |