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 / image_re.m
Created November 6, 2014 17:18
Regex for Markdown images
@"(?:\\(|:\\s+)(?!http)([^\\s]+\\.(?:jpe?g|gif|png|svg|pdf))"
# matches local images:
# matches "(image.png)"
# matches "]: image.png"
# does not match remote images (http*)
@ttscoff
ttscoff / bytes.rb
Created November 2, 2014 15:34
Convert file sizes between human-readable and machine representations
#!/usr/bin/ruby
module Bytes
def to_human(n,fmt=false)
count = 0
formats = %w(B KB MB GB TB PB EB ZB YB)
while (fmt || n >= 1024) && count < 8
n /= 1024.0
@ttscoff
ttscoff / bitlyize.rb
Created October 25, 2014 22:30
Bitlyize Service/CLI to shorten links and automatically add affiliate tags
#!/usr/bin/ruby
# encoding: utf-8
# Bitlyize by Brett Terpstra 2014
# Shortens all URLs in input and automatically adds Amazon and iTunes affiliate codes
# A single bitly link passed to this script will return the long url
# This script was designed for use in an OS X System Service, but runs
# as a CLI and can be included as a Ruby library in other scripts
#
# The bitly_username and bitly_key variables are required
# Optionally configure the custom domain, and itunes and amazon affiliate variables
@ttscoff
ttscoff / gifwar.sh
Created September 29, 2014 16:59
It's pronounced "GIF"
#!/bin/bash
say -v Vicki "it's pronounced gif"
say -v Zarvox "it's pronounced jiff"
while true; do
say -v Vicki "no, it's pronounced gif"
say -v Zarvox "it's pronounced jiff"
done
@ttscoff
ttscoff / im.bash
Created September 28, 2014 00:18
An experiment with calling `doing` with an "im" function to see how far natural language status updates will go. "im planning out the book structure" => `doing now @planning out the book structure` (http://brettterpstra.com/projects/doing/)
# experiment with doing
# im planning out the book structure => @planning out the book structure
# im waiting for her to call me back => @waiting for her to call me back
# im done wishing for ponies => wishing for ponies @done()
# im hungry => hungry
im() {
local verb=$1
shift
if [[ $verb =~ ing$ ]]; then
@ttscoff
ttscoff / syslinks.bash
Created September 23, 2014 18:25
A oneliner using wgrep to pull all of the PICKS from Systematic (since I started using the PICK: prefix, anyway)
@ttscoff
ttscoff / brett.theme.bash
Last active February 20, 2025 09:38
My in-progress Bash-it theme
#!/usr/bin/env bash
THEME_PROMPT_HOST='\H'
SCM_THEME_PROMPT_DIRTY=' 💢'
SCM_THEME_PROMPT_CLEAN=' 🌱'
SCM_THEME_PROMPT_PREFIX='[ '
SCM_THEME_PROMPT_SUFFIX=' ] '
export LS_COLORS='di=92:fi=0:ln=94:pi=36:so=36:bd=36:cd=95:or=34:mi=0:ex=31:*.log=1;30:*.txt=34:*.mmd=34:*.markdown=34:*.md=01;34:*.scpt=7:*.rb=35:*.tgz=93:*.gz=93:*.zip=93:*.dmg=93:*.pkg=93:*.taskpaper=95;1:*.pdf=96:*.jpg=33:*.png=33:*.gif=33:*.svg=33'
GIT_THEME_PROMPT_DIRTY=' 💢'
GIT_THEME_PROMPT_CLEAN=' 🌱'
@ttscoff
ttscoff / ezsnippets.rb
Last active February 20, 2025 09:38
ezsnippets v1, define expansions as you write (based on work by Stephen Margheim: http://www.alfredforum.com/topic/4680-snippets-on-the-fly-text-expansion/))
#!/usr/bin/ruby
=begin
# ezsnippets
Brett Terpstra 2014, MIT License
Based on a great idea by Stephen Margheim <http://twitter.com/s_margheim>
- http://www.alfredforum.com/topic/4680-snippets-on-the-fly-text-expansion/
- https://github.com/smargh/alfred_snippets
@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}"
@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