Skip to content

Instantly share code, notes, and snippets.

@bsidhom
bsidhom / rip_dvd.py
Created December 27, 2017 19:59
Rip all chapters from a DVD to separate files
#!/usr/bin/env python3
import argparse
import datetime
import os
import os.path
import subprocess
import time
def log_message(message):
@bsidhom
bsidhom / package_python.sh
Created June 1, 2018 23:21
Package an executable binary file into a python script
#!/usr/bin/env bash
set -Eeuo pipefail
function main() {
local input_file="$1"
cat <<EOF
from __future__ import print_function
import bz2
@bsidhom
bsidhom / git-branch-subtree.sh
Created July 10, 2018 21:03
Print graphical subtree of all branches that separate from master from the same point as the current HEAD
# The following is very useful for keeping track of ongoing work in dependent branches, e.g., before rebasing.
git log --graph --oneline --decorate --all --ancestry-path --not master $(git merge-base master HEAD)
@bsidhom
bsidhom / git-update-submodules.sh
Created July 17, 2018 18:14
Update each submodule to the latest version of `origin`'s default branch
#!/usr/bin/env bash
git submodule foreach 'git fetch origin && git checkout $(git symbolic-ref refs/remotes/origin/HEAD)'
#!/usr/bin/env bash
# Show the upstream tracking branch for HEAD
git rev-parse --abbrev-ref --symbolic-full-name '@{u}'
# Show the upstream tracking branch for `my-branch`
git rev-parse --abbrev-ref --symbolic-full-name 'my-branch@{u}'
# List each local branch along with its upstream tracking branch
git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads
@bsidhom
bsidhom / pwgen.py
Created August 4, 2018 17:44
Password generator
#!/usr/bin/env python3
import argparse
import secrets
import string
def generate_diceware_password(length, word_file):
with open(word_file) as file:
lines = [line.rstrip() for line in file]
@bsidhom
bsidhom / LICENSE
Created August 4, 2018 17:46
This license applies to all public gists: https://gist.github.com/bsidhom
MIT License
Copyright (c) 2018 Benjamin Sidhom
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@bsidhom
bsidhom / concat-mp4.py
Created September 24, 2019 02:32
Concatenate MP4s in the order provided using ffmpeg
#!/usr/bin/env python3
import argparse
import io
import os.path
import re
import subprocess
import tempfile
def merge_videos(inputs, output):
@bsidhom
bsidhom / clip.sh
Created October 10, 2019 21:54
Copy file (with mime-type) to clipboard. Useful for copying images to clipboard from the command line.
#!/usr/bin/env bash
set -euo pipefail
function main() {
if [[ "$#" != 1 ]] ; then
printf "usage: %s <input file>\n" "$0" >&2
return 2
fi
local file="$1"
@bsidhom
bsidhom / ffcat.sh
Created September 12, 2020 05:28
Concatenate MP4 files and inject 360 metadata. Similar to concat-mp4.py, but depends on https://github.com/google/spatial-media
#!/usr/bin/env bash
# Usage: ffcat <output> <input> [input ...]
set -euo pipefail
# Prints the contents of a concat file for ffmpeg.
function catfile() {
local inputs=($@)
local input