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 / 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 / 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)
@chr5tphr
chr5tphr / mdtoc.awk
Last active July 18, 2022 12:17
Create a table of contents for a markdown file
#!/usr/bin/env -S gawk -f
$1~/^##+$/{
l = length($1);
r = q = substr($0, l + 2);
gsub(" ", "-", q);
printf "%" ((l - 2) * 4 + 2) "s[%s](#%s)\n", "* ", r, q
}
@chr5tphr
chr5tphr / exportex.sh
Last active February 4, 2022 17:08
Export latex project with a flat figure hierachy.
#!/usr/bin/env bash
set -u
usage() {
cat <<EOF
Usage: "${BASH_SOURCE[0]##*/}" [options] [extra_file ...]
@chr5tphr
chr5tphr / wofind.sh
Created June 28, 2021 20:35
Find a window in sway with wofi and use use it as a criterion in a swaymsg.
#!/usr/bin/env bash
JQWINS='
[recurse(.nodes[])] |
[
.[] |
select(has("app_id")) |
(.id | tostring) + "\t" + .name + (" [" + if .app_id then .app_id else .shell end + "]")
] |