Skip to content

Instantly share code, notes, and snippets.

View thegamecracks's full-sized avatar

thegamecracks thegamecracks

View GitHub Profile
@thegamecracks
thegamecracks / backup_world.py
Last active July 31, 2025 20:52
Yet another script to backup Minecraft worlds
#!/usr/bin/python3
"""Backup a Minecraft world into an archive.
CAUTION: This script has not been thoroughly tested and you may encounter bugs.
By default, this script will perform the following tasks:
1. Download mcrcon from https://github.com/Tiiffi/mcrcon, if needed
2. Send an RCON command to disable automatic saving and save the world
3. Create an archive of the world/ directory named "world-%Y-%m-%d.zip"
4. Send an RCON command to re-enable automatic saving
@thegamecracks
thegamecracks / notch.sqf
Last active May 19, 2025 01:45
A proof-of-concept approximation of missile notching in Arma 3
TGC_fnc_getAbsClosureSpeed = {
params ["_observer", "_target"];
private _dir = getPosATL _target vectorFromTo getPosATL _observer;
private _velocity = velocity _target;
private _angle = vectorNormalized _velocity vectorDotProduct _dir;
vectorMagnitude (_velocity vectorMultiply _angle)
};
TGC_fnc_isRadarGuided = {
params ["_ammo"];
private _property = configFile >> "CfgAmmo" >> _ammo >> "weaponLockSystem";
@thegamecracks
thegamecracks / resolve_case.py
Last active February 8, 2025 03:58
Structuring multiple prompts with discord.py message components
import datetime
import discord
from discord import app_commands
from discord.ext import commands
bot = commands.Bot(".", intents=discord.Intents.default())
@bot.command()
@commands.is_owner()
import datetime
import textwrap
from tkinter import BooleanVar, Tk
from tkinter.ttk import Checkbutton, Frame, Label, Style
LOREM_IPSUM = "Lorem ipsum odor amet, consectetuer adipiscing elit. Vivamus tincidunt ultricies accumsan feugiat ultrices sagittis tellus? Turpis penatibus convallis; suscipit nisl tincidunt suscipit litora? Ex fusce facilisis ullamcorper aenean iaculis metus pharetra libero. Feugiat fermentum fermentum mauris urna curabitur diam ad. Volutpat parturient arcu nec semper etiam vitae augue convallis dui. Gravida neque lacus donec interdum finibus ullamcorper. Sodales aliquam tempor tempor purus curabitur mauris ridiculus aptent."
class TaskCard(Frame):
MAX_DESCRIPTION_CHARS = 256
@thegamecracks
thegamecracks / table.py
Created January 8, 2025 02:36
A basic Tkinter table widget using frames, labels, and native relief styles
from tkinter import Tk
from tkinter.ttk import Frame, Label, Style
class Table(Frame):
"""Presents tabular data in a self-contained widget."""
def __init__(self, parent, rows, *, title):
super().__init__(parent)
@thegamecracks
thegamecracks / idle.py
Last active September 17, 2024 02:12
Subclassing asyncio event loop to run certain tasks when idle
# HACK: this proof of concept is not robust, don't use this in production!
# Minimum Python version: 3.11
import asyncio
from contextvars import Context
from typing import (
Any,
Callable,
Coroutine,
Generator,
Generic,
@thegamecracks
thegamecracks / quiz.py
Created August 31, 2024 20:08
A complete rewrite of someone else's Tkinter quiz GUI
import math
import operator
import random
import sys
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from tkinter import Misc, StringVar, Tk, Toplevel
from tkinter.simpledialog import askstring
from tkinter.ttk import Button, Entry, Frame, Label, Radiobutton
@thegamecracks
thegamecracks / text_resize.py
Last active August 30, 2024 04:06
Resizing Tkinter Text widgets by exact pixels
import contextlib
from tkinter import IntVar, TclError, Text, Tk
from tkinter.ttk import Entry, Frame
app = Tk()
app.title("Resizable Text")
app.geometry("500x300")
app.grid_columnconfigure(0, weight=1)
app.grid_rowconfigure(0, weight=1)
@thegamecracks
thegamecracks / docker.py
Last active August 15, 2024 15:10
Test scripts for handling signals to gracefully shut down a subprocess
import signal
import sys
from argparse import ArgumentParser
from pathlib import Path
from subprocess import Popen, TimeoutExpired
if sys.platform == "win32":
sys.exit("SIGINT and SIGTERM are not supported on Windows.")
# 1. Determine which signal to use
@thegamecracks
thegamecracks / asyncio.md
Last active August 8, 2024 17:26
Hasily-written quiz on asyncio's inner workings
  1. What makes asyncio different from multi-threading?
    • Hint: how many threads are used, and is multitasking preemptive or cooperative?
  2. Why does the distinction of blocking vs. non-blocking matter in an asyncio program? What happens when an asyncio program runs something that blocks?
  3. What is the difference between a "subroutine" and a "coroutine"?
  4. In Python, what is the distinction between a coroutine and a "coroutine function"?
    • Hint: official docs has a glossary entry for this
  5. What does a "task" represent in asyncio? What is it used for?
  6. An asyncio task takes a coroutine which will eventually start execution on the event loop. However, the event loop does not work with coroutines directly. What gets scheduled on the event loop instead?
    • Highly recommend reading the source code at this point