Skip to content

Instantly share code, notes, and snippets.

View tralston's full-sized avatar

Taylor Ralston tralston

  • Sacramento, CA
  • 07:05 (UTC -07:00)
View GitHub Profile
@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 / 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 / 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 / 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")