This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""DnD ability scores roller helper. | |
CC0 - Credit appreciated. | |
by HacKan 2024 - https://hackan.net | |
Requirements: | |
- Python 3.10+ | |
""" | |
import argparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Handy cache helpers. | |
These are not yet production ready, as I haven't toroughly tested them, but close. | |
--- | |
Mandatory license blah blah: | |
Copyright (C) 2023 HacKan (https://hackan.net) | |
This Source Code Form is subject to the terms of the Mozilla Public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from contextlib import asynccontextmanager, contextmanager | |
from time import monotonic | |
from typing import Annotated, Any, AsyncGenerator, Generator, Hashable, Iterable, Literal, Optional, Sized, Union, overload | |
from sqlalchemy import event | |
from sqlalchemy.dialects.mysql.asyncmy import AsyncAdapt_asyncmy_cursor | |
from sqlalchemy.engine import URL, Connection, Engine, Row, create_engine | |
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker, create_async_engine | |
from sqlalchemy.orm import Session, sessionmaker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Pickle dumps test. | |
When pickle dumps a class, it will include the FQDN for the module. In this example, | |
we see how an imported class gets dumped including its module information, whereas | |
a local one has the current module name, which could be `__main__` or other depending | |
on how the interpreter was called! | |
If you save this file as `pickle_deal.py` and then in a python terminal you import it | |
`import pickle_deal`, you will see the following printed: | |
b'\x80\x04\x95)\x00\x00\x00\x00\x00\x00\x00\x8c\x0bpickle_deal\x94\x8c\x07Decimal\x94\x93\x94\x8c\x07123.456\x94\x85\x94R\x94.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Logo (programming language) turtle exercise.""" | |
import typing | |
import unittest | |
from dataclasses import dataclass | |
from enum import Enum | |
from itertools import zip_longest | |
from unittest import TestCase | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encode_int(number: int, *, alphabet: bytes) -> bytes: | |
"""Encode given number using the characters from the alphabet.""" | |
if number < 0: | |
raise ValueError('number must be positive') | |
if len(alphabet) != len(set(alphabet)): | |
raise ValueError('characters in the alphabet must be unique') | |
if number == 0: | |
return alphabet[0:1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
untrusted comment: HacKan minisign public key 8FE49E3814424F5C | |
RWRcT0IUOJ7kj6AFLyI3pHmT6dhr+WN8C2FR6HguMmEK0MnsSImqSmjg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# DEPRECATED BY: https://gitlab.com/hackancuba/blake2signer | |
# --- | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
# | |
# by HacKan (https://hackan.net), 2020. | |
# This software is provided as-is. You are free to use, share, modify | |
# and share modifications under the terms of that license, even with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright © 2020 HacKan | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
# | |
# This software is provided as-is. You are free to use, share, modify | |
# and share modifications under the terms of that license. Attribution | |
# is not required to share but is appreciated. | |
"""Calculate and sum time differences easily. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Time hashlib hashing functions. | |
Useful to help decide which one to use if time is of the escence. I still recommend | |
blake2 or sha384. | |
Copyright © 2020 HacKan <@hackancuba> | |
This program is free software. It comes without any warranty, to | |
the extent permitted by applicable law. You can redistribute it | |
and/or modify it under the terms of the Do What The Fuck You Want |
NewerOlder