This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from timeit import Timer | |
| def concatenation(sequence): | |
| result = '' | |
| for char in sequence: | |
| result += char | |
| return result | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import enum | |
| class BinaryNode: | |
| def __init__(self, data, parent=None): | |
| self.data = data | |
| self._parent = parent | |
| self._left = None | |
| self._right = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}>' |