Skip to content

Instantly share code, notes, and snippets.

View pbsds's full-sized avatar
🥸
In PhD crunch mode

Peder Bergebakken Sundt pbsds

🥸
In PhD crunch mode
View GitHub Profile
#!/usr/bin/env bash
# make CTRL-C kill background jobs
# https://stackoverflow.com/a/2173421
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM INT EXIT
# wait if too many background jobs
wait_max_concurrent() {
local n="$1"
if [[ "$n" -le 0 ]]; then
@pbsds
pbsds / committer-progress.sh
Last active October 12, 2025 20:49 — forked from lorenzleutgeb/committer-progress.sh
Nixpkgs Committer Progress
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash gh
set -eu
# See <https://gist.github.com/lorenzleutgeb/239214f1d60b1cf8c79e7b0dc0483deb>.
# Will exit non-zero if not authenticated.
gh auth status
if [ $# -ge 1 ]
#!/usr/bin/env nix-shell
#!/nix-shell --pure -i bash -p git git-wait nix gum
set -euo pipefail
export GIT_WAIT_TIMEOUT_MS=5000
trace() ( set -x; "$@"; )
die() { echo >&2 "ERROR:" "$@"; exit 1; }
git diff HEAD --quiet --exit-code || die "Your worktree is dirty, please commit your changes first."
# Fetch upstream branch chosen by user
@pbsds
pbsds / idun.sh
Last active September 2, 2025 11:46
ssh idun-login1.hpc.ntnu.no sinfo -N -o %all --json | jq '
[.sinfo[]|select(.partition.name == "CPUQ")] as $CPUQ_nodes |
[.sinfo[]|select(.partition.name == "GPUQ")] as $GPUQ_nodes |
def gpus_maximum:
.gres.total
| match("gpu:[^:]*:([0-9]+)").captures[0].string
| tonumber;
def gpus_used:
.gres.used
porcelain2jsonl() {
uniq | (
printf "["
while read key data; do
if test -z "$key"; then
printf "]\n["
else
printf '{"%s": "%s"}, ' "$key" "$data"
fi
done
@pbsds
pbsds / .envrc
Last active July 8, 2023 03:50
flake shell example
NIX_CONFIG="extra-experimental-features = nix-command flakes" use flake
@pbsds
pbsds / download-from-unit-bird-no.py
Created June 27, 2023 10:57
Example: `python download-from-unit-bird-no.py https://hdl.handle.net/11250/3059978`
#!/usr/bin/env python
import requests
from requests.utils import parse_url
from functools import lru_cache
from pathlib import Path
import shlex
from tqdm.auto import tqdm
import re
import typer
import os
@pbsds
pbsds / life.py
Created September 19, 2022 11:59
smol
import numpy as n,pygame as p
q=(999,)*2
b=n.random.rand(*q)>.3
t=p.display
r=n.roll
o=p.surfarray.pixels2d(t.set_mode(q))
while 1:
w=sum(r(r(b,a,0),c,1)for a in[-1,0,1]for c in[-1,0,1])
b=b&((w==3)|(w==4))|((~b)*(w==3))
o[:,:]=0-b
#!/usr/bin/env python
import re
import os
import sys
from pathlib import Path
import subprocess
import shutil
import concurrent.futures as futures
import requests
import json
$fn = 100;
rotate([0, 0, 180]) {
color("brown"){
translate([-2.5, -2.5, 0]) cube([5, 5, 70]);
translate([0, 2.5, 50]) cube([40, 5, 5], center=true);
}
translate([0, 5, 50])