Skip to content

Instantly share code, notes, and snippets.

View verhovensky's full-sized avatar
💭
"To a real warrior, power perceived may be power achieved."

BH verhovensky

💭
"To a real warrior, power perceived may be power achieved."
View GitHub Profile
@nymous
nymous / README.md
Last active September 13, 2024 17:37
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

@sameerkumar18
sameerkumar18 / yourapp_admin.py
Last active July 31, 2024 07:30
Django Admin: Celery Retry Task by ID
# Add this code in any Django app's admin.py
# Works for all Task Statuses; you can filter them in line 12.
import ast
import importlib
import json
from django.contrib import admin
from django.contrib import messages
from django.utils.safestring import mark_safe
@mac2000
mac2000 / postgres_master_slave_failover_failback.md
Last active June 28, 2024 08:23
Postgres Master Slave Failover & Failback

Postgres Master Slave Failover & Failback

video

start

docker run -it --rm -p 5551:5432 --name=db1 --hostname=db1 ubuntu:20.04 bash
docker run -it --rm -p 5552:5432 --name=db2 --hostname=db2 ubuntu:20.04 bash
@ano
ano / mysql_uuid_to_int.sql
Created February 15, 2020 05:56
MySQL Convert UUID to Integer
/*
The format for converting UUID's to integers is as follows
CONV(LEFT(HEX(`uuid_from_bin` (`uuid_v5` (<a static uuid value>,<the uuid field>))),8),16,10) AS id
MYSQL User Defined Functions
uuid_from_bin
and uuid_v5
@ano
ano / mysql_uuid.sql
Last active December 19, 2022 07:38
MySQL UUID Functions
DROP FUNCTION IF EXISTS uuid_from_bin;
DROP FUNCTION IF EXISTS uuid_to_bin;
DROP FUNCTION IF EXISTS uuid_v5;
DROP FUNCTION IF EXISTS uuid_v4;
DELIMITER //
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS CHAR(36)
BEGIN
@linhxhust
linhxhust / Add git branch to PS1
Last active December 4, 2022 09:56
Add git branch to PS1
Step 1: Open file ~/.bashrc
Step 2: Uncomment forece_color_prompt=yes
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
Step 3: Comment PS1 style. Add the following code to end of ~/.bashrc
# creating and testing permissions and test groups in django tests.
from django.contrib.auth.models import User, Permission, Group
from django.test import TestCase
from django.test import Client
class ExampleGroupPermissionsTests(TestCase):
def setUp(self):
#create permissions group
@hatarist
hatarist / ensure_csrf_cookie_mixin.py
Created July 16, 2015 15:37
EnsureCsrfCookieMixin for Django's Class-Based Views
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
xhost +local:root > /dev/null 2>&1
@c0ldlimit
c0ldlimit / git_newrepo
Created November 16, 2012 17:14
Git: Push a new or existing repo to Github
# Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/c0ldlimit/vimcolors.git
git push -u origin master
# Push an existing repository from the command line