Skip to content

Instantly share code, notes, and snippets.

View tombulled's full-sized avatar

Tom Bulled tombulled

View GitHub Profile
@tombulled
tombulled / app.py
Created December 16, 2021 19:43
Python - Concatenate Numbers of Varying Bases
import math
def join_number(a: int, b: int, base: int) -> int:
return a * base ** math.ceil(math.log(b, base)) + b
assert join_number(2, 3, 10) == 23
assert join_number(4, 64, 10) == 464
assert join_number(573, 82, 10) == 57382
assert join_number(0b101, 0b111, 2) == 0b101111
@tombulled
tombulled / fish-python-rich-alias.sh
Last active December 24, 2020 20:37
Fish alias for python3 with colour support from rich
alias py='python3 -i -c "import sys, rich, rich.pretty, rich.traceback; rich.pretty.install(); rich.traceback.install(); rich.print(\'[b]Python[/b]\', f\'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}\')"' && funcsave py
@tombulled
tombulled / app.py
Created November 15, 2020 20:37
Stream a file, in this case an mp4 video, supporting range-requests using starlette
from starlette.applications import Starlette
from starlette.responses import StreamingResponse
from starlette.requests import Request
from starlette.routing import Route
from pathlib import Path
from typing import IO, Generator
"""
Stream a file, in this case an mp4 video, supporting range-requests using starlette
@tombulled
tombulled / config-highlight.def
Created April 11, 2020 19:37
Python IDLE theme inspired by Atom's One Dark
[One Dark]
normal-foreground = #ffffff
normal-background = #282c34
keyword-foreground = #c678dd
keyword-background = #282c34
builtin-foreground = #56b6c2
builtin-background = #282c34
comment-foreground = #5c6370
comment-background = #282c34
string-foreground = #98c379
@tombulled
tombulled / include.py
Last active April 30, 2020 21:26
Python3: Automatically attempt to import relative modules
'''
Module containing the utility function: include
'''
import pkgutil
import importlib
import sys
from typing import Callable
from _frozen_importlib import ModuleSpec
# Go here for the working version: https://gist.github.com/tombulled/d313c54a0681fcf0ba6d8092f11411e6#gistcomment-3069388
import hashlib
from pprint import pprint
import base64
import bytebuffer # https://github.com/alon-sage/python-bytebuffer, pip install bytebuffer
# Other ByteBuffer classes I've found: https://github.com/iGio90/PyByteBuffer, https://github.com/aglyzov/bytebuffer
import secrets
import pyaes # https://github.com/ricmoo/pyaes, pip install pyaes