Skip to content

Instantly share code, notes, and snippets.

View tralston's full-sized avatar

Taylor Ralston tralston

  • Sacramento, CA
  • 13:22 (UTC -07:00)
View GitHub Profile
@tralston
tralston / print-history.js
Created November 8, 2021 20:24
[Print Basecamp Chat History based on dates]
// In Chrome Dev-Tools, run the following commands, substituting the date for the earliest cutoff you want
earliest = new Date("2021-10-22T08:00:00Z"); // T08:00:00Z Means Midnight Pacific Time when CA is on UTC-800
bc = $("bc-grouped-dates"); bc.children().filter( (i, el) => new Date($(el).data("datetime")) < earliest).remove(); bccr = $("bc-chat-room"); bccr.css("overflow", "visible"); bcip = $("bc-infinite-page"); bcip.css("overflow", "visible")
@tralston
tralston / command_choices.sh
Created March 29, 2019 07:19
Choose among multiple similar commands in bash script
#!/bin/bash
# If the functionality of a GNU command (vs BSD) is needed, instead of checking for $OSTYPE, check if command is installed.
# This method isn't perfect, because you could have the case where the preferred command isn't installed when you expect it to be
# (e.g. Mac has no gdate installed). Perhaps in combination with $OSTYPE for better coverage.
# This checks if gdate is installed (likely beacuse running in a Mac environment). If not, use the normal date command.
DATE=$(type -p gdate date | head -n 1)
# Execute the command
@tralston
tralston / dupes.sql
Created December 19, 2018 20:09
Finding Which dupes have at least one on each source, then showing the paths for all the dupes that qualify
SELECT * from files
WHERE hash IN (
SELECT hash --, COUNT(source)
FROM
(SELECT *, COUNT(source) FROM files
GROUP BY hash, source) AS A
GROUP BY hash
HAVING COUNT(source) > 1)
@tralston
tralston / functions_unit_types.nb
Created May 19, 2018 00:12
[Constrain functions to specific unit types] #mathematica
f[x_]:=x
f[5] ==> 5
f[x: Quantity[_, unit_]?(CompatibleUnitQ[#, "feet"] &)]:=x (* Important that parameters in list do not have underscore *)
f[5] ==> f[5]
f[Quantity[5, "feet"]] ==> 5 ft
f[Quantity[5, "meters"]] ==> 5 m
f[Quantity[5, "pound"]] ==> f[5 lb]
@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]
@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 / 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 / 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 / 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 / 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