Skip to content

Instantly share code, notes, and snippets.

#!/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"
@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
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
# 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}/) }
# 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"
require "rubygems"
require "activesupport"
class Person
attr_accessor :name, :age
def initialize(name, age)
@name=name
@age=age
end
end
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)
# EXTRACTED FROM THIS THREAD:
# http://rails.lighthouseapp.com/projects/8994/tickets/879-finding-the-days-weeks-months-years-between-two-dates
require "rubygems"
require "activesupport"
#activesupport is necessary for Date.parse (I think)
class Date
def self.days_between(start, finish)
(finish - start).to_i
end
while 1
unixtime = Time.new.strftime('%s')
if Integer(unixtime) > 1234567890
puts "HOORAAAYYYY Unix Time > 1234567890 - #{unixtime}"
else
puts "Booooo Unix Time not yet #{unixtime}"
end
sleep 1
end
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names