This file contains 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
interface CommonProps { | |
a: number | |
b: string | |
} | |
interface EnabledProps { | |
onChangeFn: (newVal: string) => void | |
} | |
type ConditionalProps = |
This file contains 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
package main | |
import "fmt" | |
// List represents a singly-linked list that holds | |
// values of any type. | |
type List[T any] struct { | |
next *List[T] | |
val T | |
} |
This file contains 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
twinPrimes = filter twin (zip primes (tail primes)) | |
twin (x,y) = y == x+2 | |
primes = sieve [2..] | |
sieve (p:ps) = p : sieve [x | x <- ps, mod x p /= 0] |
This file contains 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
// U-combinator | |
const U = f => f(f) | |
const Uz = f => v => f(f)(v) // like U, but for eager/non-lazy languages | |
// (stops infinite expansion caused by eager evaluation) | |
// Y/Z-combinator | |
const Y = g => (f => g( f(f) )) (f => g( f(f) )) // or g => U( f => g( U(f) ) ) | |
const Z = g => (f => g( v => f(f)(v) )) (f => g( v => f(f)(v) )) // or g => U( f => g( Uz(f) ) ) | |
// properties: | |
// Y g = g(Y g) = g(g(Y g)) = g(...g(Y g)...) |
This file contains 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* parenthesesPermutations_(prefix, nOpen, nClose, score) { | |
if (score < 0) { | |
return; | |
} | |
if (nOpen === 0 && nClose === 0) { | |
if (score === 0) { | |
yield prefix; | |
} | |
return; |
This file contains 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
!pragma teoz true | |
!theme plain | |
hide footbox | |
skinparam ParticipantPadding 20 | |
skinparam BoxPadding 20 |
This file contains 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 Tuple<T=any> = readonly T[] | |
type Nullable<T> = T extends null | undefined ? T : T | null | undefined | |
type ErrorFirstCallback<E extends Error, R> = (err: Nullable<E>, result: R) => void | |
type Resolve<R> = (value: R | PromiseLike<R>) => void | |
type Reject<E extends Error> = (reason: Nullable<E>) => void | |
function makeCallback<E extends Error, R>(resolve: Resolve<R>, reject: Reject<E>): ErrorFirstCallback<E, R> { | |
return (error, result) => { | |
if (error) reject(error) | |
else resolve(result) |
This file contains 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 readline from 'readline' | |
import { Readable } from 'stream' | |
import { EOL } from 'os' | |
class MyUrl extends URL { | |
constructor(...args) { | |
super(...args) | |
this.searchKeys = new Set(this.searchParams.keys()) | |
} | |
isSame(other) { |
This file contains 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 { promises as fs } from 'fs'; | |
import { JSDOM } from 'jsdom'; | |
import MarkdownIt from 'markdown-it'; | |
import open from 'open'; | |
import { tmpdir } from 'os'; | |
import { join as joinPath } from 'path'; | |
import request from 'request-promise-native'; | |
import SVGO from 'svgo'; | |
const PLANTUML_SERVER = 'https://www.plantuml.com/plantuml' |
This file contains 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
// https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher#Description | |
class VigenereCipher { | |
constructor(...keys) { | |
this.keys = Array.from(keys).map(normalize) | |
} | |
get key() { return this._key } | |
set key(key) { | |
this._keys = [key] | |
this._key = normalize(key) |
NewerOlder