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 / recentgists.rb
Created July 28, 2012 11:51
Log my public gists for the last 24 hours to Day One and nvALT
#!/usr/bin/env ruby
require 'open-uri'
require 'time'
require 'erb'
require 'rubygems'
require 'json'
user = 'ttscoff'
dayone = true # log to day one? (true or false)
@ttscoff
ttscoff / finished.rb
Created July 31, 2012 15:36
A quick shell script that wraps the terminal-notifier for quick Mountain Lion notifications when a process finishes
#!/usr/bin/ruby
# finished: a quick script to notify you when a command is done using Mountain Lion notifications
# It grabs the current folder as the title and takes one argument as the message
# Example: make && make install && finished "Done compiling" || finished "compiler failed"
#
# Needs the terminal-notifier gem : `gem install terminal-notifier`
# Can alternately be used with the CLI <https://github.com/alloy/terminal-notifier>
# (remove require block below and swap comment lines at the bottom)
require 'rubygems'
@ttscoff
ttscoff / bid.sh
Created July 31, 2012 20:27
Retrieve Bundle Identifiers for OS X applications using semi-fuzzy string matching
bid() {
local shortname location
# combine all args as regex
# (and remove ".app" from the end if it exists due to autocomplete)
shortname=$(echo "${@%%.app}"|sed 's/ /.*/g')
# if the file is a full match in apps folder, roll with it
if [ -d "/Applications/$shortname.app" ]; then
location="/Applications/$shortname.app"
else # otherwise, start searching
@ttscoff
ttscoff / growlnotify.rb
Created August 1, 2012 11:18
Seamless drop-in to turn existing growlnotify calls into Mountain Lion Notifications
#!/usr/bin/env ruby
# encoding: utf-8
# == Synopsis
# Requires the terminal-notifier gem ([sudo] gem install terminal-notifier)
# growlnotify wrapper to turn Growl alerts into Mountain Lion notifications
# Uses growlnotify option syntax to keep your old scripts working with the new shiny.
#
# If you use Growl via growlnotify in your shell scripting, this script
# will replace Growl's alerts with Mountain Lion notifications.
@ttscoff
ttscoff / DefaultKeyBinding.dict
Created August 2, 2012 15:09
Keybinding for multiple kill rings
// > defaults write -g NSTextKillRingSize -string 6
// replace yank: command with yankAndSelect for use with the kill ring
"^y" = (yankAndSelect:);
@ttscoff
ttscoff / rmdbc.bash
Created August 2, 2012 17:12
Bash alias to recursively delete Dropbox conflicted files
alias rmdbc="find . -name *\ \(*conflicted* -exec rm {} \;" # recursively delete Dropbox conflicted files
# and/or (smart idea from Gordon Fontenot)
alias rmdbcsafe="find . -name *\ \(*conflicted* -exec mv {} ~/DropboxConflicts/ \;" # recursively move Dropbox conflicted files to temp folder
# or... via TJ Luoma
alias rmdbctrash="find . -name *\ \(*conflicted* -exec mv -v {} ~/.Trash/ \;" # recursively move Dropbox conflicted files to Trash
# More advanced idea combining ideas from @modernscientist and @GFontenot would be
# Hazel or launchd script to move conflicted files to temp folder once a day, and Hazel or launchd script to delete files older than [x]
# Or schedule TJ's idea of moving to Trash and skipping intermediate folder while still maintaining the ability to review
# hmmmm...
@ttscoff
ttscoff / campl.us_partial.rb
Created August 3, 2012 04:12
Very partial code for parsing out campl.us urls and finding source image url
require 'net/http'
# in the main tweet parser. tweet_text is the status.text string
# match short campl.us urls:
if tweet_text =~ /\((http:\/\/campl.us\/\w+?)\)/
picurl = $1
# grab the source and parse out the full size image url
final_url = get_body(picurl).match(/"(http:\/\/pics.campl.us\/f\/c\/.+?)"/)
return false if final_url.nil?
@ttscoff
ttscoff / gistloggertest.txt
Created August 4, 2012 15:21
Just testing the Gist logger for Day One
The standard CGI environmental variables are available as read-only attributes of a CGI object. The following is a list of these variables:
AUTH_TYPE HTTP_HOST REMOTE_IDENT
CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
@ttscoff
ttscoff / keys.m
Created August 5, 2012 14:48
Command line utility for checking whether a modifier key is held
#import <Carbon/Carbon.h>
// `keys` utility for checking whether a modifier key is held
// From <http://lists.apple.com/archives/applescript-users/2009/Sep/msg00374.html>
//
// $ clang keys.m -framework Carbon -o keys
int main (int argc, const char * argv[]) {
unsigned int modifiers = GetCurrentKeyModifiers();
if (argc == 1)
@ttscoff
ttscoff / Launch All in Dock.applescript
Created August 5, 2012 14:58
Launch all Dock apps with exclusions based on modifier keys
-- Launch All in Dock.applescript
-- Brett Terpstra 2012
--
-- Modified version of an AppleScript to launch all
-- persistent (Keep in Dock) apps[^1]. Allows you to exclude
-- apps based on modifier keys held when it runs.
--
-- Uses the `keys` utility found on the Apple Mailing Lists[^2].