Skip to content

Instantly share code, notes, and snippets.

View jbaiter's full-sized avatar

Johannes Baiter jbaiter

View GitHub Profile
@jbaiter
jbaiter / lg_c2.edid
Last active November 27, 2023 23:02
LG C2 OLED EDID for flashing to a HDMI dongle to simulate HDR support to a PS5
@jbaiter
jbaiter / index.js
Last active September 5, 2023 19:18
Minimal sample to reproduce esbuild bug with disabled dependencies
import nodeFetch from 'node-fetch';
let fetchImpl;
if (typeof fetch !== 'undefined') {
fetchImpl = fetch;
console.log('Using browser fetch');
} else {
console.log('Using node-fetch');
fetchImpl = nodeFetch;
}
@jbaiter
jbaiter / sqlite3.d.ts
Created August 18, 2023 12:39
@sqlite.org/sqlite-wasm TypeScript type hints
// unofficial sqlite3 types.
// initially based on https://gist.github.com/mizchi/cb572eae55154ec781ced5c111621939
// by GitHub user @mizchi
// expanded by @jbaiter to:
// - describe all high-level APIs and data structures as closely as possible
// - include docstrings based on the official documentation
// - Type out and document all the low-level extension and WASM↔JS glue APIs.
declare module "@sqlite.org/sqlite-wasm" {
/** Types of values that can be passed to/retrieved from SQLite. */
@jbaiter
jbaiter / fts5-offsets.c
Last active July 30, 2023 22:22
Implementation of SQLite FTS3/4 `offsets` auxiliary function for FTS5. Call with `offsets(ftsTable, colIdx)`. Returns `(colIdx, startByteOffset, endByteOffset)` for every matching phrase in a row.
/* Add your header comment here */
#include "sqlite3ext.h" /* Do not use <sqlite3.h>! */
SQLITE_EXTENSION_INIT1
#include <stddef.h>
#include <string.h>
/* =================================================================== */
/* =============== Copied from sqlite/fts5_aux.c ===================== */
/* =================================================================== */
#ifndef UNUSED_PARAM2
@jbaiter
jbaiter / wg-monitor.py
Last active May 25, 2023 13:29
Structured Logging and Prometheus Exports for Wireguard sessions
#!/usr/bin/env python3
"""Wireguard logging and monitoring tool.
Logs the following events along with the peer state in JSON format to stdout:
- Peer connected (= successfull handshake after period of no handshakes)
- Peer disconnected (= no handshake for longer than 5 minutes)
- Peer roamed (= source IP of the peer changed)
Additionally, the tool exposes a Prometheus-compatible monitoring endpoint
on port 9000 that exports the following metrics:
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://127.0.0.1:8080/start_fixture.json",
"type": "Manifest",
"behavior": ["paged"],
"rights": "http://rightsstatements.org/vocab/NoC-NC/1.0/",
"metadata": [
{
"label": { "de": ["Titel"], "en": ["Title"] },
"value": {
@jbaiter
jbaiter / exporter-rewrite-proxy.py
Last active March 3, 2022 13:10
Rewriting proxy to reduce cardinality of Prometheus node-exporter counter metrics.
#!/usr/bin/env python3.9
""" Rewriting proxy to reduce cardinality of Prometheus node-exporter counter metrics.
This small proxy service is intended to run alongside the Prometheus
node-exporter, with Prometheus fetching the metrics from the proxy instead of
from the exporter directly. The proxy will then apply user-defined rewriting
rules to the metrics' labels, currently either by wholesale removal of certain
labels or by rewriting certain label values. If, after rewriting, there are
several time series with identical names and labels, they are summed to form a
single counter metric.
@jbaiter
jbaiter / rate-limit.lua
Created January 23, 2018 16:10
Simple Nginx Rate Limiting with Lua, redis and redis-cell
-- Requires the `redis-cell` module to be installed in Redis: https://github.com/brandur/redis-cell
local redis = require "nginx.redis"
local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
@jbaiter
jbaiter / mergeRefs.ts
Created March 22, 2021 07:37
mergeRefs: Merge multiple React Refs into a single one
/** Merge multiple refs into a single one.
*
* Taken from https://www.davedrinks.coffee/how-do-i-use-two-react-refs/, type-hints by us
*/
export function mergeRefs<T>(
...refs: (React.MutableRefObject<T> | React.Ref<T>)[]
): React.Ref<T> | null {
const filteredRefs = refs.filter(Boolean)
if (!filteredRefs.length) return null
if (filteredRefs.length === 0) return filteredRefs[0]
@jbaiter
jbaiter / c19vakz.py
Last active June 5, 2021 12:19
Check if a a COVID-19 vaccination appointment can be made, for Bavarian citizens.
import requests
from keycloak import KeycloakOpenID
# To obtain this, log into your account and select a person.
# The citizen ID is the last part of the URL, a UUID
CITIZEN_ID = None
# This is your authentication info
EMAIL = None
PASSWORD = None