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 / whereami.sh
Created July 2, 2014 16:08
Uses get-location/CoreLocation on a Mac and Google's geocoding API to tell you the street address of your current location
#!/bin/bash
# So you know whoami, but whereami?
# Relies on this handy hack <https://github.com/lindes/get-location>
latlong=$(/usr/local/bin/get-location 2> /dev/null \
| sed -e 's/.*<\(.*\)>.*/\1/')
address=$(curl -Ss "http://maps.googleapis.com/maps/api/geocode/json?latlng=$latlong&sensor=false" \
| grep formatted_address \
| head -n 1 \
| sed -e 's/[ \t]*"formatted_address" : "\(.*\)",/\1/')
@ttscoff
ttscoff / github_toc.rb
Last active February 20, 2025 09:39
A script to generate tables of contents for GitHub readme files
#!/usr/bin/env ruby
# encoding: utf-8
=begin
github_toc v0.2.0
Brett Terpstra 2014
<http://brettterpstra.com/2014/07/01/github-toc-service/>
Creates a linked table of contents from headers in a GitHub readme
Place a [toc] marker in the file to have it automatically replaced with the TOC
@ttscoff
ttscoff / marked_gollum_pre.rb
Created June 30, 2014 22:49
Search a concatenated Marked index file for include comments and adjust [[image.jpg]] tags to point to paths relative to included file
#!/usr/bin/ruby
# Marked 2 preprocessor
# Search a concatenated Marked index file for include comments and adjust
# [[image.jpg]] tags to point to paths relative to included file
# Update: Converts [[tags]] to Markdown image tags using the generated paths
input = STDIN.read
includes = []
@ttscoff
ttscoff / new_podcast.rb
Last active September 14, 2023 14:28
Create a new Sublime Text workspace with 4 vertical columns and starter note buffers
#!/usr/bin/ruby
# new_podcast.rb
# Create a new Sublime Text workspace with 4 vertical columns and starter note buffers
# Brett Terpstra 2014
# Free to use and modify (WTF license)
# Usage: new_podcast.rb episode_title
require 'fileutils'
# By default new workspaces are created in subdirs off the current directory
# modify project_root to always have them built in a specific location, (e.g. project_root = "~/Dropbox/Podcasts")
@ttscoff
ttscoff / cdt.bash
Created June 12, 2014 14:22
cdt function to change directory based on a tag filing system
# In my tag-filing system where top-level "context" folders are tagged with
# "=Context" tags and subfolders are tagged with "@project" tags, this function
# lets me quickly cd to any tagged folder in my filing system. The first
# argument is a context folder, the rest are a chain of subfolders. The
# subfolders don't need to be contiguous, and the matching is fuzzy.
cdt() {
local fuzzy
local root
local sub
local list
@ttscoff
ttscoff / gen_random_filename.bash
Created June 9, 2014 15:39
Generate random filenames using an adjective and a noun from the WordNet dictionaries
# Bash function gen_random_filename
# Description: Generates random file names
# Requires shuf (brew install coreutils)
# Requires a list of adjectives and nouns (1 per line)
gen_random_filename() {
local adjs=~/words/adjectives.txt
local nouns=~/words/nouns.txt
local adj noun title starts_with_1 starts_with_2 counter
@ttscoff
ttscoff / gen_random_filename.bash
Last active August 29, 2015 14:02
Bash function to generate random 2-word underscore strings for filenames. Uses aspell and shuf (gnu coreutils).
# Bash function gen_random_filename
# Description: Generates random two-word names
# Requires a dictionary file, easily generated with `aspell dump master > dictionary.txt`
# or grab it from https://gist.githubusercontent.com/ttscoff/55493fe89c35ec1588ba/raw/
# Requires shuf (brew install coreutils)
#
# Example results:
# darkest_pickpockets
# besets_struts
# unzip_Malone
@ttscoff
ttscoff / marked_lyx.sh
Last active May 5, 2017 08:55
A custom preprocessor for Marked 2 that will export two files after Marked does initial inclusion and processing, then cancel the processor and have Marked resume processing.
#!/bin/bash
# A custom preprocessor for Marked 2 that will export two files after Marked
# does initial inclusion and processing, then cancel the processor and have
# Marked resume processing.
# Install the latest version of MultiMarkdown:
# http://fletcherpenney.net/multimarkdown/download/
function main()
@ttscoff
ttscoff / mindmeister_store.rb
Last active December 19, 2022 22:43
Store Markdown exports (as well as PDF and other formats) of all MindMeister maps in an account. See https://brettterpstra.com/2014/05/27/mirror-your-mindmeister-maps-to-nvalt/ for usage
#!/usr/bin/env ruby
require 'digest/md5'
require 'uri'
require 'net/http'
require 'yaml'
require 'rexml/document'
require 'fileutils'
require 'time'
require 'open-uri'
@ttscoff
ttscoff / tm.completion.bash
Last active February 20, 2025 09:42
Fuzzy Bash completion for tmux session/window using [tm](http://brettterpstra.com/2014/05/11/making-my-tmux-life-easier/)
_tm_complete() {
local rx
local token=${COMP_WORDS[$COMP_CWORD]}
local IFS=$'\t'
local words
if [ $COMP_CWORD -eq 2 ]; then
words=$(tmux list-windows -t ${COMP_WORDS[1]} 2> /dev/null | awk '{print $2}' | tr -d '*-' | tr "\n" "\t")
elif [ $COMP_CWORD -eq 1 ]; then
words=$(tmux -q list-sessions 2> /dev/null | cut -f 1 -d ':' | tr "\n" " ")
fi