Skip to content

Instantly share code, notes, and snippets.

@jcreedcmu
jcreedcmu / enum.ts
Created September 16, 2018 15:46
enum.ts
export function range(n) {
const rv = [];
for (let i = 0; i < n; i++)
rv.push(i);
return rv;
}
const r = Math.random;
type Point = {x: number, y: number};
@jcreedcmu
jcreedcmu / RelationList.agda
Created August 30, 2018 11:02
RelationList.agda
module RelationList (A : Set) where
-- Converse of relation
converse : (A → A → Set) → (A → A → Set)
converse R a a' = R a' a
-- A list of things (a1, a2, ... an) with relations
-- u -R-> a1 -R-> a2 -R-> ... -R-> an -R-> v
data Rist' (R : A → A → Set) (v : A) : (u : A) → Set where
rnil : {u : A} → (r : R u v) → Rist' R v u
{-# OPTIONS --without-K #-}
open import HoTT
module b where
A : Set
A = ℕ
rev : (A → A → Set) → (A → A → Set)
rev R a a' = R a' a
@jcreedcmu
jcreedcmu / DagTypes.agda
Created August 23, 2018 19:51
DagTypes.agda
module DagTypes where
data Unit : Set where
* : Unit
data Void : Set where
data Sum (A B : Set) : Set where
inl : A → Sum A B
inr : B → Sum A B
@jcreedcmu
jcreedcmu / mastodon.css
Created August 16, 2018 17:09
mastodon.css
@media (min-width: 1024px) {
.tabs-bar {display: flex; width: 785px; margin-left: calc(25% + 155px); z-index: 1;}
.columns-area {width: calc(50% + 300px); margin: -60px auto auto;}
.column {display: none;}
.column:last-child {display: flex; min-width: 800px; margin-top: 55px;}
}
a[data-preview-title-id="column.community"] {
display: none;
}
@jcreedcmu
jcreedcmu / a.ts
Created August 3, 2018 15:15
Diagram generator
function tmap<T, U>(f : (x : T) => U, xss: T[][]): U[][] {
return xss.map(xs => xs.map(x => f(x)));
}
function table<T>(xss: string[][], extra? : string): string {
const es = extra || '';
let buf = `<table ${es}>`;
xss.forEach(xs => {
buf += "<tr>";
xs.forEach(x => {
{-# OPTIONS --rewriting #-}
module a where
infix 30 _↦_
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
{-# BUILTIN REWRITE _↦_ #-}
data Foo : Set where
{-# OPTIONS --without-K #-}
module Cayley where
open import HoTT
-- The type of categories whose set of objects is X
record Cat (X : Set) : Set₁ where
constructor cat
field
hom : X → X → Set
@jcreedcmu
jcreedcmu / conditional.ts
Created March 14, 2018 20:58
More fun with conditional types
type Rec = {
'text': string,
'bool': boolean
};
type Un =
| {t: 'text', v: string}
| {t: 'bool', v: boolean};
type Datum<K, V> = { t: K, v: V };
@jcreedcmu
jcreedcmu / gist:b7c0232ecad88f02149850f94838d172
Created March 13, 2018 20:25
Fun things to do with Typescript 2.8
type Union =
{ type: 'A', a: string } |
{ type: 'B', b: number }
type FilterType<T, K> = (T extends { type: K } ? T : never);
type RemoveType<T, K> = (T extends K ? never : T);
type MappedUnion = {[P in Union['type']]: RemoveTypeFromRecord<FilterType<Union, P>, 'type'>};
type MappedUnionTarget = {