Skip to content

Instantly share code, notes, and snippets.

View victorusachev's full-sized avatar

Victor Usachev victorusachev

View GitHub Profile
@victorusachev
victorusachev / helpers.py
Last active July 12, 2021 13:13
Application configuration example
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Iterator
from my_app.settings import get_settings
if TYPE_CHECKING:
from my_app.settings import Settings
@contextmanager
import sys
import contextlib
from pathlib import Path
from typing import Any, ClassVar, Dict, Iterable, List, Optional
import requests
class GameApi:
base_url: ClassVar[str] = 'https://www.planitpoker.com/api/'
import enum
from typing import Iterable, Type
def merge_enums(new_name: str, *enums: Iterable[Type[enum.Enum]]) -> Type[enum.Enum]:
attributes = [{m.name: m.value for m in e} for e in enums]
intersection = set.intersection(*map(set, attributes))
if intersection:
raise ValueError(f"Error codes are duplicated: {', '.join(intersection)}")
@victorusachev
victorusachev / dotted_version_conversions.py
Created May 25, 2021 07:30
Implement the conversion of the dotted version string to an integer and reverse conversion. This approach can be used to compactly store large amounts of version data.
"""
Implement the conversion of the dotted version string to an integer and reverse conversion.
This approach can be used to compactly store large amounts of version data.
"""
import struct
from typing import List, Optional
import pytest
@victorusachev
victorusachev / graphene.py
Last active May 26, 2021 00:59 — forked from mixxorz/graphene.py
Get requested fields from ResolveInfo. Graphene python.
"""
MIT License
Copyright (c) 2018 Mitchel Cabuloy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
import sys
import paramiko
def main(hosts: list[str]) -> None:
for host in hosts:
transport = paramiko.transport.Transport((host, 22))
transport.start_client(timeout=1)
key = transport.get_remote_server_key()
@victorusachev
victorusachev / jobs.py
Created March 12, 2024 19:58
apscheduler.BlockingScheduler with retry
import functools
from typing import Callable, Any
from loguru import logger
from integration.utils import retry
def run_something(f: Callable, *args: Any, **kwargs: Any) -> None:
try: