Skip to content

Instantly share code, notes, and snippets.

@ttscoff
ttscoff / changelog.rb
Last active September 5, 2024 18:16
Generate release notes from git commit messages
#!/usr/bin/ruby -W1
# frozen_string_literal: true
require 'optparse'
require 'shellwords'
# A script to automate changelog generation from Git commit messages
#
# For use with a git-flow workflow, it will take changes from the last tagged
# release where commit messages contain NEW, FIXED, CHANGED, and IMPROVED
@cocoalabs
cocoalabs / gist:2fb7dc2199b0d4bf160364b8e557eb66
Created August 15, 2016 21:50
Color Terminal for bash/zsh etc..
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
@ttscoff
ttscoff / sizeup.bash
Created January 5, 2015 16:48
A shell function for viewing file sizes and totals within a nested directory structure
__sizeup_build_query () {
local bool="and"
local query=""
for t in $@; do
query="$query -$bool -iname \"*.$t\""
bool="or"
done
echo -n "$query"
}
@ttscoff
ttscoff / Automator Workflow.sublime-build
Last active October 22, 2018 21:38
A script to take input on STDIN and update a specified Automator (OS X) workflow action with it
{
"shell_cmd": ["cat", "$file", "|", "/usr/bin/ruby", "/Users/ttscoff/scripts/update_workflow.rb"]
}
@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
@siracusa
siracusa / rename.pl
Created August 16, 2014 16:29
Larry Wall's file renamer, slightly modified
#!/usr/bin/perl
use strict;
use warnings;
die "Usage: rename <expression> <files>\n" unless (@ARGV >= 2);
my $op = eval 'sub { ' . shift . ' }'; # crazily dangerous - type carefully!
die $@ if $@;
@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 / 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_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()