Skip to content

Instantly share code, notes, and snippets.

View non7top's full-sized avatar

non7top non7top

  • Bakı
  • 16:44 (UTC +04:00)
View GitHub Profile
non7top /
Created March 21, 2024 18:04 — forked from nymous/
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

non7top /
Created December 29, 2023 22:04 — forked from vadimkantorov/
A one-line example enabling Python's argparse to accept dictionary arguments
# Example:
# $ python --env a=b --env aa=bb
# Namespace(env={'a': 'b', 'aa': 'bb'})
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--env', action = type('', (argparse.Action, ), dict(__call__ = lambda a, p, n, v, o: getattr(n, a.dest).update(dict([v.split('=')])))), default = {}) # anonymously subclassing argparse.Action
non7top / git-branch-cleaner
Created May 10, 2023 18:07 — forked from jdhoek/git-branch-cleaner
Bash script for cleaning up old git branches from local and remote repositories
ME=$(basename $0)
function showHelp {
cat << EOF
Clean-up old git branches
Usage: $ME local show-last [AGE_IN_WEEKS]
$ME remote show-last REMOTE [AGE_IN_WEEKS]
non7top / upload.php
Created April 13, 2022 11:32 — forked from taterbase/upload.php
Simple file upload in php
<!DOCTYPE html>
<title>Upload your files</title>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
non7top / remove_crw.cmd
Created February 6, 2020 00:41 — forked from xvitaly/remove_crw.cmd
Remove telemetry updates for Windows 7 and 8.1
@echo off
echo Uninstalling KB3075249 (telemetry for Win7/8.1)
start /w wusa.exe /uninstall /kb:3075249 /quiet /norestart
echo Uninstalling KB3080149 (telemetry for Win7/8.1)
start /w wusa.exe /uninstall /kb:3080149 /quiet /norestart
echo Uninstalling KB3021917 (telemetry for Win7)
start /w wusa.exe /uninstall /kb:3021917 /quiet /norestart
echo Uninstalling KB3022345 (telemetry)
start /w wusa.exe /uninstall /kb:3022345 /quiet /norestart
echo Uninstalling KB3068708 (telemetry)
non7top / remove-win10-spyware.bat
Created February 6, 2020 00:41 — forked from zorchenhimer/remove-win10-spyware.bat
Remove all the nasty stuff that was backported to Windows 7 and 8 from Windows 10.
@echo off
echo Error: Not running as administrator.
echo Please right click the batch file and select 'Run as Administrator'
exit /b 1
echo Uninstalling bad updates...
non7top /
Created September 8, 2018 11:47 — forked from cstroie/
Recode MP3 files with normalization
# recode
# Copyright 2011 Costin STROIE <>
non7top / super-tip.txt
Created January 18, 2018 19:11 — forked from ericdouglas/super-tip.txt
Change 4 spaces to 2 spaces indentation and change tab to spaces - Vim tip
// 4 spaces to 2 spaces
%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g
// Tab to 2 spaces
:%s/\t/ /g
non7top / nginx-lua-s3.nginxconf
Created January 14, 2018 21:51 — forked from raucao/nginx-lua-s3.nginxconf
Nginx proxy to S3
location ~* ^/s3/(.*) {
set $url_full "$1";
set_by_lua $now "return ngx.cookie_time(ngx.time())";
set $string_to_sign "$request_method\n\n\n\nx-amz-date:${now}\n/$bucket/$url_full";
set_hmac_sha1 $aws_signature $aws_secret $string_to_sign;
set_encode_base64 $aws_signature $aws_signature;
# install 7-zip, curl and vim
# (Windows 2012 comes with .NET 4.5 out-of-the-box)
# Then use the EC2 tools to create a new AMI from the result, and you have a system
# that will execute user-data as a PowerShell script after the instance fires up!
# This has been tested on Windows 2012 64bits AMIs provided by Amazon (eu-west-1 ami-a1867dd6)
# Inject this as user-data of a Windows 2012 AMI, like this (edit the adminPassword to your needs):
# <powershell>
# Set-ExecutionPolicy Unrestricted