Skip to content

Instantly share code, notes, and snippets.

@mrgrain
mrgrain / pinentry-1password.sh
Last active January 5, 2025 00:21
1Password CLI pinentry for gpg-agent
#!/bin/sh
COMMAND="op read $OP_PIN_ITEM"
echo "OK"
while read cmd rest; do
echo "cmd=$cmd rest=$rest" >&2
echo "cmd=$cmd rest=$rest" >> $LOG
case "$cmd" in
\#*)
@baldowl
baldowl / RGB_LED.yaml
Last active January 5, 2025 00:22
Playing with ESP32-C6 and ESPHome
light:
- platform: esp32_rmt_led_strip
name: Status LED
pin: GPIO8
rgb_order: RGB
num_leds: 1
rmt_channel: 0
chipset: ws2812
entity_category: config
@nymous
nymous / README.md
Last active January 5, 2025 00: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

@NiceRath
NiceRath / nftables_tproxy_example.nft
Last active January 5, 2025 00:14
NFTables TPROXY - proxy input and output
#!/usr/sbin/nft -f
# see also:
# https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks
# https://docs.kernel.org/networking/tproxy.html
# https://powerdns.org/tproxydoc/tproxy.md.html
# http://git.netfilter.org/nftables/commit/?id=2be1d52644cf77bb2634fb504a265da480c5e901
# http://wiki.squid-cache.org/Features/Tproxy4
# https://serverfault.com/questions/1052717/how-to-translate-ip-route-add-local-0-0-0-0-0-dev-lo-table-100-to-systemd-netw
# https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/netfilter/nft_tproxy.c
@WabaScript
WabaScript / soundboard_scrape.py
Created January 5, 2025 00:12
Quickly scrape sounds from soundboard website to make a local soundboard
import requests
from bs4 import BeautifulSoup
import os
import re
import time
# Base URL for MyInstants
BASE_URL = "https://www.myinstants.com"
CATEGORY_URL = f"{BASE_URL}/en/categories/sound%20effects/"
import pygame
import numpy as np
from pygame.locals import QUIT
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import os
# Engine class: Handles the initialization, object loading, rendering, and main game loop.
class Engine:
import pygame
import numpy as np
from pygame.locals import QUIT, KEYDOWN, KEYUP
from OpenGL.GL import *
from OpenGL.GLU import *
import os
class Engine:
def __init__(self, w, h, fov=np.pi / 4, near=0.1, far=100.0):

A metatable can be defined like

local t = setmetatable({}, {
  __tostring = function() return 'custom tostring behavior!' end
})

Here are the metamethods that you can define, and their behavior

Operators

@hlfshell
hlfshell / ultralearning.md
Created January 15, 2023 22:08
Ultralearning Notes

Ultralearning

The following is the notes I took years ago on the book Ultralearning by Scott Young. The bombastic title and promise to learn virtually anything quickly makes it sound as if its the typical marketing-powered fluff-filled nonfiction book stores are overflowing with, but something about this book stuck with me. After finishing it I quickly went back and wrote these thoughts down. While I don't follow his layout of plans regularly, I have used it to guide a lot of my own self education.

I've successfully utilized it when I needed to refresh on mathematics for my Master's degree (a host of skills that atrophied sigificantly for the dozen years between undergrad and the masters). I've also used it to self-study subjects like Robotics and Deep Learning (though I did decide in the end to go for the Master's accreditation).

I share it here with hopes that someone finds it useful.


Principle 1 - Metalearning