Skip to content

Instantly share code, notes, and snippets.

@chbndrhnns
chbndrhnns / test_.py
Last active September 26, 2023 18:49
FastAPI 0.103 loses custom class name
import typing as t
import pytest
from pydantic import BaseModel
from pydantic.json_schema import GenerateJsonSchema
from fastapi import FastAPI
from fastapi._compat import get_definitions
from fastapi.openapi.constants import REF_TEMPLATE
from fastapi.openapi.utils import get_fields_from_routes
<TaskOptions>
<TaskOptions>
<option name="arguments" value="$FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="Format code using black" />
<option name="output" value="$FilePath$" />
@chbndrhnns
chbndrhnns / service.py
Created October 12, 2021 13:07
what's not to like about this code?
import os
import random
from time import sleep
import httpx
class TaskRepository:
def get_all(self):
import pytest
BASE = 10
SYMBOLS_DICT = {1: "I", 5: "V", 10: "X", 50: "L", 100: "C", 500: "D", 1000: "M"}
def get_digit_at(num, pos):
return num // 10 ** pos % 10
@chbndrhnns
chbndrhnns / main.py
Created August 31, 2021 09:08
FastAPI response wrapper
from typing import Generic, TypeVar
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from pydantic.generics import GenericModel
T = TypeVar("T")
@chbndrhnns
chbndrhnns / config_builder.py
Created May 27, 2021 11:35
Testing subprocesses
from pathlib import Path
class GunicornConfigBuilder:
def __init__(self):
self._cmd = "gunicorn"
self._log_level = None
self._app_module = "tests.integration.webserver.app:app"
self._check_only = False
self._print_only = False
@chbndrhnns
chbndrhnns / categories.json
Created June 26, 2018 07:26
YNAB: Clone Budget
{"categories": {
"Pflicht": {
"Miete": 500.00,
"Krankenversicherung": 0.00,
"Lebensmittel": 0.00
},
"Projekte": {
"Notfall": 2000
},
"Realität": {
@chbndrhnns
chbndrhnns / singleton.py
Created November 25, 2017 22:07 — forked from lucgiffon/singleton.py
Singleton Mixin Class of Python
#!/usr/bin/env python
# vim: set fileencoding=utf8 :
"""Singleton Mixin"""
class Singleton(object):
"""Singleton Mixin Class
Inherit this class and make the subclass Singleton.
Usage:
@chbndrhnns
chbndrhnns / gist:0bd5056a77687247bacf4cafa49700ad
Last active July 5, 2017 11:21
mock HTTPRequest in python
# source: https://stackoverflow.com/a/28507806
def mocked_requests_get(*args, **kwargs):
class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
def json(self):
return self.json_data
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ConfigParser
import argparse
import os
import logging
import sys
import gitlab
import threading