Skip to content

Instantly share code, notes, and snippets.

View ttscoff's full-sized avatar
💭
Breathing

Brett Terpstra ttscoff

💭
Breathing
View GitHub Profile
@ttscoff
ttscoff / bookmarker
Last active February 24, 2025 10:35 — forked from rhsev/bookmarker
(This script has moved to <https://github.com/ttscoff/bookmarker>) This script acts as a wrapper for Brett Terpstra's [bookmark-cli](https://github.com/ttscoff/bookmark-cli). It shortens long bookmark IDs to 9-digit numbers and stores the mappings in a JSON file. The short ID is also added to the file’s Spotlight metadata. This ensures manageabl…
#!/usr/bin/env ruby
require "json"
require "securerandom"
require "optparse"
# This script has been moved to https://github.com/ttscoff/bookmarker
# Created by Ralf Hulsmann
#
# A wrapper around
@ttscoff
ttscoff / README.md
Last active March 3, 2025 09:10
Save Readwise highlights to DEVONthink

Readwise to DEVONthink

This script has moved to its own repository. Please download there.

@ttscoff
ttscoff / README.md
Last active January 31, 2025 12:23
A background script to archive linkding bookmarks to DEVONthink

Archive linkding bookmarks to DEVONthink

This script will archive bookmarks from a linkding server to DEVONthink.

This script is designed to run once initially, and then be set to run in the background at intervals using cron or launchd.

You can specify a certain tag to only archive bookmarks containing that tag. This is useful because if you're just linking a tool or interesting app, you probably don't need an archive of it. Tagging allows selective and intentional archiving. But if you leave it blank, the script will just archive all bookmarks.

You can also specify tags for different types of archives, including webloc, webarchive, and pdf.

@ttscoff
ttscoff / linkding_webarchive.rb
Last active January 13, 2025 18:54
Linkding to Markdown archiving script with webarchive generation
#!/usr/bin/env ruby
# Archive linkding bookmarks to Markdown files
# Can use [Gather](https://brettterpstra.com/projects/gather-cli/)
# for conversion (if installed), or use Marky
# the Markdownifier (web-based).
#
# See options below for configuration
#
# This script is designed to run once initially, and then
# be set to run in the background at intervals using cron
@ttscoff
ttscoff / pullremote.sh
Last active February 3, 2025 19:53
remote git pull script
#!/bin/bash
# Remote host is the first argument
HOST=$1
# Remote directory is a mirror of the local directory
DIR=$(pwd)
# SSH to the host and run the pull script
ssh $HOST "~/scripts/remotepull.sh '$DIR'"
# Sync Build notes not stored in git
@ttscoff
ttscoff / strip_emoji.swift
Created January 4, 2025 16:39
Strip all emoji, including new Apple emoji. Please comment to add edge cases.
import Foundation
extension String {
private static let emojiPattern =
"[\u{fe0f}\u{00A9}\u{00AE}\u{203C}\u{200d}\u{2049}\u{2122}\u{2139}\u{2194}-\u{2199}\u{21A9}-\u{21AA}\u{231A}-\u{231B}\u{2328}\u{23CF}\u{23E9}-\u{23F3}\u{23F8}-\u{23FA}\u{24C2}\u{25AA}-\u{25AB}\u{25B6}\u{25C0}\u{25FB}-\u{25FE}\u{2600}-\u{2604}\u{260E}\u{2611}\u{2614}-\u{2615}\u{2618}\u{261D}\u{2620}\u{2622}-\u{2623}\u{2626}\u{262A}\u{262E}-\u{262F}\u{2638}-\u{263A}\u{2642}-\u{2653}\u{2660}\u{2663}\u{2665}-\u{2666}\u{2668}\u{267B}\u{267F}\u{2692}-\u{2694}\u{2696}-\u{2697}\u{2699}\u{269B}-\u{269C}\u{26A0}-\u{26A1}\u{26AA}-\u{26AB}\u{26B0}-\u{26B1}\u{26BD}-\u{26BE}\u{26C4}-\u{26C5}\u{26C8}\u{26CE}-\u{26CF}\u{26D1}\u{26D3}-\u{26D4}\u{26E9}-\u{26EA}\u{26F0}-\u{26F5}\u{26F7}-\u{26FA}\u{26FD}\u{2702}\u{2705}\u{2708}-\u{270D}\u{270F}\u{2712}\u{2714}\u{2716}\u{271D}\u{2721}\u{2728}\u{2733}-\u{2734}\u{2742}\u{2744}\u{2747}\u{274C}\u{274E}\u{2753}-\u{2755}\u{2757}\u{2763}-\u{2764}\u{2795}-\u{2797}\u{27A1}\u{27B0}\u{27BF}\u{2934}-\u{2935}\
@ttscoff
ttscoff / strip_emoji.rb
Last active January 4, 2025 16:44
Ruby method to strip emoji, including new Apple emoji
#!/usr/bin/env ruby
# Remove all emoji from a string, including Apple's new overqualified emoji.
#
# Hat tip to mathiasbynens
# <https://github.com/mathiasbynens/emoji-test-regex-pattern/blob/main/script/get-sequences.js>
# String extension for emoji stripping
class ::String
EMOJI_RX = /[\u{fe0f}\u{00A9}\u{00AE}\u{203C}\u{200d}\u{2049}\u{2122}\u{2139}\u{2194}-\u{2199}\u{21A9}-\u{21AA}\u{231A}-\u{231B}\u{2328}\u{23CF}\u{23E9}-\u{23F3}\u{23F8}-\u{23FA}\u{24C2}\u{25AA}-\u{25AB}\u{25B6}\u{25C0}\u{25FB}-\u{25FE}\u{2600}-\u{2604}\u{260E}\u{2611}\u{2614}-\u{2615}\u{2618}\u{261D}\u{2620}\u{2622}-\u{2623}\u{2626}\u{262A}\u{262E}-\u{262F}\u{2638}-\u{263A}\u{2642}-\u{2653}\u{2660}\u{2663}\u{2665}-\u{2666}\u{2668}\u{267B}\u{267F}\u{2692}-\u{2694}\u{2696}-\u{2697}\u{2699}\u{269B}-\u{269C}\u{26A0}-\u{26A1}\u{26AA}-\u{26AB}\u{26B0}-\u{26B1}\u{26BD}-\u{26BE}\u{26C4}-\u{26C5}\u{26C8}\u{26CE}-\u{26CF}\u{26D1}\u{26D3}-\u{26D4}\u{26E9}-\u{26EA}\u{26F0}-\u{26F5}\u{26F7}-\u{26FA}\u{26FD}\u{2702}\u{2705}\u{2708}-\u{270D}\u{270F}
@ttscoff
ttscoff / beengone-more-examples.bash
Last active January 8, 2025 21:46
Some more examples of beengone in scripting
#!/bin/bash
# Example script to test the beengone command
# Loops while checking idle time with a minimum threshold before executin a command
# Works while screen saver is running
open /System/Library/CoreServices/ScreenSaverEngine.app
while true; do
beengone -m 3s
if [[ $? -eq 0 ]]; then
@ttscoff
ttscoff / idletil.fish
Last active January 8, 2025 21:46
A fish function to test for minimum idle time (using beengone) before executing a command.
function idletil --description 'Wait until system idle time has reached X seconds and optionally execute command'
argparse 'h/help' 'c/command=+' -- $argv
or return
if set -q _flag_help
echo "Usage: idletil SECONDS [-c \"command to execute\"]"
echo "SECONDS may be represented as XdXhXmXs or any combination"
return 0
end
@ttscoff
ttscoff / ifgone
Last active January 8, 2025 21:46
A bash script that uses beengone to test for a minimum idle time before executing a command.
#! /bin/bash
gone() {
if [[ -n $1 ]]; then
TIME=$1
# loop indefinitely
# > could also use --wait flag to wait for the user to be
# > gone instead of looping
while true; do
# use the --minimum flag to generate an exit code