Skip to content

Instantly share code, notes, and snippets.

View djsun's full-sized avatar

David James djsun

View GitHub Profile
require 'rubygems'
require 'datacatalog'
DataCatalog.base_uri = "http://localhost:3000"
DataCatalog.api_key = "CHANGE_THIS"
# r = DataCatalog::About.get
# puts r
r = DataCatalog::User.all
class Person
attr_accessor :name
def initialize(name)
@name = name
end
end
people = {}
person_1 = Person.new("Saul")
person_2 = Person.new("John")
@djsun
djsun / gist:289815
Created January 29, 2010 15:37
sorted_yaml_hash.rb
# Based on http://snippets.dzone.com/posts/show/5811
#
# Differences over snippet above:
# * will sort hashes with keys that are symbols
# * different usage style (see below)
require 'yaml'
module SortedYamlHash
$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
$ gem list | grep json
json (1.2.0)
json_pure (1.2.0)
$ gem list | grep activesupport
activesupport (2.3.5)
rows = []
tables.each do |table|
rows.concat(table.css("tr"))
end
rows
# The information is somewhat jumbled together. This method takes
# advantage that headings are wrapped in <b> tags. The result is
# an array of strings, which is easier to parse than one big string
# (which is what we would have gotten if we used `start.content`)
#
# Sample result:
# [
# "Description:",
# "Operating and Maintenance Petitions. When the annual allowable increase does not completely cover the landlord's yearly increase in operating and maintenance expenses for a property, a landlord may petition for an additional base rent increase of up to 7%. This is known as an Operating and Maintenance or O&M increase",
# "Agency Name:",
class Puller
def initialize(handler)
@handler = handler
end
def run
@handler.organization("DOE")
@handler.organization("NASA")
@handler.source("California Earthquakes")
@handler.source("Hawaii Earthquakes")
# http://www.ca.gov/CaSearch/Agencies.aspx
# From Firefox Http Live Headers Add-On
POST /CaSearch/Agencies.aspx __EVENTTARGET=ctl00%24leftColumn%24dicLetters%24lnkLetterA_C&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJMTc5MTE0ODI4DxYEHhNDdXJyZW50U2VhcmNoU3RyaW5nZR4OQ3VycmVudExldHRlcnMFBUEsQixDFgJmD2QWAgIED2QWAmYPZBYEAgEPZBYCAgEPFgIeBWNsYXNzBQZhY3RpdmVkAgkPFgIeBFRleHQF4%2FICPHRhYmxlIGNlbGxwYWRkaW5nPSIwIiBjZWxsc3BhY2luZz0iMCIgaWQ9ImFnZW5jeV9saXN0Ij48dHI%2BPHRkIGNsYXNzPSJhZ2VuY3lfbGV0dGVyIiBjb2xzcGFuPSIyIj5BPC90ZD48L3RyPjx0ciA%2BPHRkPjxhIGhyZWY9Imh0dHA6Ly93d3cuYWltLmNhLmdvdi9Ib21lL2RlZmF1bHQuYXNweCI%2BQWNjZXNzIGZvciBJbmZhbnRzIGFuZCBNb3RoZXJzPC9hPjwvdGQ%2BPHRkIGNsYXNzPSJhZ2VuY3lfc29jaWFsIj48aW1nIHNyYz0iaW1hZ2VzL3NlYXJjaF9hcHAvYndfZW1haWxfaWNvbi5qcGciIGFsdD0iRW1haWwiIC8%2BJm5ic3A7Jm5ic3A7PGltZyBzcmM9ImltYWdlcy9zZWFyY2hfYXBwL2J3X3R3aXR0ZXJfaWNvbi5qcGciIGFsdD0iVHdpdHRlciIgLz4mbmJzcDsmbmJzcDs8aW1nIHNyYz0iaW1hZ2VzL3NlYXJjaF9hcHAvYndfZmFjZWJvb2tfaWNvbi5qcGciIGFsdD0iRmFjZWJvb2siIC8%2BJm5ic3A7Jm5ic3A7PGltZyBzcmM9I
require 'rubygems'
require 'mongo'
class MongoLeakFinder
def initialize
db = Mongo::Connection.new.db("cgp")
@coll = db.collection("records")
@coll.create_index("n", :unique => true)
end
class ResourceGroup
has_many :resource_entries
end
class ResourceEntry
belongs_to :resource, :polymorphic => true
end
# A type of resource
class Image < ActiveRecord::Base