Skip to content

Instantly share code, notes, and snippets.

@Tishka17
Tishka17 / override.py
Created April 15, 2025 15:59
Dishka container override example
from collections.abc import AsyncIterator, Iterator
from contextlib import contextmanager
from typing import TypeVar
from dishka import (
DEFAULT_COMPONENT,
AsyncContainer,
Container,
make_async_container,
make_container,
@Tishka17
Tishka17 / modifier.py
Created March 15, 2025 17:31
Assignement modificator in python
# logic
MOD x = y
x = MOD.__transform__(t"{y}") # lazy evaluation
x = MOD(y) # general case
# unpack
MOD1 x, MOD2 y = z
_x, _y = z
x = MOD1(x), MOD2(y)
@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,