Skip to content

Instantly share code, notes, and snippets.

@josuecau
josuecau / seedbox
Last active March 17, 2019 12:16
Select .torrent file to upload to seed box
#!/usr/bin/env bash
#
# Description: Select .torrent file to upload to seed box.
# Usage: $ seedbox
# Author: Josué CAU <me@josuecau.com>
# Version: v0.1.1
# Dependencies: fzf(1)
# Env: SEEDBOX_ADDRESS
set -e
@josuecau
josuecau / gist:b493d0b7729c6744ccef28a8e5ca2c0c
Created March 2, 2019 10:46
MusicBrainz Picard File Naming
$if2(%albumartist%,%artist%)/$if($ne(%albumartist%,),%album%/,)$if($gt(%totaldiscs%,1),%discnumber%/,)$if($ne(%albumartist%,),$num(%tracknumber%,2) ,)%title%
@josuecau
josuecau / h265toh264.sh
Last active February 24, 2019 12:17
Convert H.265 (HEVC) to H.264 (MPEG-4 AVC)
#!/usr/bin/env bash
#
# Description: Convert H.265 (HEVC) to H.264 (MPEG-4 AVC)
# Author: Josué Cau <me@josuecau.com>
# Date: 2018-02-16
# Dependencies: ffmpeg(1)
set -e
if [ "$#" -ne 3 ]; then
@josuecau
josuecau / flac2mp3.sh
Last active February 2, 2019 12:50
Convert FLAC to MP3 using ffmpeg(1)
#!/usr/bin/env bash
#
# Convert FLAC to MP3 using ffmpeg(1)
# Source: https://stackoverflow.com/a/26109838/2397516
set -e
if [ $# -lt 1 ]; then
echo "Usage: $(basename "$0") /files/to/convert"
exit 1
@josuecau
josuecau / recursive-search-replace-osx.sh
Last active October 8, 2018 20:10
Recursive search & replace on Mac OS X
# search & replace with backup
find . -name "*.php" -print | xargs sed -i.bak 's/foo/bar/g'
# delete backup files
find . -name '*.bak' | xargs rm
# Seoul oh-my-zsh theme
# Theme with username, hostname, relative path and git branch
# Inspired by Maran theme and Seoul256 color scheme
PROMPT='%F{173}%n%{$reset_color%}%F{252}@%{$reset_color%}%F{179}%M%{$reset_color%}%F{252}:%{$reset_color%}%F{116}%~%{$reset_color%}$(git_prompt_info) %F{252}%(!.#.$)%{$reset_color%} '
ZSH_THEME_GIT_PROMPT_PREFIX="%F{252}:%{$reset_color%}%F{108}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="*"
ZSH_THEME_GIT_PROMPT_CLEAN=""
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
@josuecau
josuecau / json2csv
Last active May 26, 2018 09:27
Convert JSON to CSV using jq(1)
#!/usr/bin/env bash
#
# Convert JSON to CSV using jq(1)
# Source: https://stackoverflow.com/a/32967407
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv' $input
@josuecau
josuecau / certbot
Created May 19, 2018 08:25
Certbot with Docker and Cloudflare DNS Authenticator plugin
#!/usr/bin/env bash
#
# Certbot with Docker and Cloudflare DNS Authenticator plugin
# https://certbot.eff.org
# https://github.com/certbot/certbot/tree/master/certbot-dns-cloudflare
docker run -it --rm --name certbot \
-v '/etc/letsencrypt:/etc/letsencrypt' \
-v '/etc/cloudflare.conf:/etc/cloudflare.conf' \
-v '/var/lib/letsencrypt:/var/lib/letsencrypt' \
#!/usr/bin/env bash
input="${1:-/dev/stdin}"
awk '{s+=$1} END {print s}' "$input"