Skip to content

Instantly share code, notes, and snippets.

@mortie
mortie / Makefile
Last active February 20, 2025 13:16
Meson C++
OUT ?= build
PROGRAM = example
.PHONY: build
build: $(OUT)/build.ninja
ninja -C $(OUT) $(PROGRAM)
.PHONY: setup
setup: $(OUT)/build.ninja
@mortie
mortie / FastHashSet.hh
Last active December 2, 2024 22:28
Fast flat hash set in C++ (Warning: not tested, probably has bugs)
#pragma once
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <cstdlib>
#include <functional>
template<
typename Key,
@mortie
mortie / reverse-ssh-tunnel.service
Created November 11, 2024 14:42
SSH service for creating a reverse SSH tunne
[Unit]
Description=Create reverse SSH tunnel
[Service]
User=martin
ExecStart=/usr/bin/autossh -N -T -o 'ServerAliveInterval 10' -o 'ServerAliveCountMax 2' -R 0.0.0.0:<SERVER PORT>:localhost:22 <SERVER>
Restart=always
RestartSec=5s
[Install]
@mortie
mortie / hashmap.c
Last active September 20, 2024 21:35
C hashmap
#include "hashmap.h"
#include <stdint.h>
#include <stdlib.h>
static uint32_t strhash(const char *str)
{
// I'm sitting at an airplane as I'm writing this,
// I don't have access to resources on what reasonable hash algorithms,
// I need something and this is something
@mortie
mortie / gamerandr
Last active February 16, 2024 21:44
gamerandr: Display mode switching automation for GNOME Wayland
#!/bin/sh
# This program uses gnome-randr (https://github.com/maxwellainatchi/gnome-randr-rust)
# to change display configurations for the duration of a process.
# It's intended to use with games if you're normally using the computer with
# DPI scaling enabled.
# Usage: gamerandr <config> [command...]
# It can be used with Steam by changing the launch options of a game to:
# gamerandr <config> %command%
# For example, I use 'gamerandr fps %command%' for Counter-Strike 2,
@mortie
mortie / dtcanon.py
Last active December 13, 2022 13:38
Create a canonicalized representation of devicetree files, for easier diffing
#!/usr/bin/env python3
import sys
import traceback
import subprocess
class Reader:
def __init__(self, f):
self.f = f
self.next = f.read(1)
@mortie
mortie / meson.build
Created December 6, 2022 10:14
Meson project with clang-tidy and clang-format integration
project('test', 'cpp')
clang_tidy_prog = find_program('clang-tidy', required: false)
run_clang_tidy_prog = find_program('./run-clang-tidy.sh')
clang_format_prog = find_program('clang-format', required: false)
run_clang_format_prog = find_program('./run-clang-format.sh')
srcs = [
'src/foo.cc',
'src/bar.cc',
@mortie
mortie / enc.c
Last active October 3, 2022 15:50
V4L2 video encoder
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/videodev2.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/eventfd.h>
#include <sys/mman.h>
@mortie
mortie / cfdns.sh
Created September 13, 2022 19:22
Cloudflare dynamic DNS
#!/bin/sh
set -eu
token='<your API token>'
zone='<your DNS zone ID>'
record='<your DNS record ID>'
ip_url='ifconfig.co'
call() {
@mortie
mortie / sst
Created August 5, 2022 21:24
sst: Reliable SSH connections using tmux
#!/bin/sh
# SST: SSH, but reliable, using tmux.
# When you lose connection, the connection will be re-tried, and you will get back where you
# left off.
# An aggressive heartbeat setting is used to detect network issues much more reliably than
# SSH's default settings would.
#
# Usage:
# sst <host>: Create a temporary tmux session, which will be killed when it hasn't