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 FiberFunction<Args extends any[], Return> = ( | |
| cell: CellFunction | |
| ) => (...args: Args) => Return; | |
| type FiberInstance<Args extends any[], Return> = ( | |
| ...args: Args | |
| ) => [Return, FiberInstance<Args, Return>]; | |
| type FiberFactory = <Args extends any[], Return>( | |
| fiber: FiberFunction<Args, 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
| export function AsyncNode({ children }: { children: Promise<ReactNode> }) { | |
| return useLatestResolvedValue<ReactNode>(children, () => null) as any; | |
| // as any assertion needed for issue https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20356#issuecomment-336384210 | |
| } | |
| export function useLatestResolvedValue<Value>( | |
| promise: Promise<Value>, | |
| initial: () => Value | |
| ) { | |
| const [[value], dispatch] = useReducer< |
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 Lazy<Value> = () => Value | |
| export function lazy<Value>(thunk: () => Value){ | |
| let value: Value // will hold computed value | |
| let factory: (() => Value) | null = thunk // used as check if value is computed and allow thunk to be garbage collected | |
| return () => { | |
| if (!factory) { | |
| return value | |
| } else { | |
| value = factory() |
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 { any } from "prop-types"; | |
| type Cell = { initialized: boolean; state: any; next: any }; | |
| export function Cell(): Cell { | |
| return { initialized: false, state: null, next: null }; | |
| } | |
| export type CellFunction = <State, Initial>( | |
| callback: (state: State | Initial) => State, |
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
| /* | |
| let a = 1 | |
| let b = 2 | |
| const u = plus(a, mul(b,b)) | |
| const f = x => plus(a, x) | |
| const k = f(b) |
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
| extern crate crypto; | |
| use self::crypto::digest::Digest; | |
| use self::crypto::sha2::Sha256; | |
| use std::mem; | |
| use std::rc::Rc; | |
| fn main() { | |
| let mut hasher = Sha256::new(); | |
| // write input message |
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
| # You must run these command manually | |
| mkdir ipfs | |
| cd ipfs | |
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash | |
| source ~/.profile | |
| nvm install stable | |
| nvm use stable | |
| npm install -g yarn |
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 Tequal<A, B> = A extends B ? (B extends A ? true : false) : false; | |
| type Bind<P extends Record<string, any>, R> = Tequal<P, {}> extends false | |
| ? (<K extends keyof P>( | |
| key: K, | |
| value: P[K] | |
| ) => Bind<Pick<P, Exclude<keyof P, K>>, R>) | |
| : () => R; | |
| function curryNamed<Params extends Record<string, any>, R>( |
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 sourcecode | |
| case class Symbol(name: String)(implicit line: sourcecode.Line) | |
| case class Struct(tag: Symbol, entries: Map[Symbol, Struct]) | |
| sealed trait TypeTerm | |
| case class Union(cases: Map[Symbol, Map[Symbol, TypeTerm]]) extends TypeTerm |
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 ns = [ | |
| { name: "a", x: 200.01, y: 200.01 }, | |
| { name: "b", x: 220, y: 220 }, | |
| { name: "c", x: 180, y: 200.01 }, | |
| { name: "d", x: 182, y: 201 }, | |
| { name: "e", x: 230, y: 170 }, | |
| { name: "f", x: Math.random() * 400, y: Math.random() * 400 }, | |
| { name: "g", x: Math.random() * 400, y: Math.random() * 400 }, | |
| ]; |