Skip to content

Instantly share code, notes, and snippets.

@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 / Dockerfile
Last active October 6, 2022 20:27
Poetry Dockerfile template
FROM python:3.10.5-slim-buster AS base
LABEL maintainer="https://github.com/somespecialone"
LABEL description="Poetry Dockerfile template"
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
FROM base AS builder
@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]
# https://pawamoy.github.io/posts/unify-logging-for-a-gunicorn-uvicorn-app/
import sys
import logging
from loguru import logger
__all__ = ("setup_logging",)
_LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} <lvl>| {level: ^6} |</> {message}"