Skip to content

Instantly share code, notes, and snippets.

View DurandA's full-sized avatar

Arnaud Durand DurandA

View GitHub Profile
@liviaerxin
liviaerxin / README.md
Last active November 15, 2024 19:14
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload
@tothi
tothi / mitmproxy-jwt-refresh-addon.py
Created August 28, 2022 20:52
mitmproxy addon for handling oauth access and refresh tokens automatically
# run: mitmproxy -k -p 8090 -s mitmproxy-jwt-refresh-addon.py
# set burp upstream proxy to localhost:8090
#
# use case:
# - application authorization is implemented by OAuth 2.0
# - testing is performed using Burp as primary and mitmproxy as upstream proxy
# - mitmproxy takes care of the Authorization tokens using this addon
# - user gets an access_token and a refresh_token during the 1st login (e.g. password login)
# - mitmproxy addon caches access_token and refresh_token
# - mitmproxy addon adds Authorization: Bearer [access_token from cache] header for every request
@ryanburnette
ryanburnette / Caddyfile
Last active October 29, 2024 12:36
Caddy v2.1+ CORS whitelist
(cors) {
@cors_preflight{args.0} method OPTIONS
@cors{args.0} header Origin {args.0}
handle @cors_preflight{args.0} {
header {
Access-Control-Allow-Origin "{args.0}"
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
Access-Control-Allow-Headers *
Access-Control-Max-Age "3600"
@wilburx9
wilburx9 / dismissible_animated.dart
Last active January 16, 2023 07:02
Animated Flutter Dismissible
Tween<Offset> _offSetTween = Tween(
begin: Offset(1, 0),
end: Offset.zero,
);
...
@override
Widget build(BuildContext context) {
return Scaffold(
...
@gregdavill
gregdavill / ecp5_swap_idcode.py
Created October 1, 2019 12:25
Script for use with prjtrellis to swap the IDCODE of a ECP5 bitstream
#!/usr/bin/env python3
"""
This simple example uses PyTrellis to unpack, change the IDCODE, and pack a bitstream
"""
import pytrellis
pytrellis.load_database("/usr/share/trellis/database")
bs = pytrellis.Bitstream.read_bit("build/gateware/impl/top_impl.bit")
chip = bs.deserialise_chip()
@zspine
zspine / SuperAdminGroupContextBuilder.php
Last active March 23, 2023 08:46
API Platform custom ContextBuilder and Denormalizer
<?php
namespace App\Serializer\ApiPlatform;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use App\Entity\User;
@591342534
591342534 / SimpleHTTPServerWithUpload.py
Created May 27, 2019 08:13 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@aliesbelik
aliesbelik / benchmarking-tools.md
Last active November 16, 2024 14:22
Benchmarking & load testing tools
#!/usr/bin/env python3
import sys
import textwrap
# Very basic bitstream to SVF converter, tested with the ULX3S WiFi interface
flash_page_size = 256
erase_block_size = 64*1024
@cr1901
cr1901 / clock_domains.md
Last active July 4, 2021 07:14
Migen Clock Domain Summary

Migen Clock Domains Summary

Terminology

  • Declaring a clock domain:
    • self.clock_domains.cd_mycd = ClockDomain()
  • Referencing a clock domain:
    • self.sync.mycd += []
    • ClockSignal("mycd")
  • Requesting an I/O signal:
  • platform.request("clk12")