Skip to content

Instantly share code, notes, and snippets.

.CodeMirror {
background: white;
}
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<!-- Policy file for xmlsocket://socks.example.com -->
<cross-domain-policy>
<!-- This is a master socket policy file -->
<!-- No other socket policies on the host will be permitted -->
<site-control permitted-cross-domain-policies="master-only"/>
var slice = Array.prototype.slice;
function thunkify(fn) {
return function (/* args */) {
var args = slice.call(arguments);
return function (cb) {
var args1 = args;
args1.push(cb);
fn.apply(this, args1);
};
};
// Adapted from http://lukajcb.github.io/blog/functional/2018/01/03/optimizing-tagless-final.html
import { Applicative, Applicative1 } from 'fp-ts/lib/Applicative'
import { Apply, Apply1, Apply2C, applySecond, liftA4 } from 'fp-ts/lib/Apply'
import * as array from 'fp-ts/lib/Array'
import * as const_ from 'fp-ts/lib/Const'
import { HKT, Type, Type2, URIS, URIS2 } from 'fp-ts/lib/HKT'
import { IO, io, URI as IOURI } from 'fp-ts/lib/IO'
import { Option, some } from 'fp-ts/lib/Option'
import { getProductSemigroup, Semigroup } from 'fp-ts/lib/Semigroup'
@reverofevil
reverofevil / es6-estree.ts
Last active December 23, 2018 04:38
Attempt at proper Mozilla AST typings for ES6
// if you've found this in Google, take a look into https://github.com/babel/babel/tree/master/packages/babel-types first
export type Node = AssignmentProperty
| CatchClause
| ClassBody
| ExportAllDeclaration
| ExportDefaultDeclaration
| ExportNamedDeclaration
| Expression
| Identifier
@reverofevil
reverofevil / index.ts
Created May 3, 2019 22:19
Isomorphic API typing
import { Type, URIS as Uris } from 'fp-ts/lib/HKT';
type JsonMap = { [K: string]: Json }
interface JsonArray extends Array<Json> {}
type Json = JsonMap | JsonArray | number | string | boolean | null
interface Prim<Uri extends Uris> {
num: Type<Uri, number>;
obj: <O>(ss: { [K in keyof O]: Type<Uri, O[K]> }) => Type<Uri, O>;
}
@reverofevil
reverofevil / hoc.ts
Created May 24, 2019 16:33
How to type HOCs in TS
import {ComponentType} from 'react';
import {Omit, Shared, Matching, GetProps} from 'react-redux';
export type Hoc<InjectedProps> = <
C extends ComponentType<Matching<InjectedProps, GetProps<C>>>
>(
WrappedComponent: C,
) => ComponentType<Omit<GetProps<C>, keyof Shared<InjectedProps, GetProps<C>>>>;
@reverofevil
reverofevil / rtti.ts
Created December 1, 2019 23:10
io-ts done right: arbitrarily handled runtime type information (overloading) for typescript
// hkt.ts
interface TagToHkt<T> { }
export type Tag = keyof TagToHkt<any>
export type Apply<F extends Tag, T> = TagToHkt<T>[F]
// util.ts
export type Intersect<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void)
? I
: never;
export type IndexForSure<O, K extends string> = O extends { [K1 in K]: any } ? O[K] : never
@reverofevil
reverofevil / cpp-guide-en.md
Last active November 7, 2022 11:32
C++ minimum for competitive programming

By sharpc and udpn. Code samples by Evil_Stivie.

This is theoretical STL minimum for competitive programmers, a subset of features of C++ standard library useful for solving algorithmic problems. Topics are grouped mostly by STL header file name and context of use. Almost all names you might encounter in this guide are in std namespace. For it, and only for it, you should add below all #includes:

using namespace std;

<iostream>, <iomanip>

cout, cin, while (cin >> ...)

@reverofevil
reverofevil / example.ts
Created April 5, 2021 10:58
Custom type error messages in TypeScript
declare const StaticErrorTag: unique symbol;
type StaticError<E extends string> = { [StaticErrorTag]: E }
type AAndBAreSame<T> = T extends {a: any}
? T extends {b: T["a"]}
? T
: StaticError<"Types of `a` and `b` differ">
: StaticError<"No `a` field">
const f = <T,>(t: T & AAndBAreSame<T>) => {};