Skip to content

Instantly share code, notes, and snippets.

View victorusachev's full-sized avatar

Виктор Усачёв victorusachev

View GitHub Profile
@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:
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 / 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
@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
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)}")
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/'
@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
@victorusachev
victorusachev / helpers.py
Created August 12, 2020 20:42
Application configuration and testability
# tests/helpers.py
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Iterator
from defmain.settings import get_settings
if TYPE_CHECKING:
from defmain.settings import Settings
@victorusachev
victorusachev / docker-build.sh
Created August 5, 2020 13:57
My local scripts for docker
# shellcheck disable=SC2046
docker build -f docker/Dockerfile -t defmain/backend:latest . -t defmain/backend:$(git rev-parse --short HEAD)
from graphene import InputObjectType, ObjectType, Schema, String, ID, Field, List
class UserSchema(ObjectType):
username = String()
first_name = String()
class PostSchema(ObjectType):
id = ID()