Skip to content

Instantly share code, notes, and snippets.

View chr5tphr's full-sized avatar

Christopher chr5tphr

  • Technically a University in Berlin
  • There's no place like 0x7f000001
View GitHub Profile
@chr5tphr
chr5tphr / rephrase
Created September 18, 2023 14:20
Use ChatGPT to rephrase scientific sentences on the command line. May be used as a template for other ChatGPT-based CLI tools.
#!/usr/bin/env bash
die(){
echo "$@"
exit 1
}
APIKEY="$(gpg -qd ~/.config/apikey/openai.gpg)"
[ "$APIKEY" ] || die "Failed to fetch api key."
@chr5tphr
chr5tphr / otp
Last active August 23, 2023 08:27
Tiny TOTP token management script using gnupg and oathtool, storing encrypted tokens
#!/usr/bin/env bash
die(){
echo "${@}"
exit 1
}
list-targets(){
find "${OTPDIR}" -type f -name '*.gpg' -printf '%P\n' | sed 's/.gpg$//g'
exit
@chr5tphr
chr5tphr / bwfull
Last active August 6, 2023 08:48
Bubblewrap full isolation
#!/bin/sh
BWROOT="${1:?"Root not specified!"}"
shift
env -i bwrap \
--bind "$BWROOT" / \
--unshare-user \
--unshare-cgroup \
--unshare-ipc \
--unshare-pid \
@chr5tphr
chr5tphr / combiget.sh
Last active May 22, 2023 13:56
Get elements from a combination of bash arrays given a flat index
#!/usr/bin/env bash
# combiget: get appropriate elements from a combination of arrays given a flat index
combiget() {
ind="${1:?'No index.'}"
arrs=("${@:2}")
for (( i = 0 ; i < ${#arrs[@]} ; i++)); do
n="$ind"
for (( j = i + 1 ; j < ${#arrs[@]} ; j++ )); do
@chr5tphr
chr5tphr / imspack.py
Created April 12, 2023 15:27
Package a static webpage as a single-entry IMS Content Package (for use with Moodle etc.)
#!/usr/bin/env python
import os
from zipfile import ZipFile
import click
from jinja2 import Template
MANIFEST = r'''
<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
@chr5tphr
chr5tphr / khal-export.py
Created April 5, 2023 09:19
Export multiple events from khal in .ics
#!/usr/bin/env python3
from datetime import datetime
import click
from khal.settings import get_config
from khal.cli import build_collection
from icalendar import Calendar
@click.command()
@chr5tphr
chr5tphr / cliphost.py
Created November 4, 2022 13:08
clipsock
#!/usr/bin/env python3
from argparse import ArgumentParser
from os import unlink, chmod
from os.path import expanduser
from socket import socket, AF_UNIX
from subprocess import run, Popen
from sys import stderr
@chr5tphr
chr5tphr / gitupd
Last active July 29, 2022 09:31
Synchronize uncomitted changes
#!/bin/bash
RMTE="${1:?"No host supplied!"}"
RDIR="${2:?"No path supplied!"}"
REPO="${3:-"refs/heads/sync"}"
git push "${RMTE}:${RDIR}" "+@:${REPO}" && git diff HEAD | ssh "${RMTE}" \
"{ git -C '${RDIR}' reset --hard '${REPO}' && git -C '${RDIR}' apply --index - ; }"
@chr5tphr
chr5tphr / mdmaketoc.awk
Last active July 18, 2022 14:17
Add sectioning and a table of contents to a markdown file
#!/usr/bin/env -S gawk -f
$1~/^##+$/ && $0!~/Table of Contents$/{
intoc = 0
if (l > length($1)) for (k in num) if (k > length($1)) delete num[k]
l = length($1)
num[l] += 1
r = q = substr($0, l + 2)
gsub(" ", "-", q);
@chr5tphr
chr5tphr / mdheadnum.awk
Last active July 18, 2022 13:14
Prepend or replace section numbering for markdown headings
#!/usr/bin/env -S gawk -f
$1~/^##+$/ && $0!~/Table of Contents$/{
if (l > length($1)) for (k in num) if (k > length($1)) delete num[k]
l = length($1)
num[l] += 1
r = substr($0, l + 2)
p = ""; for (i in num) p = p num[i] "."
if (length(num) > 1) p = substr(p, 0, length(p) - 1)