Skip to content

Instantly share code, notes, and snippets.

Family,
Please everyone take me off your lists of political emails. Most of them
are beyond common sense and incredibly insulting. I hate to have to ask
this of my family who I find smart and loving, but it's gone past the point
of just being able to simply delete or ignore.
Thank you.
Love you,
Jason Carpentier
@Erreon
Erreon / gist:1731962
Created February 3, 2012 19:39
Fizzbuzz test
(1..100).each {|n|
if n % 3 === 0 && n % 5 === 0
puts "FizzBuzz"
elsif n % 3 === 0
puts "Fizz"
elsif n % 5 === 0
puts "Buzz"
else
puts n
end
@Erreon
Erreon / gist:1709018
Created January 31, 2012 05:24
pull info from craigslist for picker app
class Product < ActiveRecord::Base
validates_presence_of :price, :description, :votes
serialize :images
def self.new_from_url(url)
doc = Nokogiri(open(url))
price = doc.search('h2').to_s[/\$(\d+)/].gsub('$',"")
title = doc.title
description = doc.search('#userbody').to_s.split('<!--')[0].gsub(%r{</?[^>]+?>},'').gsub(/\n/," ").strip
@Erreon
Erreon / gist:1667299
Created January 24, 2012 01:52
FizzBuzz
count = 1
while count < 100
if count % 5 == 0 and count % 3 == 0
puts "FizzBuzz"
elsif count % 5 == 0
puts "Buzz"
elsif count % 3 == 0
puts "Fizz"
else
puts count
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
if listing_count > 100
listings = []
limit = 100
begin
listing_chunk = shop.get_shop_listings(username, :offset => listings.length, :limit => limit).results
listings += listing_chunk
end while listing_chunk.length >= limit
else
class Location < ActiveRecord::Base
attr_accessible :street_address, :city, :state, :zipcode, :price, :lat, :lng, :full_address
before_validation_on_create :geoleo
def geoleo
geo = Geokit::Geocoders::GoogleGeocoder.geocode(full_address)
errors.add(:full_address, "Could not Geocode address") if !geo.success
if geo.province == "Bexar"
self.street_address,self.city,self.state,self.county,self.lat, self.lng = geo.street_address,geo.city,geo.state,geo.province,geo.lat$