Skip to content

Instantly share code, notes, and snippets.

View brandonpittman's full-sized avatar

Brandon Pittman brandonpittman

View GitHub Profile
defmodule Lists do
def len([]), do: 0
def len([ _head | tail ]), do: 1 + len(tail)
def sum([]), do: 0
def sum([h | t]), do: h + sum(t)
def double([]), do: []
def double([head | tail ]), do: [2*head | double(tail)]
@brandonpittman
brandonpittman / 99bottles.rb
Last active June 19, 2017 05:36
99 Bottles of OOP assignment
class Bottles
def verse(number_of_bottles)
first_line(number_of_bottles) << "\n" << second_line(number_of_bottles) << "\n"
end
def verses(number_of_bottles_start, number_of_bottles_end)
number_of_bottles_start.downto(number_of_bottles_end).map do |number_of_bottles|
verse(number_of_bottles)
end.join("\n")
end
@brandonpittman
brandonpittman / Gotconvert.vim
Created February 16, 2017 23:52
Convert a ThronesDB decklist into a usable format for ThronesTeki
function! Gotconvert() abort
silent g/^\D/d
silent g/^$/d
silent %s/\v^(\d)x (.+)/\1\2
endfunction
@brandonpittman
brandonpittman / proof.fish
Created January 6, 2017 00:55
Fish function for using writing scripts
# Check out the individual writing scripts here:
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
# red is wrapper for the fish utility "cprintf" that uses `cprintf "<fg:red>%s</fg>" "Weasel words:"`
function proof --description 'Check writing for dups, passive voice and weasel words'
red "Weasel words:"
weasel $argv
red "Passive voice:"
passive $argv
red "duplicates:"
@brandonpittman
brandonpittman / book_project.applescript
Created December 30, 2016 01:08
Create a book project with OmniFocus
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use O : script "omnifocus"
on main(argv)
tell application "OmniFocus"
tell default document
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
@brandonpittman
brandonpittman / dwife.txt
Created December 29, 2016 04:31
The Dornishman's Wife
The Dornishman’s wife was as fair as the sun,
and her kisses were warmer than spring.
But the Dornishman’s blade was made of black steel,
and its kiss was a terrible thing.
The Dornishman’s wife would sing as she bathed,
in a voice that was sweet as a peach,
But the Dornishman’s blade had a song of its own,
and a bite sharp and cold as a leech.
@brandonpittman
brandonpittman / move_regular_files_from_home_to_desktop.sh
Created December 29, 2016 04:19
Accidentally create a non-dotfile at the base of your home directory? Move those files to the desktop!
#!/bin/bash
find ~ -maxdepth 1 -type f -not -name '.*' -exec mv {} ~/Desktop \;
@brandonpittman
brandonpittman / uptime_check.awk
Created December 11, 2016 12:01
Create OmniFocus task to restart Mac if uptime > 7 days
#!/usr/bin/awk -f
BEGIN {
cmd="uptime"
cmd | getline output
if (output ~ /up ([7-9]|[[:digit:]][[:digit:]]) days/) {
system("osascript -e \'tell application \"Omnifocus\" to parse tasks into default document with transport text \"Restart iMac! @home ::misc //"output"\"\'")
}
}
@brandonpittman
brandonpittman / prepend.fish
Last active December 5, 2016 02:11
Prepend function for Fish Shell
function prepend -d "Prepends argv[1] to argv[-1]"
set -l args $argv[2..-1]
set -l text "$argv[1]"
for arg in $args
echo '' > $arg
sed -i -e '1i\
'"$text" $arg
@brandonpittman
brandonpittman / OF2Email.scpt
Last active September 3, 2016 10:22
Send available OmniFocus tasks to an email address
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
# classes, constants, and enums used
property NSCaseInsensitiveSearch : a reference to 1
property NSString : a reference to current application's NSString
set taskList to {}