Skip to content

Instantly share code, notes, and snippets.

Avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / Makefile
Last active Aug 10, 2020
Conway's game of life with pbm files
View Makefile
CC = gcc
CFLAGS = -O3 -std=c99
.PHONY: test
test: life
./life < gosper.pbm | mpv --no-correct-pts --fps=20 --scale=oversample -
.PHONY: time
time: life-limited
time ./$< < pulsar.pbm > /dev/null
@louisswarren
louisswarren / spiral.py
Last active Aug 8, 2020
Spirals of numbers
View spiral.py
class Turtle:
directions = [( 0, 1),
(-1, 0),
( 0, -1),
( 1, 0)]
def __init__(self, x=0, y=0, d=0, boundary=lambda x, y: True):
self.x = x
self.y = y
self.d = d
@louisswarren
louisswarren / Makefile
Last active Aug 5, 2020
Pipe pattern drawing
View Makefile
.PHONY: display
display: out.png
feh -Z $^
out.png: out.pbm Makefile
convert $< $@
out.pbm: pipes
./$^ > $@
@louisswarren
louisswarren / Makefile
Last active Jul 27, 2020
Sudoku solver
View Makefile
.PHONY: test
test: seppuku
./seppuku < example.txt
seppuku: seppuku.c
gcc -std=c99 -o $@ $<
View bnf.py
import re
from lexer import lex, LexError
def readlines_iter(f):
while (line := f.readline()):
yield line[:-1]
def main(lines):
tok_patterns = {}
@louisswarren
louisswarren / gitdemo-lstree
Last active Jul 9, 2020
Scripts for a git demo
View gitdemo-lstree
#!/bin/sh
git ls-tree -r --name-only ${1:-master}
@louisswarren
louisswarren / Makefile
Last active Jun 15, 2020
Farbfeld test
View Makefile
CC = gcc
CFLAGS = -fopenmp -lm -std=c99 -pedantic -Wall
TARGETS = abstract.ff
.PHONY: default
default: $(TARGETS) $(TARGETS:.ff=.png)
%.png: %.ff
ff2png < $< > $@
View python-proposals.md

Python Proposals

cast decorator

The common python pattern

def foo():
    tmp = []
View blackjack.py
from collections import namedtuple
from enum import Enum
import random
compose = lambda f: lambda g: lambda *a, **k: f(g(*a, **k))
class Face(Enum):
ACE = 'A'
TWO = '2'
You can’t perform that action at this time.