Skip to content

Instantly share code, notes, and snippets.

View frankie567's full-sized avatar

François Voron frankie567

View GitHub Profile
@frankie567
frankie567 / app.py
Last active October 3, 2023 11:26
Type-hinted sorting fields dependency for FastAPI
from enum import StrEnum
from fastapi import FastAPI
from .sorting import Sorting
class SortingField(StrEnum):
FIELD_A = "field_a"
FIELD_B = "field_b"
@frankie567
frankie567 / cookie_expires.py
Last active November 8, 2022 14:08
Python SimpleCookie expires tests
@frankie567
frankie567 / cloudflare_stream_token.py
Created December 28, 2021 14:50
Generate signed tokens for Cloudflare Stream in Python
import base64
from datetime import datetime
from jwcrypto import jwt, jwk # pip install jwcrypto
b64_jwk = "XXXX" # Base64-encoded JWT you get from Cloudflare Stream API (https://developers.cloudflare.com/stream/viewing-videos/securing-your-stream#step-1-call-the-streamkey-endpoint-once-to-obtain-a-key)
jwk_key = jwk.JWK.from_json(base64.b64decode(b64_jwk))
def get_video_token(video_id: str, lifetime: int = 3600) -> str:
header = {"kid": jwk_key["kid"], "alg": "RS256"}
@frankie567
frankie567 / interactive_google_oauth2.py
Last active July 29, 2023 22:07
Interactive Google OAuth2 flow with Streamlit
import asyncio
import streamlit as st
from httpx_oauth.clients.google import GoogleOAuth2
st.title("Google OAuth2 flow")
"## Configuration"
client_id = st.text_input("Client ID")
@frankie567
frankie567 / medium-ts-unit-testing-import.js
Created August 20, 2018 06:40
medium-ts-unit-testing-import
const myMethod = require('./module')
// or
import myMethod from './module'
@frankie567
frankie567 / speed-limit-upload.ts
Last active April 3, 2018 06:38
NodeJS : upload a file with a speed limit
import { createReadStream } from 'fs'
import { basename } from 'path'
import * as request from 'request' // npm i request
import * as Throttle from 'throttle' // npm install throttle
const fileToUploadPath = '/foo.txt'
const fileSize = 1024 // Computed with 'fs.stat' for example
request.post(
'/upload',