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 status = Symbol(); | |
const value = Symbol(); | |
const set = Symbol(); | |
const listeners = Symbol(); | |
class Promise { | |
constructor(callback) { | |
this[listeners] = []; | |
this[status] = "pending"; | |
const resolve = value => { |
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
class TaggedUnionValue< | |
TaggedUnion extends { [K in keyof TaggedUnion]: any[] }, | |
Tag extends keyof TaggedUnion | |
> { | |
constructor( | |
private readonly tag: Tag, | |
private readonly value: TaggedUnion[Tag], | |
) {} | |
} |
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 pipe<A, B>(f: (a: A) => B) { | |
return { | |
end: f, | |
pipe<C>(g: (b: B) => C) { | |
return pipe((a: A) => g(f(a))); | |
} | |
}; | |
} | |
function compose<A, B>(f: (a: A) => 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
class DataValid<T, E> { | |
constructor(public data: T) {} | |
} | |
class DataInvalid<T, E> { | |
constructor(public error: E, public got: unknown) {} | |
} | |
type DataValidity<T, E> = DataValid<T, E> | DataInvalid<T, E>; | |
type DataValidator<T, E> = (data: unknown) => DataValidity<T, E>; | |
type DataValidatorData< |
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 match = <T>(item: T) => < | |
Matchers extends ((item: T) => Match<any> | undefined)[] | |
>( | |
...cases: Matchers | |
): Exclude<ReturnType<Matchers[number]>, undefined>["value"] => { | |
for (const matcher of cases) { | |
const result = matcher(item) as ReturnType<Matchers[number]>; | |
if (result) { | |
return result.value; | |
} |
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 }, | |
]; |
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
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
# 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
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 |