Skip to content

Instantly share code, notes, and snippets.

@nymous
nymous / README.md
Last active April 22, 2025 21: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

@janert
janert / hugo-survival-guide.md
Last active March 21, 2025 18:37
A Hugo Survival Guide

A Hugo Survival Guide

Hugo is a static site generator: it takes some plain-text content, marries it to a bunch of HTML templates, and produces a set of complete, static HTML pages that can be served by any generic, stand-alone web server. Simple.

Or maybe not. Hugo does a lot of things automatically, relying on conventions and implicit rules, rather than on explicit configuration. For example, it tries to match each piece of content with the most

@suiluj
suiluj / python_logging.py
Last active June 7, 2024 09:24
python logging pretty print pformat indent width line break
import logging
import time
from pprint import pformat
# pretty print logs: https://stackoverflow.com/a/11093247/5628238
# pformat indent: https://stackoverflow.com/a/29469358/5628238
# (even needed when using %s string format): do not evaluate complex pformat when log level not printed: https://docs.python.org/3/library/logging.html#logging.Logger.isEnabledFor
# (wrong: complex variable string takes time nevertheless): https://reinout.vanrees.org/weblog/2015/06/05/logging-formatting.html
# https://stackoverflow.com/questions/13131400/logging-variable-data-with-new-format-string
# main script or module
@eldadfux
eldadfux / .env
Last active June 29, 2022 05:24
Appwrite 0.14 - Stack
_APP_ENV=production
_APP_LOCALE=en
_APP_OPTIONS_ABUSE=enabled
_APP_OPTIONS_FORCE_HTTPS=disabled
_APP_OPENSSL_KEY_V1=your-secret-key
_APP_DOMAIN=localhost
_APP_DOMAIN_TARGET=localhost
_APP_CONSOLE_WHITELIST_ROOT=enabled
_APP_CONSOLE_WHITELIST_EMAILS=
_APP_CONSOLE_WHITELIST_IPS=
@qdm12
qdm12 / README.md
Last active March 20, 2025 08:49
Wireguard and iptables restrictions for multiple users

Wireguard and iptables restrictions for multiple users

If you don't know what Wireguard is, well, you should. It's fast, easy to setup and highly configurable. We will configure Wireguard for multiple users with various restrictions using iptables.

Assumptions

This should fit most setups (not mine though 😉)

@coltenkrauter
coltenkrauter / fix-wsl2-dns-resolution
Last active April 20, 2025 23:06
Fix DNS resolution in WSL2
More recent resolution:
1. cd ~/../../etc (go to etc folder in WSL).
2. echo "[network]" | sudo tee wsl.conf (Create wsl.conf file and add the first line).
3. echo "generateResolvConf = false" | sudo tee -a wsl.conf (Append wsl.conf the next line).
4. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian).
5. cd ~/../../etc (go to etc folder in WSL).
6. sudo rm -Rf resolv.conf (Delete the resolv.conf file).
7. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and
secondary.
@BoQsc
BoQsc / Gists.md
Last active April 23, 2025 07:54
How to search my own Gists
@damijanc
damijanc / sample.php
Created September 13, 2018 11:53
Example on how to download an Excel file created with PhpSpreadsheet
<?php
$streamedResponse = new StreamedResponse();
$streamedResponse->setCallback(function () {
$spreadsheet = //create you spreadsheet here;
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
});
@dennisnissle
dennisnissle / functions.php
Created June 21, 2018 14:59
Move legal checkboxes right before order submit button (Germanized > 2.X)
<?php
add_action( 'init', 'my_child_move_legal_checkboxes', 50 );
function my_child_move_legal_checkboxes() {
// Remove
remove_action( 'woocommerce_review_order_after_payment', 'woocommerce_gzd_template_render_checkout_checkboxes', 10 );
// Readd before submit button
add_action( 'woocommerce_gzd_review_order_before_submit', 'woocommerce_gzd_template_render_checkout_checkboxes', 10 );
}
@xoseperez
xoseperez / rpi3_iot_server.md
Last active February 11, 2024 15:05
Raspberry Pi 3 with Mosquitto, Node-RED, InfluxDB, Grafana and Nginx (as a reverse proxy)