Skip to content

Instantly share code, notes, and snippets.

Avatar
🍜
focusing on pho

Louis Maddox lmmx

🍜
focusing on pho
View GitHub Profile
@lmmx
lmmx / list_build.py
Last active Nov 4, 2022
Recursive classmethod that fetches state from each parent class down to the base class. As a minimal example, builds a list. In `list_build.py` every class in the MRO must have the variable set (if no change, it must be `[]`). In `list_build_skippable.py` classes are skipped if the variable is not set.
View list_build.py
class A:
x = [1]
@classmethod
def fetch(cls, name: str = "x") -> list[int]:
is_base_cls = super().__thisclass__ is cls
parent_cls = cls.mro()[1]
prev = [] if is_base_cls else parent_cls.fetch(name=name)
return prev + getattr(cls, name, [])
@lmmx
lmmx / indirect_fixture_enums_synced_test.py
Last active Oct 27, 2022
Example of a `pytest.indirect` fixture passing along its name ("a" or "b", as `request.param`) to look up values rather than parametrising directly in a decorator
View indirect_fixture_enums_synced_test.py
from enum import Enum
from pytest import fixture, mark
class Int1(Enum):
small = 0
large = 100
@lmmx
lmmx / check.py
Last active Oct 23, 2022
Demo of overriding the function definition check in PyFlakes via subclass method, adapted from https://github.com/PyCQA/pyflakes/blob/master/pyflakes/api.py
View check.py
import ast
from pyflakes import checker, reporter
class CheckerSnooper(checker.Checker):
verbose: bool
def __init__(self, *args, **kwargs):
self.verbose = kwargs.pop("verbose", False)
@lmmx
lmmx / extract_audio_transcribe.sh
Created Oct 1, 2022
extract audio from an OBS Studio recording and transcribe with Whisper
View extract_audio_transcribe.sh
recfile="2022-10-01 19-44-24"; ffmpeg -i "$recfile.mkv" -q:a 0 -map a "$recfile.mp3"; whisper --model large --language en "$recfile.mp3"
@lmmx
lmmx / wood-chuck.md
Last active Sep 28, 2022
Wood chuck dialogue
View wood-chuck.md

Louis "Hi Craig"

Craig "Hi Louis"

Louis "How much wood could a woodchuck chuck if a woodchuck could chuck wood?"

Craig "He would chuck, he would, as much as he could, and chuck as much wood as a woodchuck would if a woodchuck could chuck wood"

Louis "I just checked and in 1988, a New York fish and wildlife technician named Richard Thomas calculated the volume of dirt in a typical 25–30-foot long woodchuck burrow and determined that if the woodchuck had moved an equivalent volume of wood, it could move "about 700 pounds (320 kg) on a good day, with the wind at his back"."

@lmmx
lmmx / diarise.py
Last active Nov 10, 2022
Python commands to create speaker diarisation
View diarise.py
# ffmpeg -i foo.m4a foo.wav
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
diarization = pipeline("foo.wav")
# RTTM format https://catalog.ldc.upenn.edu/docs/LDC2004T12/RTTM-format-v13.pdf
with open("foo.rttm", "w") as rttm:
diarization.write_rttm(rttm)
@lmmx
lmmx / REPRO_CONDA_SETUP.md
Last active Aug 31, 2022
Demo of Stable Diffusion usage, storing the prompt in metadata https://twitter.com/permutans/status/1562471438501548034
View REPRO_CONDA_SETUP.md
conda create -n diffusers
conda activate diffusers
conda install -y pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
pip install diffusers transformers piexif

OUTDATED For hf_stablediffusion_img2img.py download https://github.com/huggingface/diffusers/blob/main/examples/inference/image_to_image.py (edit: this has been deprecated)

For hf_stablediffusion_inpaint.py run pip install git+https://github.com/huggingface/diffusers.git (not yet been released). At time of writing the DDIM scheduler worked, the default PNDM one did not.

@lmmx
lmmx / emoji-10.md
Last active Aug 12, 2022
Smiley face
View emoji-10.md

!dream "fantastical vibrant bulbous weird!!!!!!!!!!! smiley face emoji shaped cloud with holes for eyes and mouth, in a nature scene by marc adamus, high definition, rays of light breaking behind the emoji, 😃😀😄☺️🙃😉😗, cheerful, rave art" -i -n 9

@lmmx
lmmx / handler.py
Created Aug 4, 2022
Event handling with TypdeDict
View handler.py
import logging
from sys import version_info
from typing import NoReturn, TypedDict
logger = logging.getLogger(__name__)
LeftoverItems = dict # Anything not ingested can also be returned
UnusedParams = list[str] # Anything not validated (i.e. weakly expected)
ValidatedIngested = TypedDict("ValidatedIngested", {"one": int}, total=False)