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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / td.bash
Created July 26, 2014 22:33
Bash function for creating and opening per-project TaskPaper files.
# [Create and] open project todo
# If you don't pass a name as an argument, it's pulled from the directory name
td() {
if [[ -n $1 ]]; then
proj=$1
todofile=$proj.taskpaper
else
proj=${PWD##*/}
todofile=$proj.taskpaper
fi
@ttscoff
ttscoff / forecast.rb
Created July 28, 2014 18:40
Quick Dark Sky forecast script for my GeekTool setup. Needs forecast_io gem and an API key, edit the coordinates as needed
#!/usr/bin/ruby
require 'rubygems'
require 'forecast_io'
ForecastIO.api_key = 'xxxxxxxxxxxx'
forecast = ForecastIO.forecast(44.047889,-91.640439)
if ARGV[0] == "current"
print "#{forecast.currently.temperature.round}, #{forecast.currently.summary}"