Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Breathing

Brett Terpstra ttscoff

💭
Breathing
View GitHub Profile
@ttscoff
ttscoff / rouge_bunch.rb
Created Aug 3, 2022
Rouge highlighting for Bunch syntax
View rouge_bunch.rb
# 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 Jul 2, 2022
Indigo control for BetterTouchTool
View btt_indigo.rb
#!/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"
@ttscoff
ttscoff / bunch_status.rb
Last active Jul 2, 2022
Bunch Status for BetterTouchTool and Stream Deck
View bunch_status.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
# Usage in a BetterTouchTool Shell Script Widget
#
# For a Stream Deck widget:
# /path/to/bunch_status.rb sd title "Bunch Name"
#
@ttscoff
ttscoff / lastcolor.rb
Created Jul 1, 2022
Get the current ANSI color sequence at the point a string ends
View lastcolor.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
# String color helpers
class ::String
ESCAPE_REGEX = /(?<=\[)(?:(?:(?:[349]|10)[0-9]|[0-9])?;?)+(?=m)/.freeze
# Get the calculated ANSI color at the end of the string
#
# If you want to inject a colored string into another
@ttscoff
ttscoff / 256color.rb
Last active Jul 14, 2022
256-color hex intepretation for terminal colorization
View 256color.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
# 256-color hex interpretation for terminal colorization
#
# Usage
# "text".color256(foreground, background)
#
# print "Colorize this".color256('#f7921e', '#666')
@ttscoff
ttscoff / git_fzf.fish
Last active Dec 23, 2021
Git/fzf keybindings for Fish, adapated from @junegunn
View git_fzf.fish
# @ttscoff's version of @max-sixty's revision of @aluxian's
# fish translation of @junegunn's fzf git keybindings
# https://gist.github.com/junegunn/8b572b8d4b5eddd8b85e5f4d40f17236
# https://gist.github.com/aluxian/9c6f97557b7971c32fdff2f2b1da8209
#
# 2021-12-23:
# - Fix hash returned by *git_log being truncated
# - Allow multiple selections for git_status
# - Allow multiple selections for git_log, insert HASH[1].. HASH[-1] range
# - bind ctrl-a for select all
View gist:821cb469a9daa3ba7d5929f1c4074619
mdfind -onlyin /Applications '(((kMDItemContentTypeTree == "com.apple.application"cd && (kMDItemUsedDates >= "$time.today(-30d)" && kMDItemUsedDates < "$time.today(+1d)"))))' 2> /dev/null | grep -vE '/(Dock|Finder|Music|Messages|System Preferences|Activity Monitor|Calendar).app' | awk -F/ '{sub(/\.app$/, ""); print "- ["$NF"](!s)"}' | awk '!x[$0]++'
@ttscoff
ttscoff / namecheap_ddns.sh
Created Aug 26, 2021
Namecheap DDNS for Synology
View namecheap_ddns.sh
#!/bin/bash
## Namecheap DDNS updater for Synology
## Brett Terpstra <https://brettterpstra.com>
PASSWORD="$2"
DOMAIN="$3"
IP="$4"
PARTS=$(echo $DOMAIN | awk 'BEGIN{FS="."} {print NF?NF-1:0}')
@ttscoff
ttscoff / spellcheck.bash
Last active Nov 19, 2021
Spell check all markdown files in current git repo
View spellcheck.bash
#!/bin/bash
# Check spelling of all Markdown files in current git repo using aspell
for file in $(git ls-files|grep -v -E '(/|^)_'|grep -iE '\.(md|markdown)$'); do
aspell -M --lang=en --dont-backup --home-dir=$HOME --personal=$HOME/aspell.txt check "$file"
done
@ttscoff
ttscoff / macosDND.m
Last active Sep 21, 2022
Objective-C code for toggling Do Not Disturb on macOS (including Big Sur)
View macosDND.m
/// Turn Do Not Disturb on or off
/// Only handles on and off, no schedules
/// @param enabled true on, false off
- (void)setDND:(BOOL)enabled {
NSLog(@"Turning Do Not Disturb %@", (enabled ? @"on" : @"off"));
if (@available(macOS 11.0, *)) {
NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.apple.ncprefs"];
NSData * subPlistData = [defaults objectForKey:@"dnd_prefs"];
NSMutableDictionary * propertyListDict = [[NSPropertyListSerialization propertyListWithData:subPlistData options:0 format:nil error:nil] mutableCopy];