Skip to content

Instantly share code, notes, and snippets.

View onjin's full-sized avatar

Marek Wywiał onjin

View GitHub Profile
@onjin
onjin / changelog.py
Last active October 25, 2023 09:57
changelog.md generate from conventional commits git log
#!/usr/bin/env python
# NOTE: use newer & fixed version as package: https://pypi.org/project/mkchangelog/
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse
import json
import logging
import os
import re
@onjin
onjin / creator_producers_consumers_async.py
Created March 15, 2024 08:17
example creator/producers/consumers async patter - reusable
import asyncio
import httpx
from typing import Callable, List, Any
from rich.console import Console
console = Console()
async def producer(
@onjin
onjin / supervised_workers.py
Created April 2, 2024 11:47
supervised async python workers
import asyncio
import argparse
import random
from typing import Any
async def worker(name: str, queue: asyncio.Queue[str], stop_event: asyncio.Event):
while not stop_event.is_set() or not queue.empty():
try:
# Try to get an item from the queue without indefinitely blocking
try:
@onjin
onjin / pysh
Created June 14, 2024 06:53
nix shell runner script for python and packages and optional venv
#!/usr/bin/env python
"""
pysh
This script provides a command-line interface (CLI) for creating and running a
nix-shell environment with specified Python packages. It supports using different
Python versions and can optionally create a temporary virtual environment (venv)
to install packages.
Purpose:
@onjin
onjin / Makefile
Created July 5, 2024 09:04
Makefile help generator
.DEFAULT_GOAL := help
# use '# >>> Build commands' to create section
# use '# target: target description' to create help for target
# example output from this file:
# $ make
# Usage:
#
# >>> Section 1
@onjin
onjin / state_vs_strategy.py
Created March 10, 2025 21:41
State Pattern vs Strategy Pattern
"""
Comparison of State and Strategy Patterns in Python
This script demonstrates the similarities and differences between the State and Strategy patterns.
Each pattern is implemented separately with an execution example.
### Similarities:
1. **Encapsulation of Behavior** – Both patterns encapsulate behaviors in separate classes, promoting the **Single Responsibility Principle (SRP)**.
2. **Dynamic Behavior Switching** – Both allow switching between different behaviors (strategies or states) at runtime.
3. **Use of Composition Over Inheritance** – Instead of using conditionals (`if-else` or `switch` statements), they promote using composition to delegate behavior.