Skip to content

Instantly share code, notes, and snippets.

View xshapira's full-sized avatar

Max Shapira xshapira

View GitHub Profile
@xshapira
xshapira / asgi.py
Last active August 19, 2022 11:07 — forked from bryanhelmig/asgi.py
A Django + Starlette or FastAPI connection handling example (ASGI, with WSGIMiddleware).
import functools
import importlib
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") # noqa
import anyio
from asgiref.sync import sync_to_async
from django.conf import settings
from django.core.wsgi import get_wsgi_application
@xshapira
xshapira / GitCommitEmoji.md
Created July 21, 2022 14:44 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@xshapira
xshapira / main.py
Created August 26, 2022 08:44 — forked from Kludex/main.py
Document each version on FastAPI
from fastapi import APIRouter, FastAPI
from utils import create_versioning_docs
app = FastAPI(docs_url=None, redoc_url=None)
v1_router = APIRouter(prefix="/v1")
v2_router = APIRouter(prefix="/v2")
@xshapira
xshapira / main.py
Created August 26, 2022 08:47 — forked from Kludex/main.py
Increase number of threads available on FastAPI.
import anyio
from fastapi import FastAPI
app = FastAPI()
@app.on_event("startup")
async def startup():
limiter = anyio.to_thread.current_default_thread_limiter()
@xshapira
xshapira / redoc.py
Created August 26, 2022 08:48 — forked from Kludex/redoc.py
Export FastAPI ReDoc to HTML
"""
Script to export the ReDoc documentation page into a standalone HTML file.
Created by https://github.com/pawamoy on https://github.com/Redocly/redoc/issues/726#issuecomment-645414239
"""
import json
from my_app.app import app
HTML_TEMPLATE = """<!DOCTYPE html>
import asyncio
from typing import Type
from aio_pika import RobustConnection, connect_robust
from aio_pika.connection import ConnectionType
from aio_pika.types import TimeoutType
class RabbitMQClient:
def __init__(
@xshapira
xshapira / terminal-commands.md
Created October 18, 2022 09:27 — forked from bradtraversy/terminal-commands.md
Common Terminal Commands

Common Terminal Commands

Key Commands & Navigation

Before we look at some common commands, I just want to note a few keyboard commands that are very helpful:

  • Up Arrow: Will show your last command
  • Down Arrow: Will show your next command
  • Tab: Will auto-complete your command
  • Ctrl + L: Will clear the screen
@xshapira
xshapira / python_datetime_snippets.md
Created January 21, 2023 08:00 — forked from genadyp/python_datetime_snippets.md
How to convert in python local time string to UTC?
@xshapira
xshapira / kafka_connect.py
Created January 21, 2023 10:19 — forked from iKunalChhabra/kafka_connect.py
Kafka consumer producer class in python
from confluent_kafka import Consumer, Producer, KafkaError, KafkaException
class Kafka:
def __init__(self, bootstrap_server, topic, timeout=1.0):
self.__bootstrap_server = bootstrap_server
self.__topic = topic
self.__timeout = timeout
@staticmethod
@xshapira
xshapira / async_kafka_prod_cons.py
Created January 21, 2023 10:20 — forked from vcabral19/async_kafka_prod_cons.py
playing with async python and kafka
import asyncio
from confluent_kafka import Consumer, Producer
from confluent_kafka.admin import AdminClient, NewTopic
BROKER_URL = "PLAINTEXT://localhost:9092"
TOPIC_NAME = "my-first-python-topic"