Skip to content

Instantly share code, notes, and snippets.

Louis Warren louisswarren

Block or report user

Report or block louisswarren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
louisswarren / wtype.agda
Last active Jan 29, 2020
W-types in agda
View wtype.agda
-- Based on
data W (S : Set) (P : S Set) : Set where
_◁_ : (s : S) (P s W S P) W S P
data 𝟘 : Set where
data 𝟙 : Set where
: 𝟙
louisswarren / lift.agda
Last active Jan 10, 2020
Lift types by instance resolution in Agda
View lift.agda
data : Set where
zero :
suc :
data : Set where
nonneg :
negsuc :
data : Set where
frac_/suc_ :
louisswarren / Discrete.agda
Last active Dec 18, 2019
Instance resolution for decidable equality of discrete types
View Discrete.agda
module Discrete where
open import Agda.Builtin.Equality public
data : Set where
¬_ : {a} Set a Set a
¬ A = A
data Dec {a} (A : Set a) : Set a where
louisswarren / basic.agda
Created Dec 16, 2019
A basic imperitive language in agda
View basic.agda
open import Agda.Builtin.List
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.String
Num =
record Var : Set where
constructor var
idx :
louisswarren /
Created Dec 9, 2019
Redirect stdout to a file in python using with block
import sys
class stdout_to_file:
def __init__(self, f):
self.f = f
self.stdout = sys.stdout
def __enter__(self):
sys.stdout = self.f
louisswarren / Graph.agda
Last active Nov 27, 2019
Graphs in agda
View Graph.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 /
Created Nov 18, 2019
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 /
Created Nov 6, 2019
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
errmsg = f.__name__ + ': obviously not true'
raise Exception(errmsg)
louisswarren /
Last active Oct 15, 2019
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 /
Created Oct 8, 2019
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
raise Exception("Mode not supported")
You can’t perform that action at this time.