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
// 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
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
// Since typescript nominally types string based enums, we emulate | |
// the subtractive type `object - T` by making all the properties | |
// T optional and setting their types to a non-exported enum. | |
// | |
// The enum name is long and descriptive to help with debugging. | |
const enum CannotAssignToPropertyFromExcludedObject { ϕ = "ϕ" } | |
type Excluding<T extends object> = { [P in keyof T]?: CannotAssignToPropertyFromExcludedObject; } & { [prop: string]: any; } | |
// Note: If some overlap is acceptable, providing that the overlapping property extends T[P], use | |
// type Excluding<T extends object> = Partial<T> & { [prop: string]: any }; |
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
// 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
import {Multimap, ReadonlyMultimap} from "./multimap"; | |
export type NoInfer<T> = T & { [K in keyof T]: T[K] }; | |
function identityProjection<T>(value: any, primary: T) { return primary } | |
/** | |
* Project some sequence of values onto a Map using keys generated by | |
* {@link surrogate}. Values with the same surrogate key will overwrite, with | |
* the later insertion order overwriting the earlier. |
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
/** | |
* A TypeScript type compatible runtime type-verification system. | |
* | |
* Each instance of {@link Runtype} is a complete type-verification system that | |
* can prove that an _unknown_ type is actually _known_ type. Runtypes can be | |
* composed via the convenience constructors {@link Union}, | |
* {@link Intersection}, {@link Tuple}, and {@link struct}. Additionally, when | |
* constructing a new {@link Runtype}, a parent constraint may be specified in | |
* {@link RuntypeConfig}. | |
* |
OlderNewer