Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@Pinacolada64
Pinacolada64 / datetime_practice.py
Last active April 30, 2025 23:54
Practicing datetime module
from datetime import datetime
def time_delta_in_words(d1: datetime, d2: datetime):
years = abs(d1.year - d2.year)
months = abs(d1.month - d2.month)
# if d1.month - d2.month < 12 then less than an entire year between events. therefore subtract a year
if months < 12:
years -= 1
print(f"less than 12 months between deltas, years now {years=}")
days = abs(d1.day - d2.day)
@Pinacolada64
Pinacolada64 / items.py
Last active April 1, 2025 22:51
Item ID strings
from typing import Optional, Any
class Item:
def __init__(self, item_id: int, name: str, description: str, owner: Optional[None], prefix: str = "I"):
self.prefix = prefix
self.item_id = item_id
self.owner = owner # TODO: can be a Player, but moving this after Player breaks inheritance
self.name = name
self.description = description
@Pinacolada64
Pinacolada64 / fog_of_war.py
Last active March 13, 2025 07:31
Dungeon crawler with fog-of-war map reveal
import logging
import random
from typing import Optional
from enum import Enum
# Dungeon map configuration
DUNGEON_SIZE = 20
REVEAL_RADIUS = 2
dungeon = [['.' for _ in range(DUNGEON_SIZE)] for _ in range(DUNGEON_SIZE)]
@Pinacolada64
Pinacolada64 / custom_codec_registration.py
Created February 18, 2025 06:31
Register a custom codec, with example text transformation.
import codecs
# Define your custom codec
class SimpleCodec(codecs.Codec):
def encode(self, input, errors='strict'):
# For simplicity, encoding is just the reverse.
return input[::-1], len(input)
def decode(self, input, errors='strict'):
@Pinacolada64
Pinacolada64 / color_map.py
Last active February 11, 2025 06:51
A color string parser meant to handle ANSI and Commodore terminal colors
import enum
import logging
from dataclasses import dataclass
from enum import Enum
import codecs
import cbmcodecs2
from colorama import init, Fore
@Pinacolada64
Pinacolada64 / submenus.py
Last active March 26, 2025 02:36
Options in sub-menus. A bit buggy.
import logging
from dataclasses import dataclass, field
from typing import List, Optional, Callable
from flags import Player, PlayerFlags, PlayerStat
def edit_string(prompt: str, data: str) -> str:
user_input = input(f"Edit {prompt}: ")
if user_input is None or user_input == data:
@Pinacolada64
Pinacolada64 / items.py
Created January 9, 2025 22:46
Trying out some Item classes and functions
from dataclasses import dataclass
from enum import StrEnum
from typing import Optional
# from flags import Size
@dataclass
class Item(object):
@Pinacolada64
Pinacolada64 / terminal_settings.py
Last active December 24, 2024 20:33
A better attempt at terminal settings
import logging
import textwrap
from dataclasses import asdict, dataclass, is_dataclass, field
from enum import Enum
"""
Goal: to display a settings menu. The way I think it should work:
- Enumerate through Player atributes, get a key (LINE_ENDING)
- Get a key name common to both SettingString.LINE_ENDING (to display in the menu item) and SettingValue.LINE_ENDING
@Pinacolada64
Pinacolada64 / scratch_3.py
Created December 6, 2024 00:07
Terminal settings attempt
import random
from dataclasses import dataclass, field
from enum import Enum
class ClientSettingsNames(str, Enum):
NAME = "Name"
ROWS = "Screen rows"
COLUMNS = "Screen columns"
RETURN_KEY = "Return key"
@Pinacolada64
Pinacolada64 / macro-preprocessor.py
Last active May 10, 2024 06:34
experiment to create a macro system for c64list
import re
import logging
import doctest
import tempfile
def process_macros(code: list):
"""
This function processes macro definitions and stores them in a dictionary.