Skip to content

Instantly share code, notes, and snippets.

View seanreads's full-sized avatar
🎸
Rock and Roll!

Sean seanreads

🎸
Rock and Roll!
View GitHub Profile
@seanreads
seanreads / grepents
Created April 21, 2011 16:51
Find and sort unique alpha-decimal XHTML entities in files
grep -Eho "&#?[a-z0-9]+;" *.html | sort | uniq
@seanreads
seanreads / Homebrew 0.8 bug: syntax error in case statement (formula.rb)
Created August 26, 2011 13:53
Homebrew/formula.rb:300, syntax error in case statement
/usr/local/Library/Homebrew/formula.rb:310: warning: else without rescue is useless
Error: /usr/local/Library/Homebrew/formula.rb:300: syntax error, unexpected kCASE, expecting kWHEN
case :llvm, :clang
^
/usr/local/Library/Homebrew/formula.rb:300: syntax error, unexpected ',', expecting kWHEN
case :llvm, :clang
^
/usr/local/Library/Homebrew/formula.rb:725: syntax error, unexpected kEND, expecting $end
Please report this bug: https://github.com/mxcl/homebrew/wiki/Checklist-before-filing-a-new-issue
/usr/local/Library/Homebrew/formula_installer.rb:2:in `require'
@seanreads
seanreads / fixtures-from-flat-file
Created September 21, 2011 00:04
Quick fixtures from flat file
auths = {}
count = 0
open('authorizations.txt') do |file|
file.each do |line|
key = "auth#{count}"
auths[key] = {}
auths[key][:id] = (count += 1)
auths[key][:groups] = line.chomp
auths[key][:created_at] = "<%= Time.now %>".to_s + " "
@seanreads
seanreads / ogg2mp3
Created October 1, 2011 22:38
Convert ogg to mp3
for f in *.ogg; do sox "$f" "${f%.ogg}.mp3"; done
@seanreads
seanreads / get_and_set_hash_values_with_dot_syntax.rb
Last active October 12, 2015 17:08
Get and Set Hash Values with Dot syntax
class Hash
def method_missing(method, *args, &block)
key = method.to_s
key =~ /(.+)=$/ ? store($1, args[0]) : fetch(key)
end
end
h = Hash.new
h.foo = 'bar'
p h.foo
@seanreads
seanreads / rspec.rake
Created December 19, 2012 00:32
Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc without running prerequisite tasks. Helpful for working with non-migration-aware (i.e., legacy databases).
# Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc
# without running prerequisite, database tasks. Helpful for working
# with non-migration-aware, legacy databases.
if defined?(RSpec)
tasks = %w{ spec models controllers helpers lib mailers
rcov requests routing views }
skip_db_task = Proc.new do |task|
path = task.eql?('spec') ? 'spec/**' : "spec/#{task}"
@seanreads
seanreads / stamp.rb
Last active December 25, 2015 23:49
Utility class to convert datetime column values from one timezone to another (e.g., local to UTC).
#!/usr/bin/env ruby
# Stamp class
# Utility class to convert datetime column values from
# one timezone to another (e.g., local to UTC).
class Stamp
attr_accessor :query, :status
attr_reader :records, :duplicates
def initialize(columns, old_time_zone, new_time_zone, time_format = "%F %T")
@seanreads
seanreads / S3UrlController.rb
Last active December 25, 2015 23:59
Use Rails
class S3UrlController < AuthenticatedController
# Retreive a list of S3 objects
# For a given object, get a temporary, secret URL
skip_filter(*_process_action_callbacks.map(&:filter)) # Turn off any before filter that...
before_filter :basic_authenticate # ... is not your HTTP Basic authentication
rescue_from Exception do |error|
logger.error(error)
@seanreads
seanreads / portfolio.js
Created October 23, 2013 15:52
Client-side component to Portfolio manager project
/* Portfolio - Create PDF reports of user progress
Author: Sean O'Donnell <sodonnell@acponline.org>
Revised: April 7, 2010
*/
//TODO: Put CSS selectors in PortfolioOptions
var PortfolioOptions = {
debug_mode: false,
create_document_url: '/residents/portfolio',
@seanreads
seanreads / unvox.sh
Created December 23, 2013 22:08
# find iphone voicemails and save them locally
# unvox.sh
# find iphone voicemails and save them locally
#
# Sean O'Donnell
# Mon Dec 23 14:36:42 EST 2013
#
# requires ffmpeg, see http://www.ffmpeg.org/
BASE_DIR=$(dirname $(dirname $0))
INPUT_DIR="${HOME}/Library/Application Support/MobileSync/Backup"