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
{
"@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 / 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
@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]
#!/usr/bin/env python3
from __future__ import annotations
import html
import sys
from concurrent.futures import ProcessPoolExecutor, as_completed
from dataclasses import dataclass
from enum import Enum
from itertools import chain
from multiprocessing import cpu_count
String anonymizeIp(def ip) {
if (ip.contains(':')) {
try {
StringTokenizer tok = new StringTokenizer(ip, ':');
String firstGroup = tok.nextToken();
String secondGroup = tok.nextToken();
String thirdGroup = tok.nextToken();
return firstGroup + ":" + secondGroup + ":" + thirdGroup + ":0:0:0:0:0";
} catch (Exception e) {
return "0:0:0:0:0:0:0:0";