Skip to content

Instantly share code, notes, and snippets.

@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
@mortie
mortie / tarex.c
Created July 20, 2022 16:32
Fast tar archive extractor
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
char zeroblock[512];
@mortie
mortie / jcof.md
Last active July 10, 2022 22:24
JCOF: JSON-like Compact Object Format

JCOF: JSON-like Compact Object Format

A more efficient way to represent JSON-style objects.

About

JCOF tries to be a slot-in replacement for JSON, with most of the same semantics, but with a much more compact representation of objects. The main way it does this is to introduce a string table at the beginning of the object, and then replace all strings with indexes into that string table. It also employs a few extra tricks to make objects as small as possible, without losing the most

#!/usr/bin/env python3
from pathlib import Path
import time
import sys
dirpath = sys.argv[1]
def fsize(f):
try: