Skip to content

Instantly share code, notes, and snippets.

View yeus's full-sized avatar

Thomas Meschede yeus

View GitHub Profile
@yeus
yeus / fastapi_spa_server.py
Created February 19, 2022 17:58
Single Page Application Server based on fastapi/starlette.
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
app = FastAPI()
STATIC_FILES_DIR = "./static/"
index_file = FileResponse(
STATIC_FILES_DIR + "index.html",
@yeus
yeus / rate_limiter.py
Last active December 2, 2021 19:25
async rate limiting function using token bucket algorithm
"""
author: Thomas Meschede
license: MIT
"""
def rate_limit_burst(max_calls: float, interval: float):
"""
Rate-limits the decorated function locally, for one process. Using Token Bucket algorithm.
max_calls: maximum number of calls of function in interval
import { Component, defineAsyncComponent, defineComponent, h } from 'vue'
export function hydrateNever(componentOrFactory: Component): Component {
return makeHydrationBlocker(componentOrFactory, {
beforeCreate() {
this.never = true
},
})
}