m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xarticle2pdf28
-rwxr-xr-xch30
-rwxr-xr-xmpvl22
-rwxr-xr-xmscz2pdfs36
-rwxr-xr-xnote76
-rwxr-xr-xthink24
-rwxr-xr-xwacom55
-rwxr-xr-xyt-dl-choose36
8 files changed, 307 insertions, 0 deletions
diff --git a/article2pdf b/article2pdf
new file mode 100755
index 0000000..4259ee4
--- /dev/null
+++ b/article2pdf
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Downloads an article from the web and converts it to PDF with pandoc.
+# USAGE: article2pdf <url>
+
+pdfs_dir=~/Downloads/articles
+
+html_file=`mktemp`
+
+# Some sites ban curl, so use "firefox" user agent
+user_agent='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0'
+curl --user-agent "$user_agent" --location --silent "$1" > "$html_file"
+
+pdf_file=$pdfs_dir/`pup --file "$html_file" 'title text{}' \
+ | grep -v '^\s*$' \
+ | head -n 1 \
+ | sed -e 's/^ *//' -e 's/ *$//' -e 's/ /-/g'`.pdf
+
+
+if pandoc --request-header User-Agent:"$user_agent" "$1" --pdf-engine=xelatex -o "$pdf_file"; then
+ exit 0
+else
+ # we may have failed due to unconvertable images (e.g. webp)
+ # in that case try rebuilding without images
+ pandoc "$html_file" -f html --pdf-engine=xelatex -o "$pdf_file"
+fi
+
+rm "$html_file"
diff --git a/ch b/ch
new file mode 100755
index 0000000..e989716
--- /dev/null
+++ b/ch
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Helper script for my cheatsheets system.
+# USAGE: ch
+# This will open a fzf menu over the `~/cheatsheets` directory.
+# You can select one of the files there, or use the special command `new` which
+# creates a new file (you will be prompted for a title, which should not include
+# the .md extension).
+# NOTE: Currently hardcodes cheatsheets directory to `~/cheatsheets`.
+
+prefix=~/cheatsheets/
+suffix=.md
+sheets=("$prefix"*"$suffix")
+sheets=("${sheets[@]#"$prefix"}")
+sheets=("${sheets[@]%"$suffix"}")
+sheets=("${sheets[@]}" new)
+
+sheet=$(printf '%s\n' "${sheets[@]}" | fzf)
+
+if [[ "$sheet" == "new" ]]; then
+ echo -n "enter new cheatsheet name: "
+ read new_sheet
+ file="${prefix}${new_sheet}${suffix}"
+ $VISUAL $file
+ exit 0
+fi
+
+file="${prefix}${sheet}${suffix}"
+
+[[ -f $file ]] && $VISUAL $file
diff --git a/mpvl b/mpvl
new file mode 100755
index 0000000..184dafd
--- /dev/null
+++ b/mpvl
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Starts a media file in mpv looped.
+# USAGE: mpvl [<start> <stop>] <file>
+# If only `file` given, loops the whole file.
+# If `start` and `stop` given, loops the section between those timecodes.
+
+FLAGS=
+FILE=
+
+if [ "$#" -eq 3 ]; then
+ FLAGS="--start=$1 --ab-loop-a=$1 --ab-loop-b=$2"
+ FILE=$3
+elif [ "$#" -eq 1 ]; then
+ FLAGS=--loop
+ FILE=$1
+else
+ echo "USAGE: mpvl [<start> <stop>] <file>";
+ exit 1;
+fi
+
+mpv $FLAGS "$FILE"
diff --git a/mscz2pdfs b/mscz2pdfs
new file mode 100755
index 0000000..e037086
--- /dev/null
+++ b/mscz2pdfs
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Converts a MuseScore file to PDFs, one for each part.
+# USAGE: mscz2pdfs -s <score file> -o <output directory>
+
+score=
+output_dir='.'
+
+while getopts 's:o:' flag; do
+ case "${flag}" in
+ s) score=$OPTARG ;;
+ o) output_dir=$OPTARG ;;
+ *) error "Unexpected option ${flag}" ;;
+ esac
+done
+
+if [ -z "$score" ]; then
+ echo "Provide score"
+fi
+
+base_filename=${score%.mscz}
+base_filename=${score##*/}
+json=`mktemp "/tmp/tmp-XXXXXXX.json"`
+echo "putting json in $json"
+
+musescore --score-parts-pdf "$score" > "$json"
+
+parts=`jq --raw-output '.parts[]' "$json"`
+
+i=0
+IFS=$'\n';
+for part in $parts; do
+ jq --raw-output ".partsBin[$i]" "$json" | base64 --decode > "$output_dir"/"$base_filename-$part.pdf"
+ i=$((i + 1))
+done
+IFS=' '
diff --git a/note b/note
new file mode 100755
index 0000000..132ca20
--- /dev/null
+++ b/note
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Helper script for managing a [GitJournal](https://gitjournal.io/) notes
+# directory on a computer.
+# USAGE: note
+# You can select one of the files there, or use the special command `new` which
+# creates a new file (you will be prompted for a title, which should not include
+# the .md extension).
+# Executes a `git pull` before showing file list, commits changes and pushes
+# after the file is exited.
+# NOTE: Currently hardcodes notes directory to `~/gitjournal`.
+# TODO: skip git operations if there is no network connection.
+
+set -euo pipefail
+
+directory=$HOME/gitjournal/
+
+git -C "$directory" pull || true
+
+suffix=.md
+readarray -t notes < <( \
+ find "$directory" -iname "*$suffix" -printf "%T@\t%p\n" | \
+ sort --reverse --numeric-sort | \
+ awk -F "\t" '// { print $2 }' \
+)
+notes=("${notes[@]#"$directory"}")
+notes=("${notes[@]%"$suffix"}")
+notes+=(new journal)
+note=$(printf '%s\n' "${notes[@]}" | fzf)
+
+if [[ "$note" == "new" ]]; then
+ echo -n "enter new note directory/title: "
+ read new_title
+ file="${directory}${new_title}${suffix}"
+ [[ -f "$file" ]] && echo "Note at $file already exists!" && exit 1
+ date=`date --iso-8601=seconds`
+ cat << EOF >> "$file"
+---
+created: $date
+modified: $date
+---
+
+# ${new_title##*/}
+EOF
+ commit_message="Created $new_title"
+elif [[ "$note" == "journal" ]]; then
+ new_title=`date +%Y-%m-%d`
+ long_date=`date +"%B %d, %Y"`
+ file="${directory}Journal/${new_title}${suffix}"
+ [[ -f "$file" ]] && echo "Journal entry for $new_title already exists!" && exit 1
+ date=`date --iso-8601=seconds`
+ cat << EOF >> "$file"
+---
+created: $date
+modified: $date
+---
+
+# ${long_date}
+EOF
+ commit_message="Created $long_date journal entry"
+else
+ file="${directory}${note}${suffix}"
+ commit_message="Modified $note"
+fi
+
+[[ -f "$file" ]] && $VISUAL "$file"
+
+git -C "$directory" add -N "$file"
+git -C "$directory" add -p "$file"
+git -C "$directory" commit -m "$commit_message"
+git -C "$directory" status
+echo -n "push changes? [y/N] "
+read push
+if [[ "$push" == "y" ]]; then
+ git -C "$directory" push
+fi
diff --git a/think b/think
new file mode 100755
index 0000000..63e258a
--- /dev/null
+++ b/think
@@ -0,0 +1,24 @@
+#!/bin/env ruby
+
+require "date"
+
+THOUGHTS_DIR = "vultr:/srv/thoughts"
+
+today = Date::today
+
+# .wday returns 0 for Sunday.
+# If today is Sunday, we want to put today's thoughts in next Sunday's file so
+# today's Sunday Corner doesn't change mid-day.
+days_till_next_sunday = 7 - today.wday
+
+next_sunday = today + days_till_next_sunday
+
+remote_file = "#{THOUGHTS_DIR}/#{next_sunday}"
+local_file = "/tmp/sunday-thoughts-#{next_sunday}"
+
+system "touch #{local_file}"
+system "scp #{remote_file} #{local_file}"
+system "$VISUAL #{local_file}"
+# Note that if this scp fails and you rerun the script, the first scp above (if
+# it succeeds) will overwrite your current local file.
+system "scp #{local_file} #{remote_file}"
diff --git a/wacom b/wacom
new file mode 100755
index 0000000..3c7fa96
--- /dev/null
+++ b/wacom
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# Helper script for setting up a wacom tablet.
+# USAGE: wacom [-r] [-c <config>]
+# FLAGS:
+# -r: rotate the board's input 180°, useful if using the board upside down to
+# its assumed usage orientation.
+# -c: uses one of the hardcoded configurations for stylus button bindings.
+# NOTE:
+# The configs are currently hardcoded for my personal preferences in several
+# programs/websites for the One by Wacom tablet.
+# CONFIGS:
+# aww: (obsolete) for the AWW shared whiteboard.
+# krita: the Krita drawing program.
+# miro: for the Miro shared whiteboard.
+
+ID=`xsetwacom list devices | awk '/stylus/ { print $8 }'`
+
+function rotate {
+ xsetwacom set $ID Rotate half
+}
+
+# AWW board, eraser + pencil
+function set_aww {
+ xsetwacom set $ID Button 2 "key e"
+ xsetwacom set $ID Button 3 "key p"
+}
+
+# Krita - right click (tags wheel), middle click (pan)
+function set_krita {
+ xsetwacom set $ID Button 2 "button +2"
+ xsetwacom set $ID Button 3 "button 3"
+}
+
+function set_miro {
+ xsetwacom set $ID Button 2 "key v"
+ xsetwacom set $ID Button 3 "key p"
+}
+
+function set_config {
+ case "$1" in
+ aww) set_aww ;;
+ krita) set_krita ;;
+ miro) set_miro ;;
+ *) echo "Unexpected config \"$1\""; exit 1 ;;
+ esac
+}
+
+while getopts 'rc:' flag; do
+ case "${flag}" in
+ r) rotate ;;
+ c) set_config $OPTARG ;;
+ *) error "Unexpected option ${flag}" ;;
+ esac
+done
diff --git a/yt-dl-choose b/yt-dl-choose
new file mode 100755
index 0000000..7d33588
--- /dev/null
+++ b/yt-dl-choose
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Wrapper for mpv playing an internet video with yt-dlp that lets you select the
+# video format to download. Useful when launching e.g. YouTube videos, which
+# often have a very high resolution default format that would buffer a lot.
+# USAGE: yt-dl-choose <url>
+# Opens a dmenu menu with available audio+video formats.
+# NOTE: only displays formats that have both audio and video, which have limited
+# quality. For highest resolution, we'd also need to provide options for
+# combined formats with separate audio and video streams.
+# NOTE: when given a video in a YouTube playlist, will only play that video.
+
+NO_PLAYLIST=1
+
+if [[ $# -ne 1 ]]; then
+ echo "USAGE: yt-dl-choose <url>"
+fi
+
+URL="$1"
+
+if [[ $NO_PLAYLIST ]]; then
+ URL=`echo "$URL" | sed -e 's/&list=.*&/\&/'`
+fi
+
+formats=`yt-dlp --list-formats $URL \
+ | grep -v "audio only" \
+ | grep -v "video only" \
+ | grep -v mhtml \
+ | sed '0,/---------/d' `
+format=`echo "$formats" | dmenu | cut -d' ' -f1`
+
+if [ -z "$format" ]; then
+ exit 0;
+fi
+
+mpv --ytdl-format=$format $1