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 / bitly.rb
Created December 24, 2023 21:10
Bitlyize script for use in Bitlyize Services
#!/usr/bin/env ruby
require 'json'
require 'yaml'
# Settings is a YAML file containing `:token:` and `:domain:` keys.
settings = YAML.load(IO.read(File.expand_path('~/.config/bitly/config.yaml')))
bitly_key = settings[:token]
bitly_domain = settings[:domain]
debug = false
@ttscoff
ttscoff / grabicon.rb
Last active January 20, 2024 14:57
Grab an iOS or Mac app icon from local version or iTunes search
#!/usr/bin/env ruby -W1
# frozen_string_literal: true
# Mac only
#
# Usage: grabicon.rb SEARCH TERMS [%[small|medium|large] [@[mac|ios|iphone|ipad]]
# If the search terms match a local app, that app's icon will be extracted and converted to PNG
# If the search terms don't match a local app, iTunes will be searched
# If the search terms end with "@mac", "@iphone", "@ipad", or "@ios", iTunes will be searched for a match
# If the search terms end with "%large", "%medium", "%small", or "%XXX" icon will be scaled to size
@ttscoff
ttscoff / grabicon.rb
Last active October 22, 2023 18:10
Retrieve and process an icon for a local or App Store app
#!/usr/bin/env ruby -W1
# frozen_string_literal: true
# Mac only
#
# Usage: grabicon.rb SEARCH TERMS [%[small|medium|large] [@[mac|ios|iphone|ipad]]
# If the search terms match a local app, that app's icon will be extracted and converted to PNG
# If the search terms don't match a local app, iTunes will be searched
# If the search terms end with "mac", "iphone", "ipad", or "ios", iTunes will be searched for a match
#
@ttscoff
ttscoff / bear_preprocessor.rb
Last active October 13, 2023 14:37
Marked Preprocessor for Bear
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'cgi'
input = $stdin.read.force_encoding('utf-8')
# Handle [[links]]
input.gsub!(/\[\[(?<content>.*?)\]\]/) do
m = Regexp.last_match
@ttscoff
ttscoff / toot.rb
Last active April 28, 2023 04:58
Scans RSS feed for latest post and creates Mastodon toot
#!/usr/bin/env ruby -W1
# frozen_string_literal: true
# This script scans an RSS feed for the latest post, and if
# it hasn't already been posted to Mastodon, creates a new
# toot with a link to it.
require 'json'
require 'optparse'
require 'rss'
@ttscoff
ttscoff / md_to_bike.rb
Last active March 22, 2024 18:42
This script takes simple Markdown lists and converts them for use in Bike
#!/usr/bin/env ruby
# frozen_string_literal: true
# This script takes simple Markdown lists and converts them for use in
# Bike (https://www.hogbaysoftware.com/bike/), a Mac outliner app from
# Hog Bay Software.
#
# It doesn't handle nested code blocks or any non-list Markdown. It just
# turns simple lists into text Bike will recognize when it's pasted into
# a Bike document. Multiple paragraphs in a list item become additional
@ttscoff
ttscoff / lexers.rb
Last active June 6, 2023 21:54
Find the perfect lexer to highlight your fenced code blocks and other fancy stuff. If you know the common name of a language or a common file extension for it, this script will tell you exactly what most syntax highlighters will recoghize.
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
# Have you ever been adding code to a Markdown post and
# wondered what syntax label would give you the right
# highlighting for your fenced code block? This script can
# take either a file extension or a common name of a language
# and let you know what lexers are supported for it, as well
@ttscoff
ttscoff / hugo_youtube_textexpander.js
Created February 22, 2023 19:03
TextExpander JavaScript for generating Hugo youtube tag with a YouTube url in clipboard
var url = TextExpander.pasteboardText;
var youtubeRx = /(?:youtu\.be\/|youtube\.com\/watch\?v=)([a-z0-9_\-]+)$/i
if (youtubeRx.test(url)) {
var id = youtubeRx.exec(url)[1];
TextExpander.appendOutput(`{< youtube ${id}>}`);
}
@ttscoff
ttscoff / rouge_bunch.rb
Created August 3, 2022 22:15
Rouge highlighting for Bunch syntax
# This "hook" is executed right before the site's pages are rendered
Jekyll::Hooks.register :site, :pre_render do |site|
require "rouge"
module Rouge
module Lexers
class BunchLexer < RegexLexer
title 'Bunch'
desc "Bunch.app File"
@ttscoff
ttscoff / btt_indigo.rb
Last active July 2, 2022 15:52
Indigo control for BetterTouchTool
#!/usr/bin/env ruby
# Indigo control for BetterTouchTool
#
# Usage:
#
# To query a device status
# /path/to/btt_indigo.rb status "Device Name"
#
# To toggle a device:
# /path/to/btt_indigo.rb toggle "Device Name to Query for state" "Action On Group Name" "Action Off Group Name"