Skip to content

Instantly share code, notes, and snippets.

View thegamecracks's full-sized avatar

thegamecracks thegamecracks

View GitHub Profile
@thegamecracks
thegamecracks / numerals.py
Created May 31, 2024 03:12
Personal practice for pronouncing numerals in Japanese
import difflib
import math
import random
DIGITS = {
1: "ichi",
2: "ni",
3: "san",
4: "yon",
@thegamecracks
thegamecracks / slice.py
Last active May 31, 2024 02:59
Interactive visualization of Python slicing with Tkinter
import sys
from tkinter import StringVar, Text, Tk
from tkinter.ttk import Entry, Frame, Label
from typing import Sequence
if sys.platform == "win32":
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(2)
@thegamecracks
thegamecracks / map_future.py
Last active May 17, 2024 13:23
Wrapping concurrent.futures.Future to support .map() method chaining
from __future__ import annotations
from concurrent.futures import Future, InvalidStateError, ThreadPoolExecutor
from contextlib import suppress
from typing import Any, Callable, TypeVar
T = TypeVar("T")
R_co = TypeVar("R_co", covariant=True)
@thegamecracks
thegamecracks / sphinx_reader.py
Created May 10, 2024 04:51
Basic sphinx objects.inv parser I wrote a year ago
"""
objects.inv v2 Syntax Reference:
https://sphobjinv.readthedocs.io/en/stable/syntax.html
Python Discord Bot Reference:
https://github.com/python-discord/bot/blob/main/bot/exts/info/doc/_inventory_parser.py
"""
import re
import zlib
from dataclasses import dataclass
from typing import Generator
@thegamecracks
thegamecracks / wrap_label.py
Last active May 12, 2024 12:35
A tkinter label with automatic text wrapping
import sys
from tkinter import Event, Tk
from tkinter.ttk import Frame, Label
if sys.platform == "win32":
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(2)
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce malesuada ipsum enim, feugiat venenatis sapien tempus et. Morbi auctor egestas metus vel faucibus. Nullam in nunc nisi. Maecenas eget sagittis ante. Sed ut turpis turpis. Morbi suscipit massa ac efficitur iaculis. Suspendisse risus nisi, tempor non pulvinar sed, vehicula a sapien. Pellentesque iaculis ligula sed sapien faucibus, eget mollis magna volutpat. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi porttitor luctus tellus, nec tincidunt lacus. Nunc dui eros, laoreet sed pretium id, porttitor eget nunc."
@thegamecracks
thegamecracks / 1-readme.md
Last active May 1, 2024 20:34
A persistent job scheduler built on SQLite
@thegamecracks
thegamecracks / event.py
Last active April 19, 2024 04:48
A thread-safe event compatible with asyncio
# Requires Python>=3.11
import asyncio
import contextlib
import threading
import unittest
class Event(threading.Event): # TODO: any better name?
"""A thread-safe event compatible with asyncio."""
@thegamecracks
thegamecracks / composite.py
Last active April 17, 2024 16:40
A basic command-line program for compositing two images using Pillow
"""
Dependencies:
Pillow>=10.3.0
usage: composite.py [-h] [-s SCALE] [-o OFFSET] image
Create a composite of the given image and display it.
The window can be clicked to toggle it as an overlay.
You can also right click it to save the image.
@thegamecracks
thegamecracks / bands.py
Created April 11, 2024 23:34
A collection of some random scripts I wrote on Termux
#!/usr/bin/env python3
"""Converts resistor parameters into their corrresponding color bands."""
import argparse
from decimal import Decimal
# list of colors ordered by their corresponding digit (0-9)
DIGIT_BANDS = [
"black",
"brown",
"red",
@thegamecracks
thegamecracks / 1-readme.md
Last active April 15, 2024 00:32
A simple image batch resizer using Pillow