Skip to content

Instantly share code, notes, and snippets.

View milkey-mouse's full-sized avatar

Milkey Mouse milkey-mouse

View GitHub Profile
@milkey-mouse
milkey-mouse / read.py
Created March 3, 2024 02:35
Create an audiobook from a text file with OpenAI TTS
#!/bin/env python3
import asyncio, os, string, sys
from contextlib import suppress
from aiolimiter import AsyncLimiter
FORMAT = "flac"
MAX_INPUT_LENGTH = 4096
COST_PER_CHAR = 0.030 / 1000
REQUESTS_PER_MIN = 10
@milkey-mouse
milkey-mouse / mutable.py
Created February 7, 2024 11:54
Interior mutability (like Rust's Cell<T>) in Python
from functools import update_wrapper
def Mutable(inner):
def rebind(unbound):
return lambda self, *args, **kwargs: unbound(
self.inner,
*(a.inner if isinstance(a, type(self)) else a
for a in args),
**{k: v.inner if isinstance(v, type(self)) else v
for k, v in kwargs.items()},
@milkey-mouse
milkey-mouse / async_agnostic.py
Created January 24, 2024 06:30
@async_agnostic decorator for running async functions at the REPL
import asyncio
def async_agnostic(corofn):
@wraps(corofn)
def wrapper(*args, **kwargs):
with suppress(RuntimeError):
loop = asyncio.get_running_loop()
if loop.is_running():
return corofn(*args, **kwargs)
return asyncio.run(corofn(*args, **kwargs))
#!/usr/bin/env python
# Usage: with both the terminal and /dev/input keylogger running, press every
# key on your keyboard. This program will correlate the two transcripts to
# generate a mapping from Linux kernel keycodes to terminal chars/escape codes.
#
# In other words, run:
#
# ./keylogger > kb-keylogger.csv & ./terminal > kb-terminal.csv
# killall -SIGINT keylogger
# ./generate-keymap.py
@milkey-mouse
milkey-mouse / 0000-fix-CVE-2019-5786.patch
Last active March 18, 2019 16:15
Chromium unstable patch for CVE-2019-5786
From 0b8ac062693ce67019dfef28f76e0c79db8fa0a3 Mon Sep 17 00:00:00 2001
From: Will Harris <wfh@chromium.org>
Date: Thu, 28 Feb 2019 19:32:41 +0000
Subject: [PATCH] Merge M73: FileReader: Make a copy of the ArrayBuffer when
returning partial results.
This is to avoid accidentally ending up with multiple references to the
same underlying ArrayBuffer. The extra performance overhead of this is
minimal as usage of partial results is very rare anyway (as can be seen
on https://www.chromestatus.com/metrics/feature/timeline/popularity/2158).
@milkey-mouse
milkey-mouse / ld-musl-workaround
Created April 13, 2018 16:00
I hate autoconf
#!/bin/bash
# When autoconf configure scripts look for the LIBC PATH, they assume ld
# prefaces the paths with "attempt to open /lib/path.so" (the behavior of
# GNU ld) while lld uses a different format. With CONFIGURE_LIBC_WORKAROUND
# set the output will be transformed to GNU ld's format.
if [ -n "${CONFIGURE_LIBC_WORKAROUND+1}" ] && (echo $@ | grep -q -- "--verbose"); then
exec -a $0 ld $@ 2> >(sed "s@^$0: /\(.*\)\$@attempt to open /\1 succeeded@g" >&2)
else
exec -a $0 ld $@
@milkey-mouse
milkey-mouse / procps-nongnu.patch
Created April 8, 2018 05:29
Patch for gentoo clang/musl sys-process/procps
diff --git a/proc/numa.h b/proc/numa.h
index c198d9d..1b2b4eb 100644
--- a/proc/numa.h
+++ b/proc/numa.h
@@ -22,7 +22,9 @@
#include <features.h>
-__BEGIN_DECLS
+#ifdef __cplusplus
@milkey-mouse
milkey-mouse / clang-nongnu.patch
Last active April 8, 2018 05:28 — forked from jstraarup/nongnu.patch
Make clang sanitizers ( sys-libs/compiler-rt-sanitizers-6.0.0 ) compile with musl
diff -ruN compiler-rt-6.0.0.src/lib/asan/asan_linux.cc compiler-rt-6.0.0.src-musl/lib/asan/asan_linux.cc
--- compiler-rt-6.0.0.src/lib/asan/asan_linux.cc 2018-02-07 20:51:13.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/asan/asan_linux.cc 2018-03-20 11:57:12.381740075 +0100
@@ -46,7 +46,7 @@
#include <link.h>
#endif
-#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
+#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS || SANITIZER_NONGNU
#include <ucontext.h>
@milkey-mouse
milkey-mouse / Makefile
Last active February 12, 2018 06:22
crtbegin.c and crtend.c for alpine2gentoo (BSD-licensed)
# Makefile for musl-clang crt's
all:
clang -fPIC -c crtbegin.c -o /usr/lib/crtbegin.o
ln -s /usr/lib/crtbegin.o /usr/lib/crtbeginS.o
ln -s /usr/lib/crtbegin.o /usr/lib/crtbeginT.o
clang -fPIC -c crtend.c -o /usr/lib/crtend.o
ln -s /usr/lib/crtend.o /usr/lib/crtendS.o
ln -s /usr/lib/crtend.o /usr/lib/crtendT.o
clean:
$ ./gradlew build --stacktrace
Incremental java compilation is an incubating feature.
Skipping debug jar:microg-ui-tools:preBuild UP-TO-DATE
:microg-ui-tools:preDebugBuild UP-TO-DATE
:microg-ui-tools:checkDebugManifest
:microg-ui-tools:preDebugAndroidTestBuild UP-TO-DATE
:microg-ui-tools:preDebugUnitTestBuild UP-TO-DATE
:microg-ui-tools:preReleaseBuild UP-TO-DATE
:microg-ui-tools:preReleaseUnitTestBuild UP-TO-DATE
:microg-ui-tools:prepareComAndroidSupportAnimatedVectorDrawable2531Library