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
| namespace Example1 { | |
| type Sig<I, O> = (input: I) => O; | |
| declare const imm: (int: number) => Sig<[], [number]>; | |
| declare const add: () => Sig<[number, number], [number]>; | |
| interface Builder<Stack> { | |
| $: <I extends any[], O extends any[]>( | |
| instr: Stack extends [...I, ...any[]] ? Sig<I, O> : never | |
| ) => Builder<Stack extends [...I, ...infer R] ? [...O, ...R] : never> | |
| } |
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 VarName = string; | |
| type Expr = Var | App | Lam | Let; | |
| type Var = { $: 'var', readonly name: VarName } | |
| const Var = (name: VarName): Var => ({ $: 'var', name }); | |
| type App = { $: 'app', readonly left: Expr, readonly right: Expr } | |
| const App = (left: Expr, right: Expr): App => ({ $: 'app', left, right }); | |
| type Lam = { $: 'lam', readonly name: VarName, readonly expr: Expr } | |
| const Lam = (name: VarName, expr: Expr): Lam => ({ $: 'lam', name, expr }); | |
| type Let = { $: 'let', readonly name: VarName, readonly def: Expr, readonly body: Expr } |
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 { createHmac } from 'crypto'; | |
| // token here | |
| const priv = "..."; | |
| const base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | |
| const base32tohex = (base32: string) => base32 | |
| .toUpperCase() | |
| .replace(/=+$/, "") | |
| .split('') |
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 React, { useState, useEffect, useReducer, FC } from 'react'; | |
| type FetchState = | |
| | { readonly type: 'initial' } | |
| | { readonly type: 'loading', readonly onAbort: () => void } | |
| | { readonly type: 'error', readonly error: unknown, readonly onRetry: () => void } | |
| | { readonly type: 'ok', readonly value: unknown } | |
| | { readonly type: 'aborted', readonly onRetry: () => void } | |
| const initial: FetchState = { type: 'initial' }; |
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 System.Random | |
| import Data.Array.IO | |
| import Control.Monad | |
| data Color = R | B deriving (Eq, Show) | |
| data Tree a = E | N Color (Tree a) a (Tree a) deriving (Eq, Show) | |
| data Result a b = D a | T b deriving (Eq, Show) | |
| sseq (D x) f = D x | |
| sseq (T x) f = f 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
| import qualified Data.Map.Lazy as M | |
| import Data.Maybe | |
| data Assoc = L | R deriving (Eq, Show) | |
| -- operator table | |
| table = [ | |
| (["||"], 20, L), | |
| (["&&"], 30, L), | |
| (["|"], 40, L), |
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 Dfa<Tag> = { | |
| trans: Map<string, [Tag, string][]>; | |
| initial: string[]; | |
| final: string[]; | |
| } | |
| const invertEdges = <Tag,>(auto: Dfa<Tag>): Dfa<Tag> => { | |
| const trans = new Map<string, [Tag, string][]>(); | |
| for (const [from] of auto.trans) { | |
| trans.set(from, []); |
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 "./styles.css"; | |
| import React, { useRef, useState, useEffect, useCallback } from "react"; | |
| import { unstable_batchedUpdates as batch } from "react-dom"; | |
| // call `f` no more frequently than once a frame | |
| export const throttle = (f) => { | |
| let token = null, | |
| lastArgs = null; | |
| const invoke = () => { | |
| f(...lastArgs); |
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 IfEquals<X, Y, A, B> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B; | |
| type ReadonlyKeys<U, T = { [K in keyof U]-?: U[K] }> = { | |
| [P in keyof T]: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P> | |
| }[keyof T]; | |
| type Full<T, R = ReadonlyKeys<T>> = { | |
| -readonly [K in keyof T]-?: { | |
| type: T[K], | |
| optional: T extends Record<K, any> ? false : true, | |
| readonly: K extends R ? true : false, | |
| } |
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
| 0eNq1XdtyGzkO/ZUpPduzvF/yuL+xlUrJdmema2VJJclz2VT+fVt2xq3YTfPgwH7aynoEkAAOmgQPwW+rm83DsD+M29Pq07fV3XC8PYz707jbrj6t/j2sb3fb4e6Xw/B1PP/v9K/bw3AafgnxX8fV1Wqc/o/j6tN/vq2O42/b9eYs4vT3fph+O56G++m/2K7vz//6IeD6HwGr79OPt3fDX6tP9vtV9+c3jwO5+JH7/vlqNWxP42kcngbw+I+/v2wf7m+GwyT15W+vVvvdcXya2LfVJKL8Gq9Wf68+ZfdrPAueFB7Pfzruh2mg97u7h81w7c+qzgN8Id51xVurke/78oNGfujLzxr5sSvfGY381JfvNfJzX37SyC99+VUjv3ble6eRb01fQVQp6APYqxBs+xAOKgjbPoaDCsO2D+KgArHtoziqUGz7MI4qGNs+jqMKx7YP5KgCsu0jOamQ7PpITiokuz6Sk+5b3EdyViHZzUge/tofhuPx+nRYb4/73eF0fTNsTgsKn03mHxXejYfh9unvaUlDkGsITQ1hSUN8peG434yn0/TH17Kf00Z4Mfar1ddxc/7NtEI77LbX+816WsxdrXYPp/3D6cu0jtwdJrXTnzfD19NqaSBJPtUkM2aWa6gyDUWuocg0zLA/L7FP6+1pWjvf34zb9Wm34LHn+I6vpF+dJZwOu82Xm+H39R+Tg86/eXIjtHY/noZh88PT38/SHs57hSpawF8EyyzinDyf1/NX5DjcPA77/fPiWtqQtgzvYcuvm4fxbp7En+szeubhpxwvDLk8fiuONt8MB7ekwIkVOJmCOYHux/1wfdpd/3aY5n/3huCAwMTL82a8HPmSyMiLDJAx5AkwyKyd8b1vZPamr7Pf5Mrh8OTSxhRS20ZXz3DfTt+QpW+Gn7Ph+ngc7m824/a36/v17e/j9jzO1xB+DqP0qG5SNu5/JICn+sMbkw6LG2YDh7C1ongIFpfsRegI7ifJb5kpLIMheMLVNmp8HQKjMgAqn9Yoizq |
NewerOlder