Skip to content

Instantly share code, notes, and snippets.

Avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / pool.c
Created May 11, 2021
Linked list pool
View pool.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#define POOL_NODE_HEADERS struct pool_node *prev, *next
struct pool_node {
POOL_NODE_HEADERS;
};
@louisswarren
louisswarren / findunicode.c
Last active May 5, 2021
Strip unicode (why was this tricky in php?)
View findunicode.c
#include <stdio.h>
#define BUF_SZ (1 << 16)
size_t
find_unicode(char *p, size_t n)
{
size_t i;
for (i = 0; i < n; ++i) {
if (p[i] & 128)
@louisswarren
louisswarren / Makefile
Last active Apr 26, 2021
Menger sponge sides
View Makefile
.PHONY: default
default: menger8.png
%.png: %.pbm
convert $^ $@
menger%.pbm: menger
./$^ $* > $@
menger%.svg: menger.py
@louisswarren
louisswarren / Makefile
Last active Apr 30, 2021
Key expansion
View Makefile
.PHONY: default
default: keys
./keys
keys: CFLAGS += -lcrypto
@louisswarren
louisswarren / list.c
Last active Apr 7, 2021
Ordered lists in C
View list.c
#include <stdio.h>
#include <stdlib.h>
struct list_entry {
struct list_entry *next;
int value;
};
struct list {
struct list_entry *head;
@louisswarren
louisswarren / encrypt.patch
Last active Mar 25, 2021
Patch for the encrypt hook for supporting disabling of workqueue
View encrypt.patch
--- 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)
View powermethod.py
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 Mar 17, 2021
That's 65% more word per word
View word.c
#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 Mar 4, 2021
Generate svg grids
View Makefile
.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 / Makefile
Last active Mar 4, 2021
Cellular automata
View Makefile
.PHONY: test
test: 027.png
.PHONY: all
all:
$(MAKE) -j 4 $$(for i in $$(seq -w 0 255); do echo -n "$$i.png "; done)
%.png: %.svg
convert $^ $@