Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / task.py
Last active March 20, 2020 05:57
Subpar
import heapq
class Task:
def __init__(self, time):
self.time = time
def __lt__(self, other):
return self.time < other.time
def __repr__(self):
@louisswarren
louisswarren / spite.py
Last active March 13, 2020 08:37
Spite in python
import curses
SPADE, HEART, DIAMOND, CLUB = '♠♥♦♣'
BOX = {
'light': ('┌───┐',
'│ │',
'│ │',
'└───┘'),
'heavy': ('┏━━━┓',
@louisswarren
louisswarren / cursesexample.py
Last active March 7, 2020 09:12
Menus with curses in python
import curses
class Menu:
def __init__(self, y, x, options):
self.y = y
self.x = x
self.options = options
self.height = len(options)
self.width = max(len(opt) for opt in options)
self.win = curses.newwin(self.height + 2, self.width + 8, y, x)
@louisswarren
louisswarren / bug-2-6-1.agda
Last active February 24, 2020 04:11
Bug in Agda version 2.6.0.1.20191219
-- Agda version 2.6.0.1.20191219
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Sigma
ℕ×ℕ : Set
ℕ×ℕ = Σ ℕ λ _ → ℕ
record Cont : Set where
@louisswarren
louisswarren / listdays.sh
Last active February 20, 2020 22:07
List all of the days in a given year
#!/bin/sh
if [ "$1" = "--help" ] || [ $1 = "-h" ]; then
echo "Usage: listdays [year] [format]"
exit
fi
if [ -n "$1" ]; then
year="$1"
else
year=`date "+%Y"`
@louisswarren
louisswarren / wtype.agda
Last active April 26, 2021 23:54
W-types in agda
-- Based on https://mazzo.li/epilogue/index.html%3Fp=324.html
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
louisswarren / lift.agda
Last active January 10, 2020 03:59
Lift types by instance resolution in Agda
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
data ℤ : Set where
nonneg : ℕ → ℤ
negsuc : ℕ → ℤ
data ℚ : Set where
frac_/suc_ : ℤ → ℕ → ℚ
@louisswarren
louisswarren / Discrete.agda
Last active December 18, 2019 04:56
Instance resolution for decidable equality of discrete types
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
louisswarren / basic.agda
Created December 16, 2019 08:01
A basic imperitive language in 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
field
idx : ℕ
@louisswarren
louisswarren / stdio_redirect.py
Last active November 5, 2021 06:35
Redirect stdout to a file in python using with block
import sys
class stdio_redirect:
def __init__(self, stdin=None, stdout=None, stderr=None):
self.stdin, self.sys_stdin = stdin, sys.stdin
self.stdout, self.sys_stdout = stdout, sys.stdout
self.stderr, self.sys_stderr = stderr, sys.stderr
def __enter__(self):
sys.stdin = self.stdin