Skip to content

Instantly share code, notes, and snippets.

@vxgmichel
vxgmichel / amerge.py
Created May 16, 2024 15:54
Merge of async generators using anyio
import random
import asyncio
from contextlib import asynccontextmanager
from typing import AsyncIterable, AsyncIterator, TypeVar
from anyio import create_memory_object_stream, create_task_group
from anyio.abc import ObjectReceiveStream, TaskStatus
from anyio.streams.memory import MemoryObjectSendStream
T = TypeVar("T")
@parmus
parmus / aliases.sh
Last active September 18, 2024 19:59
YAML syntax highlighting in less using yq
# YAML syntax highlight for the terminal. Just pipe YAML through it.
alias yc='yq -C eval-all'
# Less with YAML syntax highlighting
alias yless='yq -C eval-all | less -R'
@akrylysov
akrylysov / README.md
Last active October 2, 2024 17:32
Fast Intel-on-ARM Docker on macOS with Lima and Rosetta

macOS 13 Ventura introduced support of running amd64 binaries with Rosetta inside of arm64 Linux VMs when using Apple Virtualization framework.

Lima VM v0.14.0 and later support the new feature.

Setup:

# Install Docker client and Lima
brew install docker docker-compose docker-credential-helper lima

Docker on Lima (lima-vm/lima) Setup Guide

In recent months, Lima has become de facto standard software as a free and open source alternative to Docker Desktop for Mac. Several projects (such as Colima, Rancher Desktop, or Finch) for similar purpose also uses Lima as their backend. These projects will make it easier to set up Lima. But some people may not want to introduce extra components other than Lima. This guide will show you how to set up Lima to be alternative to Docker Desktop for Mac, while using Lima only.

🪣 Note. It is a good practice to uninstall Docker Desktop for Mac before proceeding with the following steps.

1. Install Lima and Docker CLI

@Kludex
Kludex / main.py
Created December 5, 2022 08:58
Uvicorn logging for prod & dev
import logging
import sys
from typing import List
import structlog
import uvicorn
from fastapi import FastAPI
from structlog.stdlib import ProcessorFormatter
from structlog.types import Processor
@nymous
nymous / README.md
Last active November 19, 2024 08:17
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

@sts10
sts10 / rust-command-line-utilities.markdown
Last active November 19, 2024 11:55
A curated list of command-line utilities written in Rust

A curated list of command-line utilities written in Rust

Note: I have moved this list to a proper repository. I'll leave this gist up, but it won't be updated. To submit an idea, open a PR on the repo.

Note that I have not tried all of these personally, and cannot and do not vouch for all of the tools listed here. In most cases, the descriptions here are copied directly from their code repos. Some may have been abandoned. Investigate before installing/using.

The ones I use regularly include: bat, dust, fd, fend, hyperfine, miniserve, ripgrep, just, cargo-audit and cargo-wipe.

  • atuin: "Magical shell history"
  • bandwhich: Terminal bandwidth utilization tool
@phortuin
phortuin / signing-git-commits.md
Last active November 16, 2024 07:44
Set up a GPG key for signing Git commits on MacOS (M1)

Based on this blogpost.

To sign Git commits, you need a gpg key. GPG stands for GNU Privacy Guard and is the de facto implementation of the OpenPGP message format. PGP stands for ‘Pretty Good Privacy’ and is a standard to sign and encrypt messages.

Setting up

Install with Homebrew:

$ brew install gpg
@davidfowl
davidfowl / .NET6Migration.md
Last active October 23, 2024 18:30
.NET 6 ASP.NET Core Migration
@wvanderdeijl
wvanderdeijl / federation.md
Last active June 27, 2024 06:24
Google Cloud service account to AWS Role federation

Google Cloud service account to AWS Role federation

inspired by https://github.com/shrikant0013/gcp-aws-webidentityfederation

  1. create an AWS Role configured for Web Identity federation using Cognito or any OpenID provider
  2. select Google as the Identity provider in the wizard
  3. set the audience to a dummy value and do not add any additional conditions in the setup wizard. We will edit the trust policy after completing the wizard.
  4. assign any permissions needed to the role
  5. read up on "Available keys for AWS web identity federation" at