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 / grabicon.sh
Created March 4, 2011 23:45
Rough Bash script for pulling icon files from Mac applications
#!/bin/bash
APP=`echo $1|sed -e 's/\.app$//'`
# Removes ".app" if it was passed
ICON=`defaults read /Applications/$APP.app/Contents/Info CFBundleIconFile|sed -e 's/\.icns$//'`
# Removes ".icns" if the Info.plist has it
# Harcoded for /Applications, needs to be rewritten for other locations or droplets
## Save icon on Desktop in JPEG format, resized to 256 max width/height
@ttscoff
ttscoff / pick_editor.rb
Created April 2, 2011 13:40
Returns the best running editor on a Mac, if any, based on my personal order of preference.
#!/usr/bin/ruby
#
# Returns the best running editor (Mac), if any, based on my personal order of preference.
def pick_editor
editors = ['TextMate','MacVim','Espresso','Coda','TextEdit']
ps = %x{ps Ao comm|grep .app|awk '{match($0,/([^\\/]+).app/); print substr($0,RSTART,RLENGTH)}'}.split("\n")
editors.each {|editor|
return editor if ps.include?(editor+".app")
}
#!/usr/bin/ruby
%w[fileutils ftools set zlib].each do |filename|
require filename
end
# Load the Marshal dump to a hash
def load file_name
begin
file = Zlib::GzipReader.open(file_name)
@ttscoff
ttscoff / inline2ref.rb
Created September 9, 2011 21:06
Convert inline Markdown links to references
#!/usr/bin/env ruby
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
def find_headers(lines)
in_headers = false
lines.each_with_index {|line, i|
if line =~ /^\S[^\:]+\:( .*?)?$/
@ttscoff
ttscoff / inline2ref_bb.rb
Created September 11, 2011 01:07
Inline Markdown links to Reference links v2 (BBEdit)
#!/usr/bin/env ruby
# change this to your domain to have local links titled appropriately
my_site = "http://brettterpstra.com"
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
def find_headers(lines)
@ttscoff
ttscoff / dotjssafarifix
Created October 17, 2011 14:07
Add CSS loading to dot.js Safari extension
# Adding CSS loading to dot.js Safari Extension
#################################
# /usr/local/bin/djsd line 33-42
# just need to add "css" to the detect origin function
def detect_origin(req)
path = req.path
origin = req.header['origin']
search = path.gsub('/','').gsub(/\.(js|css)$/,'') + '$'
@ttscoff
ttscoff / DefaultKeyBinding.dict
Created November 8, 2011 23:45
Flexible DefaultKeyBinding trick to continue plain text lists
// Add to (or create) ~/Library/KeyBindings/DefaultKeyBinding.dict
// Incorporated change by Lri to not require additional words on the line to work
// fixed to handle first character of list item being non-alphanumeric
// Issues:
// If there are more than one symbols ([[, ![, etc.) at the beginning of the line, anything beyond the first one is captured and added to new line
// FIXED: Entering more than one blank item in a row and then using ⌘Z leaves a placeholder character on the previous line.
{
@ttscoff
ttscoff / wiki2html.rb
Created November 15, 2011 21:56
wiki to html with wikicloth
#!/usr/bin/ruby
require 'rubygems'
require 'wikicloth'
@wiki = WikiCloth::Parser.new({ :data => ARGF.read })
puts @wiki.to_html
@ttscoff
ttscoff / indent-to-ul.rb
Created December 7, 2011 14:02
Indented or Markdown list to HTML Unordered List
#!/usr/bin/ruby
# ruby script to make an unordered list from indented data.
data = %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip
result = "<ul>\n"
last_leading_space = ""
g_tab_width = 4
@ttscoff
ttscoff / scrivwatcher.rb
Created January 25, 2012 15:05
Watch a Scrivener project for changes and update Marked.app
#!/usr/bin/ruby
# scrivwatch.rb by Brett Terpstra, 2011
# Modifications to merge into one file for Markdown viewing in Marked by BooneJS, 2012
# Modified to use REXML and add titles by Brett Terpstra, 2012 <https://gist.github.com/1676667>
#
# Watch a Scrivener project for changes and update a preview file for Marked
# Usage: scrivwatch.rb /path/to/document.scriv
# <http://markedapp.com>
require 'fileutils'