Skip to content

Instantly share code, notes, and snippets.

@mhofman
mhofman / MacOS Screen sharing on localhost only.md
Last active January 5, 2025 00:29
MacOS ScreenSharing on localhost only

Force recent MacOS to listen for screen sharing on localhost only, keeping SIP on

All the following has been validated on MacOS Mojave 10.14.6

Problems

While there is a command line preference to accept only local VNC connections, that setting still doesn't prevent the daemon from listening to the wildcard address, and advertise the service on Bonjour. I haven't actually tried to see if it restricted anything in modern versions of the operating system, but here it is for reference:

sudo defaults write /Library/Preferences/com.apple.RemoteManagement.plist VNCOnlyLocalConnections -bool yes
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active January 5, 2025 00:26
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@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):