Skip to content

Instantly share code, notes, and snippets.

View somespecialone's full-sized avatar
💮

Dmytro somespecialone

💮
View GitHub Profile
@somespecialone
somespecialone / example.py
Created May 23, 2025 20:28
Minimalistic request coalescer as class and decorator suitable for FastAPI. Will return response from first request to concurrent subsequent request, without caching
# Thanks to me
import asyncio
from fastapi import FastAPI
from request_coalescer import coalesce
app = FastAPI(lifespan=lifespan)
@somespecialone
somespecialone / storage.py
Created July 4, 2024 23:25
Async SQLite-only storage for `aiogram` using `sqlalchemy.ext.asyncio.AsyncSession`
# SQLite only storage for Dispatcher and telegram bots
from enum import Enum
from typing import Callable
from sqlalchemy import delete, Column, String, select, Enum as EnumSQLType, JSON
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.dialects.sqlite import insert
from aiogram.fsm.storage.base import BaseStorage, KeyBuilder, DefaultKeyBuilder, State, StateType
@somespecialone
somespecialone / ChartAnim.vue
Created September 14, 2023 17:13
Chart like music visualization animation Vue component
<script setup lang="ts">
const COUNT = 4 // Count of the bars
function r(min: number, max: number): number {
return Math.ceil(Math.random() * (max - min) + min)
}
</script>
<template>
<div class="music-chart-visualization">
<div
@somespecialone
somespecialone / poetry.Dockerfile
Last active May 25, 2025 13:32
UV and Poetry Dockerfiles templates for Python application containerization. Include variants with ssh and key to make able private GitHub Python library repository installation
FROM python:3.13-slim AS base
LABEL maintainer="https://github.com/somespecialone"
LABEL description="Poetry Dockerfile template"
FROM base AS builder
RUN apt-get update && apt-get install --no-install-recommends -y curl
ENV POETRY_VERSION=2.1.3 \
@somespecialone
somespecialone / event_emitter.py
Last active November 3, 2022 01:57
Simple generic python event emitter class.
# https://www.joeltok.com/blog/2021-3/building-an-event-bus-in-python
import asyncio
from typing import Callable, Coroutine, Generic, TypeVar, TypeAlias, Any
from warnings import warn
from inspect import iscoroutinefunction
_E = TypeVar("_E")
_Listener: TypeAlias = Callable[[...], Coroutine[Any, Any, None]] | Callable[[...], None]
_Waiter: TypeAlias = Callable[[...], bool]
@somespecialone
somespecialone / logging.py
Last active May 22, 2025 19:14
Setup logging function with Loguru. Suitable for Uvicorn+FastAPI
# https://pawamoy.github.io/posts/unify-logging-for-a-gunicorn-uvicorn-app/
import sys
import logging
from typing import Sequence
from loguru import logger
LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} <lvl>| {level: ^6} |</> {message}"