I made a mini library out of this, have a look att github.com/KATT/next-router-query
-- Collision-resistant ids optimized for horizontal scaling and performance, for PL/PgSQL. | |
-- Based on https://github.com/ericelliott/cuid | |
-- Version 1.0.0 | |
-- Usage: SELECT cuid(); | |
-- BEGIN CONFIG --- | |
-- Put a unique host ID (int) here per server instance. | |
-- Once set, this value should not be changed. |
-- From https://github.com/geckoboard/pgulid/blob/d6187a00f66dca196cf5242588f87c3a7969df75/pgulid.sql | |
-- | |
-- pgulid is based on OK Log's Go implementation of the ULID spec | |
-- | |
-- https://github.com/oklog/ulid | |
-- https://github.com/ulid/spec | |
-- | |
-- Copyright 2016 The Oklog Authors | |
-- Licensed under the Apache License, Version 2.0 (the "License"); | |
-- you may not use this file except in compliance with the License. |
# | |
# Python | |
# | |
export PYENV_ROOT=${PYENV_ROOT:-$HOME/.pyenv} | |
# Usage: | |
# Add to .envrc file: | |
# use python 3.7.5 | |
use_python() { | |
# Install pyenv for management of Python versions |
# (c) miraculixx, licensed as by the terms of WTFPL, http://www.wtfpl.net/txt/copying/ | |
# License: DO WHATEVER YOU WANT TO with this code. | |
# | |
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
# | |
from io import StringIO | |
from contextlib import contextmanager |
// via https://github.com/aws-amplify/amplify-js/discussions/5554 | |
import {Auth} from "@aws-amplify/auth"; | |
.... | |
Auth.configure({ | |
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID | |
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', | |
// REQUIRED - Amazon Cognito Region | |
region: 'XX-XXXX-X', |
#!/usr/bin/env ruby | |
# gem install active_support | |
require 'active_support/inflector' | |
require 'active_support/core_ext/string' | |
# gem install webrick (only ruby3) | |
require 'webrick' | |
# gem install mechanize |
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/ | |
create or replace function uuid_generate_v7() | |
returns uuid | |
as $$ | |
begin | |
-- use random v4 uuid as starting point (which has the same variant we need) | |
-- then overlay timestamp | |
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string | |
return encode( |
#!/usr/bin/env zx | |
const fs = require('fs') | |
async function getCurrentVersion() { | |
let version; | |
try { | |
version = await $`/Applications/Chromium.app/Contents/MacOS/Chromium --version` | |
} catch (e) { |
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