Skip to content

Instantly share code, notes, and snippets.

View victorusachev's full-sized avatar

Victor Usachev victorusachev

View GitHub Profile
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
@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 timeit import Timer
def concatenation(sequence):
result = ''
for char in sequence:
result += char
return result
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)
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 random
from dataclasses import dataclass, field
from decimal import Decimal
from typing import Callable, Iterable, List, Union
_logger = logging.getLogger(__name__)
MENU = [
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):
# convert to dict
# fiasHouseGuidByAddress = addressObjects
# .Select(
# ao => new KeyValuePair<string, Guid>(ao.AddressObjectId, ao.FiasHouseGuid)
# )
# .ToDictionary(t => t.Key, t => t.Value);
import uuid
from dataclasses import dataclass, field
from pprint import pprint
import asyncio
import time
async def do_some_prints_with_sleeps(coro_id):
print(f"[{coro_id}] Hello, i am coro with asyncio.sleeps")
print(f"[{coro_id}] Will sleep right now for 1 second")
await asyncio.sleep(1)
print(f"[{coro_id}] I woke up, but feel sleepy, will sleep 1 second more")
await asyncio.sleep(1)
class Predicate:
def __init__(self, pattern):
self.pattern = pattern
def __call__(self, value):
return self.pattern in value
def __repr__(self):
return f'<Predicate: {self.pattern}>'