Skip to content

Instantly share code, notes, and snippets.

View ungive's full-sized avatar
💭
scrobble scrobble scrobble

Jonas van den Berg ungive

💭
scrobble scrobble scrobble
View GitHub Profile
@ungive
ungive / paddle-cover-fees.py
Created April 12, 2026 18:03
Formula to calculate fee coverage for Paddle for a given subtotal and VAT percentage. Also takes a source and target currency to add fee conversion fees. The source currency is the buyer currency, the target currency is your account balance currency. Note that with a payout, if your bank account's currency is different from your Paddle account c…
"""
total = 2500
tax = 399
subtotal = total - tax
vat_percent = tax / subtotal = 0.19
wanted_revenue = total - tax = 2101 # revenue without fees
new_subtotal = subtotal + X
new_tax = new_subtotal * vat_percent
@ungive
ungive / CMakeLists.txt
Created April 4, 2026 13:37
Generate compile_commands.json automatically for clangd with CMake
# Automatically create and update a symlink to the compile_commands.json file in
# the source directory, so that it is in a known location and can be picked up
# easily by clangd. When using Visual Studio Code, use the clangd extension,
# version 0.3.2 or higher, so the clangd language server automatically restarts
# on configuration change, which is useful when switching between Debug and
# Release builds (to switch between debugging and testing performance). See
# https://github.com/clangd/vscode-clangd/issues/300. Always build the "ALL"
# target during development, to ensure the compile_commands.json is in sync.
if(CMAKE_EXPORT_COMPILE_COMMANDS)
add_custom_target(
@ungive
ungive / main.go
Created December 2, 2021 22:53
external monitor brightness control
package main
import (
"errors"
"fmt"
"log"
"math"
"os"
"os/exec"
"strconv"
@ungive
ungive / brightness.py
Last active April 16, 2020 13:50
Regulate your screen brightness live with a simple zenity slider. Made this script because the built-in slider in Manjaro's task bar doesn't work on my older iMac and I don't want to put too much effort into fixing it. Based on this script: https://gist.github.com/ViktorNova/a13c6613dd365b2c67b0 NOTE: Check line 60 for window positioning
#!/usr/bin/python3
import sys, subprocess, os, time
from subprocess import PIPE, Popen
from threading import Thread
from queue import Queue, Empty
import atexit
dir_path = os.path.dirname(os.path.realpath(__file__))
lockfile=os.path.join(dir_path, '.brightness-lock~')
#!/usr/bin/python3
import sys, subprocess, os
from subprocess import PIPE, Popen
from threading import Thread
from queue import Queue, Empty
def enqueue_output(out, queue):
for line in iter(out.readline, b''):
queue.put(line)
""" Disclaimer: This is just pseudocode that's really similar to Python.
"""
# Generiere ein Spielfeld. Hierbei ist `n` die Seitenlänge
# (das Feld ist quadratisch) und `b` die Anzahl der Minen.
field = Field(n, b)
# - `startFields` ist eine Liste mit allen möglichen Startfeldern. [1]
# - `solvedFields` ist eine Liste mit Lösungen für alle Felder `startFields`.
# Bis zu diesem Punkt werden sie nur mit den Regeln der Logik gelöst. [2]
@ungive
ungive / strncmp_fast.c
Last active June 6, 2017 20:55
Optimised string comparison.
#include <stddef.h>
#include <stdint.h>
int strncmp_fast(const char *str1, const char *str2, size_t size)
{
typedef uint_fast32_t word_t;
int blocks = size >> 2;
if (size > sizeof(word_t)) {
word_t *word1 = (word_t *)str1;