Skip to content

Instantly share code, notes, and snippets.

View tralston's full-sized avatar

Taylor Ralston tralston

  • Sacramento, CA
  • 23:55 (UTC -07:00)
View GitHub Profile
@tralston
tralston / clean_time_machine.sh
Last active January 2, 2018 18:57
[Time Machine Clean Up]
# Prerequisites
# - the `hln` command, which on mac can be installed via `brew install hardlink-osx`
# - various time machine cleaning scripts: tmdejunk, tmdeempty, tmdeduphl, tmdeduphldir
# In the time machine volume, under Backups.backupdb/<Machine Name>
# Note: this only prunes the hardlinks in the /Users/ folder of each backup snapshot.
# The following code will find the /Users folder within each snapshot, and then run the tmdejunk command, followed by tmclean command. It will prune empty folders, prune hardlink folders, then delete hardlink files, then prune empty folders again. This process can take several hours depending on how many snapshots you have backed up
@tralston
tralston / 7zip.sh
Last active April 24, 2018 20:49
[7zip CLI] Ultra high compression for 7zip on commandline #bash
# This will compress the entire pwd, dot files included. Archive placed in pwd
sudo 7z a -t7z [FILENAME.7z] -m0=lzma2 -mx=9 -aoa .
# No compression, just copy. Also, splits into 900MB parts for easier transfer over internet
7z a -t7z -mx=0 -v900m [FILENAME.7z] [files...]
# Same as previous, but encrypt headers (file names, and password protected
7z a -t7z -mx=0 -mhe=on -p -v900m [FILENAME.7z] [files...]
@tralston
tralston / install_net3.bat
Created April 10, 2018 03:56
[Install .NET 3/3.5 Framework on Windows 8, 8.1 and 10] Check status of and install .NET 3.5 Framework on later versions of Windows that have removed it.
rem Check if it is installed to begin with.
DISM /Online /Get-Features /Format:Table | findstr -i netfx3
rem Install .NET 3(.5)
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:D:\sources\sxs
@tralston
tralston / rsync.sh
Created April 10, 2018 08:08
[Rsync over SSH with Paths with Spaces]
# the -s argument protects what's inside the quotation marks. This is crucial when there are spaces in the path
rsync -avP -s --rsync-path=/bin/rsync ~e/Videos/Videos/2013/h265/* "superman@homenas:/volume1/PlexMedia/Home Videos/"
@tralston
tralston / restore.sh
Last active September 14, 2022 12:26
[Change video/photo timestamp to date recorded or taken]
# For mp4, the recorded date can exist as Recorded date or Tagged date. If you want to do this for all the files in a folder, use the following command:
for file in *.mp4; do touch -t "$(mediainfo "$file" | grep --color=never -iEm 1 '(Recorded date|Tagged date)' | sed -r 's/.*([0-9]{4})-([0-9]{2})-([0-9]{2})[T ]([0-9]{2}):([0-9]{2}):([0-9]{2}).*/\1\2\3\4\5.\6/')" "$file"; done
# Some videos will not have that date in the metadata, so you'll have to correct it yourself
touch -t CCYYMMDDHHMM[.ss] file.ext
@tralston
tralston / fixit.sh
Last active April 11, 2018 00:31
[Fix HEVC fourcc code to be able to play h265 videos on AppleTV from Plex]
# Note this only works on newer versions of ffmpeg (3.4.2+)
ffmpeg -i file.mp4 -codec copy -vtag hvc1 -map 0:0 -map 0:1 file.mp4
# see what codec id (fourcc code) your video has
mediainfo "file.ext" | grep -im 2 'codec id' | tail -n1
# or a list of files
for file in *.mp4; do echo "$file" "$(mediainfo "$file" | grep -im 2 'codec id' | tail -n1)"; done
# Fix the fourcc code hev1 -> hvc1. Note: this will overwrite the timestamp, so make sure to save it or restore it
# Added _fixed suffix as to not overwrite original in case it doesn't work
@tralston
tralston / find_magic.sh
Created April 12, 2018 02:40
[Find files based on return value of function]
# Will find files based on if the magic file type 'file $file.ext' matches pattern, then print the filename
# e.g. look for sqlite dbs
find . -type f -exec sh -c 'case "$(file -b "$0")" in *"SQLite"*) true;; *) false;; esac' {} \; -print
@tralston
tralston / diffy.sh
Created April 19, 2018 23:23
[Color Diff by Word Output of Two Commands] #diff #color
# Compare mediainfo output for two files. This requires dwdiff (or cwdiff)
dwdiff -c <(mediainfo file1.mp4) <(mediainfo file2.mp4)
# Last command has a custom script I wrote, diffmedia, as follows:
diffmedia file1.mp4 file2.mp4
@tralston
tralston / query.sql
Created May 4, 2018 03:23
Find folders recursively from parent folder in PhotoSweeper X #sql #sqlite
-- PhotoSweeper X database (sqlite3) is located in:
-- ~/Library/Containers/com.overmacs.photosweeperpaddle/Data/Library/Application Support/PhotoSweeper X/Library.pslib
-- First query gives all folderids that are subfolders of folderid 351
CREATE TABLE folders WITH RECURSIVE folds(x) AS (VALUES(351) UNION SELECT folderID FROM PSFolder, folds WHERE PSFolder.parentFolderID=folds.x) SELECT * FROM folds ORDER BY x;
-- If you're curious how many files are in this folder structure, run this
SELECT count(*) FROM PSFile WHERE parentFolderID IN folders;
@tralston
tralston / get-source.sh
Created May 7, 2018 16:41
Find apt package source for installed/available package #bash #apt
# This helps if you have several sources for a package, and are not sure which one is installed or available
# For instance, if a pacakge is available on ubuntu main and a ppa both.
apt-cache policy [pkg-name]