Skip to content

Instantly share code, notes, and snippets.

View victorusachev's full-sized avatar

Victor Usachev victorusachev

View GitHub Profile
class List:
def __init__(self, items):
super().__init__()
self._items = items
def __call__(self, function):
self._items = map(function, self)
return self
def __iter__(self):
import logging
import random
from dataclasses import dataclass, field
from decimal import Decimal
from typing import Callable, Iterable, List, Union
_logger = logging.getLogger(__name__)
MENU = [
import enum
class BinaryNode:
def __init__(self, data, parent=None):
self.data = data
self._parent = parent
self._left = None
self._right = None
import logging
import threading
def worker(event: threading.Event, /, *, sleep: float = 1):
while not event.is_set():
logging.debug("worker thread checking in")
event.wait(sleep)
from timeit import Timer
def concatenation(sequence):
result = ''
for char in sequence:
result += char
return result
@victorusachev
victorusachev / simple_cli.py
Created December 3, 2019 21:59
python alghoritms_simple_cli.py iter_fib 0 1 2 3 4 5 6 7 8 9 10 100
import sys
from functools import lru_cache
class Executor(dict):
def register(self, func):
if func.__name__ in self:
raise NameError(f'{func.__name__} already register')
self[func.__name__] = func
return func
from __future__ import annotations
import functools
import inspect
import warnings
from typing import Callable, Type, Union
__all__ = ('DEFAULT_STACK_LEVEL', 'deprecated', 'pending_deprecation', 'warn')
DEFAULT_STACK_LEVEL = 3
from collections import OrderedDict
empty = object()
class Item:
"""
Descriptor
Usage:
>>> class SomethingType:
from urllib.parse import (
parse_qsl,
urlencode,
urlparse,
urlunparse,
)
def inject_query_parameters(url: str, params: dict) -> str:
parts = urlparse(url)
"""
My solution
See https://t.me/aiohttp_ru/3955
"""
import asyncio
import json
import aiohttp
from asgiref.sync import sync_to_async