Skip to content

Instantly share code, notes, and snippets.

@Tishka17
Tishka17 / bot.py
Created January 10, 2025 23:20
Stateless dialog rendering
import asyncio
import logging
import os
from dataclasses import dataclass
from typing import Any
from aiogram import Bot, Dispatcher, Router, F
from aiogram.filters import CommandStart
from aiogram.fsm.state import State
from aiogram.types import Message, CallbackQuery
@Tishka17
Tishka17 / oidc.py
Created January 8, 2025 14:11
open id connect client
import http
import json
import logging
from dataclasses import dataclass
from datetime import datetime
from typing import Any
import aiohttp
from adaptix import Retort
@Tishka17
Tishka17 / classes.py
Last active October 10, 2024 20:11
dishka benchmark
from enum import auto
from dishka import BaseScope
try:
from dishka.entities.scope import new_scope
except ImportError:
new_scope = str
class B:
def __init__(self, x: int):
@Tishka17
Tishka17 / regexmatch.py
Created September 3, 2024 14:51
regex match case
import re
class R:
def __init__(self, value):
self._value = value
class MatchRegex(type):
def __instancecheck__(cls, obj):
@Tishka17
Tishka17 / converter.py
Created June 9, 2024 08:42
Converting between types using adaptix parsers
from dataclasses import dataclass
from adaptix import Retort, Chain, loader, dumper
@dataclass
class A:
field: str
@Tishka17
Tishka17 / README.md
Created April 10, 2024 12:16
Dishka rendering example 2

Usage:

regs = [container.registry]+list(container.child_registries)
x = render(regs, type(container))
print(x)
@Tishka17
Tishka17 / render.py
Created March 4, 2024 23:47
Dishka graph rendering
from collections import defaultdict
from dataclasses import dataclass
from uuid import uuid4
from dishka.dependency_source.factory import Factory
from dishka.entities.key import DependencyKey
from dishka.entities.scope import BaseScope
from dishka.registry import Registry
@Tishka17
Tishka17 / hhash.py
Last active December 13, 2024 09:31
Comparing hash calculation
import hashlib
from timeit import timeit
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
a = b'1 2 3 4' * 1024 * 1024 * 100
funcs = [
hashlib.sha1,
hashlib.sha256,
hashlib.sha384,
@Tishka17
Tishka17 / announce.html
Created September 3, 2023 12:19
Dialogs 2.0 announce HTML
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"></meta></head>
<body>
<h2>Хочу объявить о выходе <b>aiogram_dialog</b> <code>2.0.0</code></h2>
<p>
Разработка заняла полтора года с января 2022, было выпущено более 20
промежуточных версий.
Изначально это планировалось как порт версии 1.х на aiogram3, но после
@Tishka17
Tishka17 / dialog_start_result.py
Created September 2, 2023 18:57
Custom Start widget with result processing
import asyncio
import logging
import os
from typing import Any
from typing import (
Optional,
)
from aiogram import Bot, Dispatcher, F, Router
from aiogram.filters import CommandStart