Skip to content

Instantly share code, notes, and snippets.

View ascopes's full-sized avatar

Ash ascopes

  • United Kingdom
  • 11:50 (UTC)
View GitHub Profile
@ascopes
ascopes / dynload.c
Last active January 11, 2026 09:55
Loads a shared object and executes code inside it
#include <assert.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
const char *const module = "./module.so";
typedef void (*run_func)(void);
int main(void) {
@ascopes
ascopes / stream.py
Created January 4, 2026 12:05
Python functional stream operations
import abc
import itertools
import typing as t
type MapFn[T, U] = t.Callable[[T], U]
type PredicateFn[T] = t.Callable[[T], bool]
type FlatMapFn[T, U] = t.Callable[[T], Stream[U]]
type ReduceFn[C, T] = t.Callable[[C, T], C]
@ascopes
ascopes / chain.py
Created December 24, 2025 10:09
Python functional operator chaining
from __future__ import annotations
import abc
import typing as t
class Operator[A, B](abc.ABC):
__slots__ = ()
@abc.abstractmethod
@ascopes
ascopes / upgrade-fedora.md
Last active November 9, 2025 10:10
Upgrade steps for Fedora

Upgrading Fedora

The following is summarised from https://docs.fedoraproject.org/en-US/quick-docs/upgrading-fedora-offline/

  1. Install dependencies: sudo dnf install clean-rpm-gpg-pubkey dracut-config-rescue remove-retired-packages rpmconf symlinks
    • Most of these will be used after the upgrade step next.
    • dracut-config-rescue will automate updating the rescue kernel in the future during a dnf upgrade.
  2. Update existing system
    1. sudo dnf upgrade --refresh
  3. sudo reboot
@ascopes
ascopes / adguard.yaml
Last active October 5, 2025 17:29
Adguard Home Configuration
apiVersion: v1
kind: Namespace
metadata:
name: adguard
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: adguard
namespace: adguard
@ascopes
ascopes / aktor.py
Last active July 13, 2025 09:46
Crude implementation of the actor model in Python using asyncio.
import abc
import asyncio
import dataclasses
import traceback
import typing as t
import weakref
@t.final
@dataclasses.dataclass(frozen=True, slots=True, kw_only=True)
@ascopes
ascopes / pihole.md
Last active August 22, 2025 11:10
pihole config for k3s (/var/lib/rancher/k3s/server/manifests/pihole.yaml)

PiHole configuration for Raspberry Pi running k3s.

Requirements

  • network router should be pointing to the IP address of the k3s cluster for DNS.
  • k3s cluster must have a static IP assigned to it via DHCP by the network router.
  • k3s is required, as this assumes we're using traefik as the reverse proxy.
  • the host running the k3s control plane node should have the resolv.conf in this gist copied to /etc/resolv.conf (if you use systemd-resolved, good luck, you'll have to find a way to overwrite this so systemd doesn't just blindly revert it
@ascopes
ascopes / tar_octal_ascii_number.py
Created June 1, 2025 11:10
Python encoding of "octal numbers" in tar files
import typing as t
@t.final
class TarOctalAsciiNumber(int):
__slots__: t.Sequence[str] = ()
def __new__(cls, value: int) -> t.Self:
return super().__new__(cls, value)
@ascopes
ascopes / stacktrace.sh
Last active May 3, 2025 10:36
Script to produce a bash stacktrace, compatible with Bash v5.x
function stacktrace() {
if ! command -v realpath > /dev/null 2>&1; then
function realpath() {
cd "${1}" > /dev/null 2>&1 && pwd || printf "?"
}
fi
printf "Script stacktrace (most recent call first):\n"
local frame=0
@ascopes
ascopes / build.sh
Last active February 10, 2025 07:06
Creates a GNU cross-compiler consisting of binutils, gcc, g++, and gdb for a given architecture. Useful for OS development. Requires podman or docker locally.
#!/usr/bin/env bash
set -o errexit
set -o nounset
[[ -n ${DEBUG+defined} ]] && set -o xtrace
function container() {
if docker --version > /dev/null 2>&1; then
local command=(docker "${@}")
elif podman --version > /dev/null 2>&1; then
local command=(podman "${@}")