Skip to content

Instantly share code, notes, and snippets.

View onjin's full-sized avatar

Marek Wywiał onjin

View GitHub Profile
@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 / gime.sh
Created April 7, 2026 21:14
Dead simple file templates store
#!/usr/bin/env bash
# Directory where your snippets are stored
SNIPPET_DIR="$HOME/snippets"
# Ensure fzf is installed
if ! command -v fzf &>/dev/null; then
echo "fzf is required but not installed."
exit 1
fi
@onjin
onjin / Example.java
Created January 14, 2026 07:42
Example java as script
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
record Options(
boolean verbose,
List<String> inputs
) {}
@onjin
onjin / enable_zoom_at_apt.sh
Created July 29, 2021 08:05
install/upgrade zoom by apt
#!/bin/bash
url=https://zoom.us/client/latest/zoom_amd64.deb
debdir=/usr/local/zoomdebs
aptconf=/etc/apt/apt.conf.d/100update_zoom
sourcelist=/etc/apt/sources.list.d/zoomdebs.list
sudo mkdir -p $debdir
( echo 'APT::Update::Pre-Invoke {"cd '$debdir' && wget -qN '$url' && apt-ftparchive packages . > Packages && apt-ftparchive release . > Release";};' | sudo tee $aptconf
echo 'deb [trusted=yes lang=none] file:'$debdir' ./' | sudo tee $sourcelist
@onjin
onjin / docker-compose.yml
Created September 5, 2016 09:17
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@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.
@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 / mkchangelog
Created March 7, 2014 07:41
Script creates CHANGELOG.txt according to current git tags.
#!/bin/bash
#
# usage: ./mkchangelog
#
# author: Marek Wywiał <onjinx@gmail.com>
#
# description: Script creates CHANGELOG.txt according to current git tags. Also
# supports commits without tags (git log HEAD...first_tag).
# Lines starting with 'Merge' will be skipped.
# Remember to add 'include CHANGELOG.txt' into your MANIFEST.in if
@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 / obsidian-web-clipper.js
Last active June 28, 2024 07:09 — forked from kepano/obsidian-web-clipper.js
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */