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 / marky.rb
Created June 20, 2012 17:02
Ruby script for interfacing with Marky the Markdonwifier
#!/usr/bin/env ruby
require 'open-uri'
require 'net/http'
require 'iconv'
require 'optparse'
require 'fileutils'
require 'cgi'
$options = {}
@ttscoff
ttscoff / template_increment.rb
Created June 27, 2012 09:38
Turns templated input into repeating blocks based on start and end numbers
#!/usr/bin/ruby
# Turns templated input into repeating blocks based on start and end numbers
# Basic syntax: `##0,5##` where 0 is start and 5 is end
# Modifiers may be included: `##+4##` will be replaced by the current counter plus four
# One start,end placeholder allowed, any number of modifers
# By Brett Terpstra, 2012 <http://brettterpstra.com>
# WTFPL License <http://en.wikipedia.org/wiki/WTFPL>
input = STDIN.read
@ttscoff
ttscoff / pdfsearch.rb
Created July 2, 2012 09:04
Locate PDFs containing a string via Spotlight and return page numbers for pages containing search string.
#!/usr/bin/env ruby
=begin
PDFSearch (OSX-only[^1]) by Brett Terpstra 2012
requires pdf-reader <https://github.com/yob/pdf-reader>
`gem install pdf-reader`
* Searches for the string(s) passed as arguments in PDF files located by Spotlight
* Quote arguments to search exact phrase, unquoted arguments are fuzzy
* Returns a Markdown definition list to STDOUT with links to matched files and page numbers matched
* Progress reported to STDERR, output can be redirected silently.
@ttscoff
ttscoff / searchFocus.bookmarklet.js
Created July 3, 2012 01:05
Bookmarklet to select the search field on the current page and focus it
javascript:var%20inputs=document.getElementsByTagName('input'),firstSearch=false,textinputs=[],i,t;for(i=0;i<inputs.length;i++)if(((inputs[i].type==='text')||(inputs[i].type==='search'))&&inputs.disabled!==true)textinputs.push(inputs[i]);for(t=0;t<textinputs.length;t++)if((/search/i).test(textinputs[t].className)||(/(^[sq]$|search|query)/i).test(textinputs[t].id)||(/^(q(uery)?|s|.*?search.*)$/).test(textinputs[t].name)){firstSearch=textinputs[t];break;}if(!firstSearch)textinputs[0].focus();else%20firstSearch.focus();
@ttscoff
ttscoff / tu2ifttt-bt.py
Created July 5, 2012 04:52
Modified version of Dr. Drang's ThinkUp db -> text file script. Adds Markdown formatting and t.co expansion.
#!/usr/bin/python
import csv
import os
from datetime import datetime
import sys
import re
import urllib2
expand_tco_links = False
@ttscoff
ttscoff / ifttt-tweets2md.py
Created July 5, 2012 12:06
Converts a ThinkUp CSV export to monthly archive files with Markdown formatting
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
This script parses a text file with archived tweets and sorts them into archive files based on month
Original script by [Ian Beck](http://beckism.com/2012/07/archiving-tweets/) 2012
This iteration by [Brett Terpstra](http://brettterpstra.com) 2012
Designed to operate via Hazel or other file watcher. Reads a Dropbox file
@ttscoff
ttscoff / editscript.rb
Created July 7, 2012 01:26
Fuzzy CLI file search through configured directories, ranked results displayed as menu
#!/usr/bin/env ruby
# encoding: utf-8
# == Synopsis
# Proof of concept using Fuzzy File Finder to locate a script to edit
# Searches a set of predefined locations for a fuzzy string
# e.g. "mwp" matches both "myweatherprogram" and "mowthelawnplease"
# ................on "(m)y(w)eather(p)rogram" and "(m)o(w)thelawn(p)lease"
#
# Results are ranked and a menu is displayed with the most likely
# match at the top. Editor to be launched and directories to search
@ttscoff
ttscoff / textile.pl
Created July 14, 2012 07:11
Replacement textile command to handle UTF8
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use warnings;
use strict;
use File::Basename;
use Getopt::Long;
use Text::Textile qw(textile);
use Encode;
@ttscoff
ttscoff / wp_mangler_inline-to-ref.rb
Created July 26, 2012 11:56
Handler for wp_mangler that replaces inline markdown links with references
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
def process_post(input)
links = input.scan(/\((https?:\/\/([^\)]+))\)/)
refs = input.scan(/^\[([^^][^\]]+)\]: (.*)$/)
lines = input.split("\n")
bottom = lines[0..-1].join("\n").gsub(/^\[([^^][^\]]+)\]: .*\n?/,'')
@ttscoff
ttscoff / wp_mangler.rb
Created July 26, 2012 11:57
wp_mangler: runs a replace on WordPress post content
#!/usr/bin/env ruby
# Requires 'sequel' and 'mysql' rubygems
require 'rubygems'
require 'sequel'
require 'cgi'
def e_sql(str)
str.to_s.gsub(/(?=[\\])/, "\\")
end