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
#![feature(io)] | |
#![feature(net)] | |
#![feature(core)] | |
extern crate hyper; | |
extern crate url; | |
static HOST: &'static str = "www.google.com"; | |
macro_rules! ret_err( | |
($e:expr) => {{ |
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
#!/usr/bin/env perl | |
# Copyright (c) 2016 | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to | |
# deal in the Software without restriction, including without limitation the | |
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
# sell copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# |
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
// Module streams | |
// | |
// This is effectively a pub-sub system with a few extra convenience methods. | |
// Fundamentally, observers are attached to a stream or property, and are called | |
// when the stream or property emits an event. | |
// | |
// By and large, most of the effort in this module is devoted to creating | |
// optimized streams and properties for passing around an arbitrary amount | |
// argument variables rather than wrapping up multi-part events into arrays. | |
// |
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 Thing<T> = { | |
thing: T; | |
} | |
const propertyTableFields = { | |
a: { thing: "A" }, | |
b: { thing: 5 }, | |
c: { thing: "C" }, | |
}; |
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 { Assignable, Exact } from "./check"; // https://gist.github.com/webstrand/b0f79ef6ed37839d1432466fe8ddbc1a | |
export type Json = JsonPrimitive | JsonMap | JsonList; | |
export type JsonProperty = undefined | JsonPrimitive | JsonMap | JsonList; | |
export type JsonPrimitive = null | string | number | boolean; | |
export type JsonMap = { [key: string]: JsonProperty }; | |
export type JsonList = Json[]; | |
export type ReadonlyJson = ReadonlyJsonPrimitive | ReadonlyJsonMap | ReadonlyJsonList; | |
export type ReadonlyJsonProperty = undefined | ReadonlyJsonPrimitive | ReadonlyJsonMap | ReadonlyJsonList; |
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 KeyofSubset<T, U> = Array<({ [P in keyof T]: T[P] extends U ? P : never })[keyof 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
type Spec = Atom | Dict | List; | |
type Atom = "bool" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "float32" | "float64" | "string" | "varuint" | "varint" | "buffer" | |
interface Dict { [key: string]: Spec } | |
interface List extends Array<Spec> { } | |
type TypeFromSpec<S extends Spec> = CondTypeFromAtom<S> | CondTypeFromDict<S> | CondTypeFromList<S>; | |
type TypeFromAtom<S extends Atom> = string; | |
type TypeFromDict<S extends Dict> = { [P in keyof S]: TypeFromSpec<S[P]> } | |
type TypeFromList<S extends List> = { [P in keyof S]: TypeFromSpec<S[P] extends Spec ? S[P] : never> } | |
type CondTypeFromAtom<S> = S extends Atom ? TypeFromAtom<S> : never; |
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
// Find the first item of a list. | |
export type Head<List extends any[]> = List['length'] extends 0 ? never : List[0]; | |
// Find the last item of a list. | |
export type Last<List extends any[]> = number extends List['length'] ? List[1e+309] : _Last<List>; | |
type _Last< | |
Tuple extends any[], | |
_I extends number = Tail<Tuple>['length'] | |
> = Tuple extends [] ? never : _I extends keyof Tuple ? Tuple[_I] : never; |
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
export type MapTree<K extends readonly [unknown, ...unknown[]], V> = { | |
0: Map<K[number], V>, | |
1: ((..._: K) => any) extends ((_: infer Head, ...__: infer Tail) => any) | |
? Tail extends readonly [unknown, ...unknown[]] | |
? Map<Head, MapTree<Tail, V>> | |
: never | |
: never | |
}[K extends readonly [unknown] ? 0 : 1] & { | |
setKey(key: Readonly<K>, value: V): void; | |
getKey(key: Readonly<K>): V | undefined; |
OlderNewer