Skip to content

Instantly share code, notes, and snippets.

View aantix's full-sized avatar

Jim Jones aantix

View GitHub Profile
@aantix
aantix / seed_model_hash_dump.rb
Created January 1, 2011 02:34
Display model data in hash form for create -- Useful in dumping old Rails model data (for seeds.rb)
model = Object::const_get(ARGV[0])
rows = model.find(:all)
# Any columns you don't want output, list here as symbols
# e.g. BLACKLIST = [:user_id, :workout_id]
BLACKLIST = []
# Any columns that you'd like to rename on the output, list in this hash
# e.g. TRANSFORM = {:percentOfMax => :percent_of_max}
TRANSFORM = {}
@aantix
aantix / pre-commit
Created January 11, 2011 22:21
Checks to see if there are any uncommitted files and alerts the git user that they need to add or ignore before proceeding.
#!/bin/sh
#
# .git/hooks/pre-commit
#
if git status -u | grep '^# Untracked files:$'
then
echo 'Files need to be either added ( git add .) or ignored (edit the .gitignore file) before a commit can be made.'
exit 1
fi
@aantix
aantix / factories_from_db.rb
Created January 16, 2011 12:14
Takes a seeded model and dumps out the data in a format that can be used for testing factories
# 523 : ~/Projects/runfatboy2 $ rails runner ~/factories_from_db.rb Exercise 1 2 3
#
# Factory.define :exercise_incline press do |r|
# r.name 'Incline Press'
# r.url 'http://video.google.com/googleplayer.swf?docId=-5762262560903802111&hl=en'
# r.verb 'Lift'
# r.measurement_type_id 3
# r.exercise_type_id 1
# r.user_id 2
# r.start_weight 0.8
@aantix
aantix / turk_import_to_excel.rb
Created January 19, 2011 02:51
Imports the data for a specific Mechanical Turk HIT (by title) and stores the data in an excel spreadsheet.
# turk_import_to_excel.rb hit_title file_output.xls sandbox=false dispose_hit=false
# ruby turk_import_to_excel.rb 'Find resources to help the disabled/underprivileged people of San Francisco, CA' /tmp/output.xls false false
#
# 255 char limitation for spreadsheet cell : http://blog.eastfacesoftware.com/2008/01/14/ruby-spreadsheet-excel-gem-255-character-limit/
#
require 'rubygems'
require 'rturk'
require "spreadsheet/excel"
@aantix
aantix / sync.rb
Created January 19, 2011 21:38
RSyncs all svn changed files to a remote VM volume. Useful when you want to test changes on a remote VM, but not necessarily commit them to the SVN trunk.
#!/usr/bin/env ruby
ignore_patterns = ["db/","test","log","reports","server","vendor/","Gemfile","tmp",".idea","config/",".DS_Store", ".xml", '.zip']
ignore_statuses = ['!','D','?']
changed_files = (`svn status`).split("\n").collect do |e|
p = e.split(/\s+/)
ignore_statuses.include?(p[0]) ? nil : p[p.size - 1]
end.compact
@aantix
aantix / download_images.rb
Created November 7, 2011 01:16
Download all images for a given web page
require 'nokogiri'
require 'open-uri'
require 'uri'
require 'pathname'
pages = ['http://images.google.com/search?tbm=isch&hl=en&source=hp&q=dogs',
'http://images.google.com/search?tbm=isch&hl=en&source=hp&q=cats',
'http://images.google.com/search?tbm=isch&hl=en&source=hp&q=hats']
pages.each do |page|
@aantix
aantix / gist:1596047
Created January 11, 2012 18:30
Open Letter to Mechanical Turk: Please improve the externalSubmit interface

Sharon, just to introduce myself. My name is Jim Jones, I’m a senior software engineer at Zvents (recently acquired by StubHub). We’re located in San Mateo, CA.

I am the author of the Ruby/Mechanical Turk integration gem, Turkee ( http://www.github.com/aantix/turkee ).

Recently I’ve run into an issue with the platform’s externalSubmit interface. I’ve posted the specifics here :
https://forums.aws.amazon.com/thread.jspa?threadID=84581&tstart=0

My frustration lays with the fact that there is no way to accurately debug issues that arise with posting to the externalSubmit interface. All I receive is an ambiguous “Your request was not completed successfully”. This isn’t the first time I’ve run into this ambiguous error message.

Further complicating the issue, the above issue appeared to be inconsistent on my day-to-day debugging. One day it appeared to be length dependent, the next day those same

@aantix
aantix / clean_pop3.rb
Created January 13, 2012 23:54
Clean Pop3 Account
require 'net/pop'
Net::POP3.start(ARGV.shift, 110,
ARGV.shift, ARGV.shift) do |pop|
if pop.mails.empty?
puts 'No mail.'
else
puts "Deleting #{pop.mails.size} mails."
i = 0
pop.each_mail do |m| # or "pop.mails.each ..."
@aantix
aantix / gist:1999816
Created March 8, 2012 09:08
Remote Pair Programming sucks. Here's how to solve it.

REAL WORLD SCENARIO (blinking lights)

Mr. Tom Dev wants to remote pair program with Mr. Todd Programmer. Tom is in New York, Todd is in San Francisco. They’re working on yet another blog written in Ruby. Tom fires up Rubymine, Todd fires up TextMate.

Todd’s editor quickly alerts him that he is connected with Tom and that their projects are out of sync. The plugin gives them each the option of using Tom’s file versions, Todd’s files, or performing a git pull request. They both do a git pull and are back in sync.

Todd quickly opens the User model in Rubymine with cmd-shift-N and Todd quickly sees that same file opened in Textmate. Todd then highlights a method that has been failing a test and Tom sees that highlight. Todd makes the change to the file, clicks cmd-s, and that file change is synced over to Tom.

Tom thought there was a secondary change needed in the Profile model, so he hits cmd-T, opens the Profile model and Todd sees that file opened in Rubymine. Todd tells Tom that he’s smoking catn

@aantix
aantix / extract_emails_names.rb
Created April 11, 2012 16:50
Extract Names and Emails Address
# http://zadasnotes.blogspot.ca/2012/04/extracting-names-and-email-addresses.html
# first last <[email protected]>
# {:name => "First Last", :email => "[email protected]"}
# [email protected]
# {:name => "John Smith", :email => "[email protected]"}
# [email protected]
# {:name => "Mary", :email => "[email protected]"}
def names_and_emails_from_multiple_addresses(emails)
addresses = emails.split(',')