View fib.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib_recursive(n, _mem={1: (1, 1), 2: (1, 1)}): | |
if n not in _mem: | |
a, x = fib_recursive(n - 2) | |
b, y = fib_recursive(n - 1) | |
_mem[n] = (a + b), (x + y + 1) | |
return _mem[n] | |
for i in range(1, 101): | |
f, n = fib_recursive(i) | |
print(f"{i:>3}: {f:>21} ({n:>21} steps)") |
View Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFLAGS = -Wall -Warray-bounds=2 -Wcast-align=strict -Wcast-qual -Wconversion -Wno-sign-conversion -Wdangling-else -Wdate-time -Wdouble-promotion -Wextra -Wfloat-conversion -Wformat-overflow=2 -Wformat-signedness -Wformat-truncation=2 -Wformat=2 -Winit-self -Wjump-misses-init -Wlogical-op -Wmissing-include-dirs -Wnested-externs -Wnull-dereference -Wpacked -Wpedantic -Wredundant-decls -Wshadow -Wshift-negative-value -Wshift-overflow=2 -Wstrict-aliasing -Wstrict-overflow=2 -Wstrict-prototypes -Wstringop-overflow=4 -Wstringop-truncation -Wswitch-default -Wswitch-enum -Wuninitialized -Wunsafe-loop-optimizations -Wunused -Wuse-after-free=3 -Wwrite-strings -fanalyzer -fmax-errors=2 -pedantic-errors | |
.PHONY: default | |
default: test | |
.PHONY: test | |
test: xods | |
./$< < /dev/null | diff expected.log - | head -n40 | |
xods.o: xods.c instructions.h |
View omp.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hello |
View asm_diff.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- units.asm 2023-06-18 12:02:32.313569952 +1200 | |
+++ units_unsafe.asm 2023-06-18 12:02:32.313569952 +1200 | |
@@ -1,7 +1,7 @@ | |
-metres_from_feet(feet): | |
+metres_from_feet(double): | |
divsd xmm0, QWORD PTR .LC0[rip] | |
ret | |
-feet_from_metres(metres): | |
+feet_from_metres(double): | |
mulsd xmm0, QWORD PTR .LC0[rip] |
View Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: default | |
default: out.png | |
%.png: %.ppm | |
convert $< $@ | |
out.ppm: draw.py image.so | |
python3 $< > $@ | |
image.so: image.c |
View Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: test | |
test: main | |
./$< | |
main: main.o incl_hello.o incl_message.o | |
main.o: main.c include_file.h | |
incl_%.o: incl_%.txt | |
@# If you always want to use includes as strings, you can check that | |
@# they are null-terminated at compile-time: |
View trim.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: | |
# trim FILE START END FADE_IN FADE_OUT | |
# 1 2 3 4 5 | |
# Trim the file between START and END, with fade in and out, and | |
# 2 seconds of silence after | |
dur=`expr "${3%:*}" \* 60 + "${3#*:}" - "${2%:*}" \* 60 - "${2#*:}"` | |
fo=`expr "$dur" - $5` |
View vet.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
vet() { | |
echo "Playing $1" | |
mpv --no-audio-display "$1" | |
read x | |
if [ "$x" == "y" ]; then | |
cp -v "$1" "$2/" | |
else | |
echo "Skipping $1" | |
fi |
View html.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static const char *closebuff[1024]; | |
static const char tabs[] = "\t\t\t\t\t\t\t\t"; | |
void | |
put(int *t, const char *msg) | |
{ | |
const char *indent = tabs + sizeof(tabs) - 1 - *t; | |
printf("%s%s\n", indent < tabs ? tabs : indent, msg); |
View fullwidth.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
int | |
main(void) | |
{ | |
int c, d; | |
while ((c = getchar()) != EOF) { | |
d = c & 0x1f; | |
if ((c | 0x20) > 0x60 && d < 26) { |
NewerOlder