Skip to content

Instantly share code, notes, and snippets.

import inspect, builtins
def show_tree(base, level=0, max_depth=1):
if level > max_depth:
return
for name, obj in vars(builtins).items():
if inspect.isclass(obj) and issubclass(obj, base) and obj is not base:
print("\t" * level + f"- {name}")
show_tree(obj, level + 1, max_depth)
@MichielMe
MichielMe / decorators.py
Last active October 12, 2025 08:59
Decorators
import random
def retry(max_attempts=3):
def decorator(func):
def wrapper(*args, **kwargs):
for attempt in range(1, max_attempts + 1):
try:
print(f"Attempt {attempt}/{max_attempts}")
return func(*args, **kwargs)
except Exception as e:
@MichielMe
MichielMe / log_parser.py
Created October 11, 2025 13:29
Log Parser
# 1. Ingest the log lines
# 2. Filter log lines based on either lever or message substring
# 3. Extract and return only the message attribute of the logs
import sys
import json
def read_logs(filepath):
"""Reads the contents of a file line by line.