Skip to content

Instantly share code, notes, and snippets.

View infojunkie's full-sized avatar
💭
🎶

Karim Ratib infojunkie

💭
🎶
View GitHub Profile
@infojunkie
infojunkie / tmux-session.sh
Last active November 14, 2025 23:05
Save and restore the state of tmux sessions and windows.
#!/usr/bin/env bash
# Save and restore the state of tmux sessions and windows.
# @see https://github.com/mislav/dotfiles/blob/master/bin/tmux-session
set -e
dump() {
local d=$'\t'
tmux list-windows -a -F "#S${d}#W${d}#{pane_current_path}"
}
@infojunkie
infojunkie / dvd-rip.sh
Last active November 18, 2025 06:18
Rip a folder with HandBrakeCLI
#!/usr/bin/env bash
#
# Given a parent folder, find all DVD images (*.iso files and VIDEO_TS folders)
# Convert all titles within each DVD image to mkv using HendBrakeCLI with a hard-coded preset
#
# Prerequisites: xmllint, lsdvd, HandBrakeCLI
#
#!/usr/bin/env bash
OLDIFS=$IFS
IFS=$'\n'
@infojunkie
infojunkie / filter.xsl
Created August 24, 2024 07:42
XSL transformation to filter out some elements
<?xml version="1.0" encoding="UTF-8"?>
<!--
Filter out unwanted tags passed on the command line.
https://stackoverflow.com/a/2641719/209184
Usage: xslt3 -xsl:filter.xsl -s:share/instruments/instruments.xml filter="Channel|drumset|genre"
-->
@infojunkie
infojunkie / export_sessions.php
Last active August 14, 2024 01:56
Drush script to decode Drupal session(s) given optional cookie
<?php
/**
* Retrieve session entry for given cookie.
* https://drupal.stackexchange.com/a/231726/767
*
* Usage: drush scr scripts/export_sessions.php -- --cookie=<URL-decoded value of SESSxxxx cookie>
*
* [
* {
@infojunkie
infojunkie / abilities.php
Last active June 10, 2024 04:28
Running WorkBC Abilities quiz using PhpSpreadsheet
<?php
// Uses my fork of PhpSpreadsheet to add custom functions
// https://github.com/infojunkie/PhpSpreadsheet
//
// Usage:
// - Place spreadsheet "10-1. Quizzes - Algo Check - Shared.xlsx" in sheets/ subfolder
// - Run `php abilities.php`
// - Observe output:
/**
@infojunkie
infojunkie / discogs-tag.sh
Last active April 15, 2023 04:22
Discogs artists to flac metatag
#! /bin/bash
#
# Requirements: curl, jq, metaflac
#
# Assumes that the files are already sorted by track number.
#
curl -s https://api.discogs.com/releases/$1 --user-agent "discogs-tag/1.0" | jq -r '.tracklist[].artists | map(.name) | join(", ") | gsub(" \\(\\d+\\)"; "")' > artists
IFS=$'\n' artists=($(<artists)) i=0; for f in *.flac; do metaflac "$f" --remove-tag=ARTIST --set-tag="ARTIST=${artists[$i]}"; ((i=i+1)); done
@infojunkie
infojunkie / fetish.ts
Last active April 8, 2023 07:17
Thinnest wrapper around fetch() Web API to throw an error if not ok
/**
* Fetch wrapper to throw an error if the response is not ok.
* Why indeed? https://github.com/whatwg/fetch/issues/18
*/
export async function fetish(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response> {
const response = await fetch(input, init);
if (!response.ok) throw new Error(response.statusText);
return response;
}
@infojunkie
infojunkie / chapters2cue.php
Created February 6, 2023 17:02
Convert ffprobe chapters to cuesheet
#!/usr/bin/env php
<?php
/**
* Convert ffprobe chapters to cuesheet.
*
* This is typically used in a video-to-audio transcoding job:
*
* - ffprobe -show_chapters -print_format json -loglevel -8 video.file > chapters.json
* - ffmpeg -i video.file audio.file
@infojunkie
infojunkie / .bash_aliases
Created January 11, 2023 20:32
git-update updates all repos and prunes the stale branches
alias git-update='find . -mindepth 1 -maxdepth 3 -type d -name ".git" -print -exec git -C {}/.. pull --recurse-submodule \; -exec git -C {}/.. remote prune origin \;'
@infojunkie
infojunkie / tar-diff.sh
Last active September 23, 2022 17:15
Create an archive out of the diff of two archives
#! /bin/bash
set -e
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "Usage: $(basename -- "$0") /path/to/original.tar.gz /path/to/modified.tar.gz"
[ -f "$1" ] || die "File $1 does not exist"
[ -f "$2" ] || die "File $2 does not exist"