Skip to content

Instantly share code, notes, and snippets.

@geofft
geofft / README.md
Last active January 14, 2025 02:17
dataenum

dataenum

This is a combination of @dataclass and enum.Enum, inspired by https://blog.glyph.im/2025/01/active-enum.html . I didn't like that the syntax required making two classes, and naively combining @dataclass on an enum.Enum doesn't work (and is documented as such in the standard library docs).

The key insight is that all dataclass fields must be typed, and all enum members should not be typed, so we can unambiguously write something like this:

@dataenum
class SomeNumber:
 result: int
@geofft
geofft / .gitignore
Last active October 9, 2024 00:44
PAM module in Swift
*.so
nixpkgs-*
@geofft
geofft / README.md
Last active January 26, 2025 21:38
I can't believe it's not numba
  • main.cc: A very abbreviated version of chapter 3 of the LLVM tutorial, hard-coding a single function
  • main.py: A translation into Python using llvmlite, also hard-coding a main function
  • pycomp.py: A compiler for an extremely small subset of Python.
$ ../venv/bin/python3 pycomp.py < sourcecode.py
$ cc -o output output.o
$ ./output
24.000000
@geofft
geofft / .md
Created September 24, 2024 19:15
Building TartanLlama/sdb via Nix

Quick setup instructions for building the code from Sy Brand's Building a Debugger on a machine with a working Nix installation. (There are many other perfectly good ways to get set up; if you don't already have Nix you might prefer to do something else.)

For Recursers, you can get to a machine with Nix by configuring your SSH key, waiting an hour or two, and doing ssh broome.cluster.recurse.com.

The author's worked source code is available on GitHub, so if you want to start partway through the book, do e.g.

git clone https://github.com/TartanLlama/sdb -b chapter-8
cd sdb
@geofft
geofft / gcd.py
Created July 8, 2024 02:29
Inadvisable adventures with the match statement
import operator
class Bigger(type):
def __new__(cls, op):
self = super().__new__(cls, "spam", (), {})
self.op = op
return self
def __instancecheck__(self, instance):
@geofft
geofft / flake8_profiles.patch
Created September 8, 2023 14:58
flake8_profiles
diff --git a/flake8_profiles.py b/flake8_profiles.py
index 2921f77..aadb0ae 100644
--- a/flake8_profiles.py
+++ b/flake8_profiles.py
@@ -3,6 +3,7 @@ from __future__ import print_function
import os.path
import sys
+from flake8.exceptions import ExecutionError
from flake8.options import config
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@geofft
geofft / Makefile
Last active February 9, 2018 02:59
all: uvsysc.so
uvsysc.so: uvsysc.c
$(CC) -fPIC -shared -o $@ $< -ldl
clean:
rm uvsysc.so
.PHONY: clean
#include <linux/seccomp.h>
#include <linux/filter.h>
#include <linux/audit.h>
#include <sys/prctl.h>
#include <asm/unistd.h>
#include <stddef.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
@geofft
geofft / Makefile
Last active September 18, 2015 19:05
LD_PRELOAD + RTLD_LOCAL
all: intermediate.so preload.so main
intermediate.so: intermediate.c
cc -o $@ -fPIC -shared $< -lgnutls
preload.so: preload.c
cc -o $@ -fPIC -shared $< -ldl
main: main.c
cc -o $@ $< -ldl