Skip to content

Instantly share code, notes, and snippets.

View tfeldmann's full-sized avatar
🐕

Thomas Coenen tfeldmann

🐕
View GitHub Profile
@tfeldmann
tfeldmann / rot18.c
Last active July 9, 2020 09:22
ROT18 implementation in python and c
void rot18(char *c)
{
while (*c)
{
if (*c >= 'A' && *c <= 'Z')
*c = ('A' + (*c - 'A' + 13) % 26);
else if (*c >= 'a' && *c <= 'z')
*c = ('a' + (*c - 'a' + 13) % 26);
else if (*c >= '0' && *c <= '9')
*c = ('0' + (*c - '0' + 5) % 10);
@tfeldmann
tfeldmann / platformio.ini
Created November 14, 2020 11:46
PlatformIO config for using the BME680 with an ESP32 using the Arduino framework
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
@tfeldmann
tfeldmann / format_consecutive.py
Last active July 20, 2023 15:04
Format consecutive numbers as ranges
from itertools import count, groupby
from typing import Iterable, Tuple
def group_consecutive(nums: Iterable[int]) -> Iterable[Tuple[int, ...]]:
counter = count()
for _, g_it in groupby(nums, lambda n: n - next(counter)):
yield tuple(g_it)
@tfeldmann
tfeldmann / djadmin_theme.js
Created June 24, 2024 15:19
Find the currently active django admin mode (light / dark)
function currentTheme() {
const currentTheme = localStorage.getItem("theme") || "auto";
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
if (currentTheme === "auto") {
return prefersDark ? "dark" : "light";
}
return currentTheme;
}