Skip to content

Instantly share code, notes, and snippets.

View stpettersens's full-sized avatar

Sam Saint-Pettersen stpettersens

View GitHub Profile
@stpettersens
stpettersens / id.c3
Last active June 8, 2026 15:42
Utility functions for C3
module util::id;
import libc;
alias Id = String;
fn Id generate_id(uint length) {
/* Valid IDs are a-z lowercase *length* char strings */
DString id = {};
while (id.len() < length) {
int r = (97 + (libc::rand() % 26));
@stpettersens
stpettersens / stack.c3
Created June 8, 2026 15:34
Simple stack implemented around list in C3
module stack<Type>;
import std::collections;
/* A stack implemented around a list */
struct Stack {
List{Type} items;
int size;
}
fn Stack new() {
@stpettersens
stpettersens / refresh-jellyfin.py
Created April 4, 2026 14:11
Script to refresh a Jellyfin Server media library given a server domain and an API key.
#!/usr/bin/env python3
# refresh-jellyfin media script
import os
import sys
import requests
from datetime import datetime
from typing import TypeAlias
from dataclasses import dataclass
@stpettersens
stpettersens / C3.xml
Last active February 17, 2026 21:41
C3 Programming Language User Defined Language (UDL) XML for Notepad++ - WIP
<NotepadPlus>
<UserLang name="C3" ext="c3" udlVersion="2.1">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="yes" foldCompact="no" forcePureLC="1" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="yes" Keywords4="no" Keywords5="yes" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00/* 01 02*/ 03// 04</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@stpettersens
stpettersens / now_playing.d
Created February 16, 2026 15:49
Simple program that prints the current playing song from Rhythmbox.
import std.conv;
import std.file;
import std.stdio;
import std.string;
import std.process;
import core.time;
import core.thread;
import core.sys.posix.unistd; // getlogin
@stpettersens
stpettersens / gpg-key-migration.md
Created February 14, 2026 17:31 — forked from angela-d/gpg-key-migration.md
Move GPG Keys from One Machine to Another

Migrate GPG Keys from One Workstation to Another

Replace [your key] with your key ID

To obtain your key ID

gpg --list-secret-keys --keyid-format LONG

Which returns something like

@stpettersens
stpettersens / rpla.py
Last active February 7, 2026 21:49
Simple program to find resistance for a given resistivity in ohm metre on copper or aluminium wires given length and c.s.a.
#!/usr/bin/env python3
# Simple program to find resistance
# Author: Sam Saint-Pettersen, Feb 2026
# R = pL/A for a given resistivity in ohm metre (i.e. pCu or pAl).
import os
import sys
# Resistivities
resists: dict[str,float] = {
@stpettersens
stpettersens / onefetch_c3.diff
Created February 5, 2026 19:28
Patch onefetch's c3 logo to use my version of the logo.
--- languages.yaml 2026-02-01 16:31:21.483241400 +0000
+++ ../onefetch_c3/languages.yaml 2026-01-26 17:25:19.510650800 +0000
@@ -263,30 +263,32 @@
C3:
type: programming
ascii: |
- {0} .d8{1}888{2}b. {3} .d8{4}888{5}b.
- {0}d88P{1} Y{2}88b {3}d88P{4} Y{5}88b
- {0}888 {1} {2}888 {3} {4} .d{5}88P
- {0}888 {1} {2} {3} {4}888{5}8"
@stpettersens
stpettersens / onefetch_c3_cargo.toml
Created January 26, 2026 17:09
This is the interim Cargo.toml for my fork of onefetch that adds C3 language support.
[workspace.package]
authors = ["o2sh <ossama-hjaji@live.fr>"]
edition = "2024"
license = "MIT"
version = "2.26.1"
repository = "https://github.com/o2sh/onefetch"
[workspace]
members = ["ascii", "image", "manifest"]
@stpettersens
stpettersens / Dockerfile.python
Last active December 4, 2025 00:31
Dockerfile to build Python 3.13.9 from source with an Alpine image.
# Dockerfile to build Python 3.13.9 from source with an Alpine image.
FROM alpine:latest
# Install build dependencies for python and git
RUN sed -i '2s/^# *//' /etc/apk/repositories
RUN apk update && apk add --no-cache build-base zlib-dev openssl-dev git
# Create python directory.
RUN mkdir -p /usr/build/python
WORKDIR /usr/build/python