Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / Graph.agda
Last active November 27, 2019 02:29
Graphs in agda
module Graph where
open import Agda.Builtin.List
open import Agda.Builtin.Nat renaming (Nat to ℕ)
data Fin : ℕ → Set where
zero : ∀{n} → Fin (suc n)
suc : ∀{n} → Fin n → Fin (suc n)
len : {A : Set} → List A → ℕ
@louisswarren
louisswarren / pips.py
Created November 18, 2019 11:10
Graph sequence thing
def run(G, n):
for _ in range(n):
i = len(G[0]) - 1
for j in range(len(G)):
s = 0
if 0 <= j - 1:
s += G[j - 1][i]
if j + 1 < len(G):
s += G[j + 1][i]
G[j] += (s, )
@louisswarren
louisswarren / obviously.py
Created November 6, 2019 01:28
Decorator for adding obvious assertions to functions
def obviously(v, msg=''):
def outer(f):
def inner(*args, **kwargs):
r = f(*args, **kwargs)
if not v(r):
if msg:
errmsg = f.__name__ + ': ' + msg
else:
errmsg = f.__name__ + ': obviously not true'
raise Exception(errmsg)
@louisswarren
louisswarren / 2019-10-11.md
Last active October 15, 2019 04:44
Daily logging made easier with a simple python script

Friday 11th October 2019

A typical Friday

Keywords: logging, programming, overcast

I made a simple script for writing daily logs. This could be useful for taking notes regarding daily progress. This could have been valuable while doing my PhD. Oh well.

The weather isn't great today. Not terrible, just not great.

@louisswarren
louisswarren / openstd.py
Created October 8, 2019 04:12
Python open which uses a hyphen for stdin and stdout
import sys
def openstd(file, mode='r', *args, **kwargs):
if file == '-':
if 'r' in mode:
return sys.stdin
elif any(w in mode for w in 'wxa'):
return sys.stdout
else:
raise Exception("Mode not supported")
@louisswarren
louisswarren / closure.agda
Last active September 23, 2019 02:53
Closure (hull) operators in agda
open import Agda.Primitive
Pred : ∀{a} → Set a → Set _
Pred A = A → Set
_∈_ : ∀{a} {A : Set a} → A → Pred A → Set
x ∈ α = α x
_⊂_ : ∀{a} {A : Set a} → Pred A → Pred A → Set a
α ⊂ β = ∀ x → x ∈ α → x ∈ β
@louisswarren
louisswarren / openmenu.sh
Last active September 2, 2019 05:54
Dmenu is amazing
#!/bin/sh
cd ~
files=$(find * -not -path "*/.git/*" -not -name "*.agdai")
choice=$(echo "$files" | dmenu -i -p "xdg-open" $@)
xdg-open "$choice"
@louisswarren
louisswarren / tt.agda
Last active September 6, 2019 03:13
Type theory chapter of the HoTT book in Agda
open import Agda.Builtin.Equality
open import Agda.Primitive
Π : ∀{a b} → (A : Set a) → (B : A → Set b) → Set (a ⊔ b)
Π A B = (x : A) → B x
syntax Π A (λ x → B) = Π[ x ∶ A ] B
record _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
open import Agda.Builtin.Equality public
data ⊥ : Set where
¬_ : (A : Set) → Set
¬ A = A → ⊥
infix 4 _≢_
_≢_ : {A : Set} → A → A → Set
x ≢ y = ¬(x ≡ y)
@louisswarren
louisswarren / bloomheap.py
Last active July 20, 2019 11:47
Min heap using a tape of booleans
# Idea suggested by Michael Cowie
import itertools
class BloomHeap:
def __init__(self, *values):
self.tape = []
if len(values) == 1 and not isinstance(values[0], int):
self += values[0]
elif values: