Skip to content

Instantly share code, notes, and snippets.

View jovandeginste's full-sized avatar

Jo Vandeginste jovandeginste

View GitHub Profile
package main
import (
"archive/tar"
"compress/gzip"
"io"
"os"
"path/filepath"
)
@jovandeginste
jovandeginste / convert-rotated-video.sh
Created November 23, 2021 21:06
Convert a rotated video recording (recorded in portrait mode, but plays in landscape mode) to landscape video with the same video blurred as backdrop
#!/bin/bash -eu
INPUT="input.mp4"
OUTPUT="output.mp4"
W=1920
H=1080
OVERLAY_W=1080 # Increase this to remove the bottom part of the portrait recording
OVERLAY_X=$(
echo "(${W} - (${H} * ${OVERLAY_W} / ${W})) / 2" | bc
)
@jovandeginste
jovandeginste / scan
Created January 5, 2021 11:20
Scan and/or convert
#!/bin/bash -eu
: ${SCANNER:="brother4:bus9;dev1"} # My USB scanner
: ${OCR_LANG:=nld} # Tesseract language
: ${SCAN_DPI:=300} # A good resolution for OCR
: ${FINAL_RES:=1240x} # A good resolution for PDF
: ${SHOW:=0} # Show the result
: ${NICE:=10} # Priority of this process - this prevents Tesseract from hogging your machine
: ${UNPAPER:=1} # Whether to run unpaper
: ${FILENAME:=AUTO} # If no FILENAME is set, or set to 'AUTO': make one up based on time
@jovandeginste
jovandeginste / scandoc
Last active December 31, 2020 11:55
Scan single or multi-page document, post-process it and convert to OCR'ed PDF
#!/bin/bash -eu
# Usage: scandoc [expected number of pages]
# Eg:
# scandoc 1 # Scan one page, then process
# scandoc 5 # Scan 5 pages, then process
# scandoc # Scan until page 99 or other action triggers end
#
# Description:
# Scandoc interactively scans a number (1 or more) of pages, runs
#!/bin/bash -eu
COVERFILE=$(mktemp "coverXXX.out")
trap "{ rm -vf $COVERFILE; }" EXIT
DIR=${1:-./...}
case "${FULL:-no}" in
y*)
: ${REV:=}
: ${P:=--color=always}
;;
@jovandeginste
jovandeginste / switch-wifi
Created May 1, 2020 09:17
Simple script to switch to best WiFi signal if current signal falls below threshold (using nmcli)
#!/bin/bash -eu
# We don't need to switch if current signal has at least this this strength:
GOOD_ENOUGH=50
# Signal to switch to, must at least have this strength:
BETTER=60
# We use 'autoconnect' here, to later filter SSID's explicitly not
# configured as 'autoconnect'.
KNOWN_SSIDS=$(nmcli -g name,type,autoconnect connection show)
@jovandeginste
jovandeginste / merge.go
Created June 7, 2019 14:32
Code to merge striped files into the "actual" file
package main
import (
"fmt"
"os"
"strconv"
"syscall"
"time"
"github.com/dustin/go-humanize"
@jovandeginste
jovandeginste / portforward.go
Last active October 1, 2018 16:00
Simple port forwarder
package main
import (
"io"
"log"
"net"
"os"
)
func main() {
@jovandeginste
jovandeginste / build.sh
Created June 7, 2018 11:55
Build shibboleth from sources
#!/bin/bash
set -e
yum -y install boost-devel zlib-devel openssl-devel libcurl-devel xml-security-c-devel gcc gcc-c++ make file wget httpd-devel unzip tar sed grep patch
(
if ! test -d log4shib-1.0.9; then
wget -c https://shibboleth.net/downloads/log4shib/latest/log4shib-1.0.9.tar.gz -O log4shib-1.0.9.tar.gz
tar xfz log4shib-1.0.9.tar.gz
fi
@jovandeginste
jovandeginste / tstomp4
Last active November 23, 2016 12:45
converts a playlist.m3u8 webstream (containing chunks) to an mp4
#!/bin/bash -eu
url="$1"
output="$2"
base=$(dirname "$url")
chunklist=$(curl -s "$url" | grep "^chunklist")
if [[ -f "$output" ]]
then