Skip to content

Instantly share code, notes, and snippets.

@nymous
nymous / README.md
Last active April 25, 2024 16:50
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

@krzemienski
krzemienski / logging_subprocess.py
Created February 24, 2020 18:47 — forked from jaketame/logging_subprocess.py
Python subprocess logging to logger from stdout/stderr
#!/usr/local/bin/python3
import logging, select, subprocess
LOG_FILE = "test.log"
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO,filename=LOG_FILE,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
def logging_call(popenargs, **kwargs):
process = subprocess.Popen(popenargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@Klerith
Klerith / cloudbuild.yml
Last active April 25, 2024 16:49
Google Cloud - Build steps
steps:
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"XXXXX-docker.pkg.dev/project-name/registry/image-name",
"-f",
"dockerfile.prod",
"--platform=linux/amd64",
@carcinocron
carcinocron / debugger pause beforeunload
Last active April 25, 2024 16:48
Chrome: pause before redirect
// Run this in the F12 javascript console in chrome
// if a redirect happens, the page will pause
// this helps because chrome's network tab's
// "preserve log" seems to technically preserve the log
// but you can't actually LOOK at it...
// also the "replay xhr" feature does not work after reload
// even if you "preserve log".
window.addEventListener("beforeunload", function() { debugger; }, false)
#
# Sample configuration file for the CUPS scheduler. See "man cupsd.conf" for a
# complete description of this file.
#
# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn
# Deactivate CUPS' internal logrotating, as we provide a better one, especially
@tomas-stefano
tomas-stefano / Capybara.md
Last active April 25, 2024 16:44
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.0.0"
@BigRoy
BigRoy / openpype_to_ayon_core.md
Last active April 25, 2024 16:42
OpenPype codebase refactor to AYON core

Transition code from OpenPype to Ayon Core

Refactor

  • openpype -> ayon_core
  • Loader plugins update method now takes context instead of representation argument | ynput/ayon-core#130
  • Loader plugins attribute families (list) -> product_types (set) | ynput/ayon-core#191
  • Creator plugins: family -> productType | ynput/ayon-core#113
  • Refactor OpenPypeModule -> AYONAddon | ynput/ayon-core#22
    • now in ayon_core.addon instead of ayon_core.modules
@bradtraversy
bradtraversy / mongodb_cheat_sheet.md
Last active April 25, 2024 16:42
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@bradtraversy
bradtraversy / mysql_cheat_sheet.md
Last active April 25, 2024 16:41
MySQL Cheat Sheet

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH