Skip to content

Instantly share code, notes, and snippets.

View pathouse's full-sized avatar
🐶

Pat McGee pathouse

🐶
View GitHub Profile
module ActiveRecord
module ConnectionAdapters
module DatabaseStatements
#
# Run the normal transaction method; when it's done, check to see if there
# is exactly one open transaction. If so, that's the transactional
# fixtures transaction; from the model's standpoint, the completed
# transaction is the real deal. Send commit callbacks to models.
#
# If the transaction block raises a Rollback, we need to know, so we don't
@pathouse
pathouse / imdb_pro_production_companies_by_location.rb
Last active April 11, 2023 20:09
IMDb pro has a database of more than 22,000 production companies. Unfortunately, their searching and sorting tools are pretty poor. This is a very simple first draft of a script for scraping those pages for info and writing the results to a csv file. This is 4401 pages of data (50 companies per page) so it takes a while. An IMDb pro subscription…
require 'mechanize'
require 'csv'
PAGES = (1..4401)
LOGIN_PAGE = "https://secure.imdb.com/signup/v4/login"
BASE_URL = 'http://pro.imdb.com/companies/type-production'
def page_url(page)
@pathouse
pathouse / greed-score.rb
Last active December 17, 2015 16:39
Working through the Greed scoring problem in Ruby Koans, the first two lines of my solution made me smile. Thanks Ruby. For context, 'dice' is an array of 5 numbers representing 5 die rolls.
def score(dice)
dice_hash = {"1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0, "6" => 0}
count = dice.each {|x| dice_hash[x.to_s] += 1}
end