Skip to content

Instantly share code, notes, and snippets.

class Date
def self.days_between(start, finish)
(finish - start).to_i
end
def self.weeks_between(start, finish)
days_between(start, finish) / 7
end
def self.months_between(start, finish)
require "rubygems"
require "activesupport"
class Person
attr_accessor :name, :age
def initialize(name, age)
@name=name
@age=age
end
end
# Deomontrates (very simply) how Active Record handles multiparameter assignments
require "rubygems"
require "activesupport"
require "activerecord"
this_hash = {
"date(3i)" => "20",
"date(2i)" => "1",
"date(1i)" => "2003"
# This code just takes multiparamter inputs from a form and strings them together to
# create dash separated date string. The purpose behind this is because sometimes if
# a user doesn't fill in all the date drop downs in a form, you might get an invalid date
# The folowing code was repurposed from ActiveRecord::Base from a few of the mutliparamter
# assignment methods
module ConverDateParamsToString
def convert_date_params_to_string!(params, date_attr_name)
date_params = params.reject {| key, value | !(key =~ /^#{date_attr_name}/) }
require 'httparty'
class DataFetcher
include HTTParty
format :xml
base_uri "some.domain.com/api"
def fetch_data
get('/method', :query => {:param1 => 'hello', :param2 => 'world'})
end
end
@jamster
jamster / top_100_greatest_movie_characters_scraper.rb
Created December 16, 2008 15:47
Scrapes top 100 greatest movie characters with Ruby and Nokogiri
# = Top 100 Greatest Movie Characters Scraper
# This program just scrapes the empire online 100
# greatest movie characters web site (http://www.empireonline.com/100-greatest-movie-characters/)
# and generates a simple page to display all the
# characters on one page so you don't have to go
# clicking through 100 pages
#
# This was just built b/c I'd rather learn something new
# during the time it took me to view all 100 characters
# and still get to see who they are. I'm too lazy to click
#!/usr/bin/env ruby
# Author Jason Amster
# 11/18/08
app_name = ARGV[0]
if ARGV.length > 0
puts "Creating new Rails/Bort App #{app_name}"
else
puts "Please name your Bort app"