Skip to content

Instantly share code, notes, and snippets.

@nymous
nymous / README.md
Last active May 6, 2024 23:01
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

@mmlb
mmlb / serial-block.c
Last active May 6, 2024 22:59
serial.c
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/signal.h>
#define DEVICE "/dev/ttyS1"
@squarism
squarism / iterm2.md
Last active May 6, 2024 22:59
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@Klerith
Klerith / Instalaciones-React.md
Last active May 6, 2024 22:57
Instalaciones recomendadas para mi curso de React de cero a experto
@ciembor
ciembor / gist:1494530
Created December 18, 2011 21:28
RGB to HSL and HSL to RGB conversion functions
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
typedef struct rgb {
float r, g, b;
} RGB;
typedef struct hsl {
float h, s, l;
} HSL;
@wojteklu
wojteklu / clean_code.md
Last active May 6, 2024 22:47
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@agirault
agirault / image_orientation_dicom.md
Created October 8, 2020 22:31
Image Orientation in Dicom
@Joao-Peterson
Joao-Peterson / gmk67_linux.md
Last active May 6, 2024 22:45
Using GMK67 keyboard in linux. Function keys not working with Fn!

GMK67 with Archlinux!

Recently i bought a zuoya gmk67 keyboard, it doesn't have a function keys row and has a knob for volume control. Unfortunately, if you plug your gmk67 in a archlinux machine you will notice that using fn+1 will not produce f1 as expected, it will produce a screen brightness decrease, and if you change the physical switch in the back for the macOS mode, the function keys now work, but the modifier keys don't, quite stressful.

Fear not, you can either alter your system configuration so the keyboard functions normally, as in this gist, or remap the keys, as seen in the gist Using GMK67 keyboard in linux with key remaps!.

For this gist we are going to alter the configuration for the apple hid driver on archlinux, since this keyboard uses it, and alter the functionality of the Fn key.

This is tested on archlinux, for any other distro you might have to figure out yourself the correponding commands!

@driftregion
driftregion / udp-XRCE-DDS-dissector.lua
Last active May 6, 2024 22:44
rudimentary Wireshark plugin for XRCE-DDS
-- place in ~/.config/wireshark/plugins/
local p_xrce_dds = Proto("xrce-dds", "XRCE-DDS");
local p_xrce_dds_header = Proto("xrce-dds-header", "Header");
local p_xrce_dds_submessage = Proto("xrce-dds-submessage", "Submessage");
local f_sessionId = ProtoField.uint8("xrce-dds.sessionId", "sessionId", base.HEX)
local f_streamId = ProtoField.uint8("xrce-dds.streamId", "streamId", base.HEX)
local f_sequenceNr = ProtoField.uint16("xrce-dds.sequenceNr", "sequenceNr", base.DEC)
local f_clientKey = ProtoField.uint32("xrce-dds.clientKey", "clientKey", base.HEX)