Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / encrypt.patch
Last active March 25, 2021 22:20
Patch for the encrypt hook for supporting disabling of workqueue
--- encrypt 2021-03-26 11:18:21.981072579 +1300
+++ encrypt.no-workqueue 2021-03-26 11:18:21.981072579 +1300
@@ -62,6 +62,12 @@
allow-discards)
cryptargs="${cryptargs} --allow-discards"
;;
+ no-read-workqueue)
+ cryptargs="${cryptargs} --perf-no_read_workqueue"
+ ;;
+ no-write-workqueue)
@louisswarren
louisswarren / powermethod.py
Created March 24, 2021 22:43
Power method
class LinearMap:
def __init__(self, matrix):
self.domain_dimension = len(matrix[0])
self.range_dimension = len(matrix)
self.matrix = matrix
# def shifted(self, c):
# return LinearMap(tuple(tuple(r - c if i == j else r
# for j, r in enumerate(row))
# for i, row in enumerate(self.matrix)))
@louisswarren
louisswarren / word.c
Last active March 17, 2021 02:24
That's 65% more word per word
#include <stdint.h>
#include <stdio.h>
uint64_t
strtoword(char *s)
{
uint64_t word = 0;
word |= ((uint64_t) *(s++) & 0x1f) << 55;
word |= ((uint64_t) *(s++) & 0x1f) << 50;
word |= ((uint64_t) *(s++) & 0x1f) << 45;
@louisswarren
louisswarren / Makefile
Last active March 4, 2021 01:26
Generate svg grids
.PHONY: test
test: grid6.svg grid7.svg grid8.svg grid9.svg grid6.png grid7.png grid8.png grid9.png
grid%.svg: grid.py
python3 $^ $* > $@
%.png: %.svg
convert $^ $@
.PHONY: clean
@louisswarren
louisswarren / 110.svg
Last active November 30, 2021 04:16
Cellular automata
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@louisswarren
louisswarren / Makefile
Last active February 23, 2021 03:16
Register machine
.PHONY: test test2
test: aprog.rma assembler
./assembler < $<
test2: register prog.rm
echo 'Hello, world!' | ./register
aprog.rm: aprog.rma assembler
./assembler < $< > $@
@louisswarren
louisswarren / Makefile
Last active March 4, 2021 01:28
Svg files from python
n = 24
$(n).mp4: stringart.py
$(MAKE) -j 4 $$(for i in $$(seq -w 1 $n); do echo -n "$n-$$i.png "; done)
ffmpeg -r 2 -f image2 -s 800x800 -i $(n)-%02d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p $@
%.png: %.svg
convert $^ $@
$(n)-%.svg: stringart.py
@louisswarren
louisswarren / Makefile
Created February 3, 2021 02:08
Generate two versions of the same latex document
.PHONY: all
all: tutorial.pdf tutorial-solns.pdf
%.pdf: %.tex
pdflatex $^
%-solns.pdf: %.tex
pdflatex -jobname $(basename $@) '\def\SOLUTIONS{} \input{$^}'
.PHONY: clean
@louisswarren
louisswarren / inventory.tex
Created January 31, 2021 23:22
Inventory sheet
\documentclass[a5paper]{article}
\usepackage[a5paper,margin=1cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\pagenumbering{gobble}
\begin{document}
\begin{center}
\section*{Freezer inventory}
@louisswarren
louisswarren / mfwpp
Last active November 25, 2020 22:29
Mutex files with preprocessing
#!/bin/sh
# Generate all .m4 file outputs - being lazy and just re-running the script
# with an argument. To be safe AND lazy, add a useless argument just to make
# sure this doesn't fork bomb me some day if I change how this is done.
if [ -z "$1" ]; then
exec find $(dirname -- "$0") -name '*.m4' -exec "./$0" '{}' 'safety' \;
fi
# Generate $1 from its .m4 file.