Skip to content

Instantly share code, notes, and snippets.

test 'upcoming games are games without a score' do
liverpool = Team.create!(:name => 'Liverpool')
arsenal = Team.create!(:name => 'Arsenal')
upcoming_liverpool_versus_arsenal = Game.create!(:home_team => liverpool, :away_team => arsenal)
played_liverpool_versus_arsenal = Game.create!(:home_team => liverpool, :away_team => arsenal, :home_score => 2, :away_score => 3)
assert liverpool.home_games.upcoming.include?(upcoming_liverpool_versus_arsenal)
assert_equal false, liverpool.home_games.upcoming.include?(played_liverpool_versus_arsenal)
end
#Here is a hint for the view
@team.home_games.all(:conditions => #...fill in the rest
<%= javascript_include_tag :defaults %>
# 1. Register for an account at clickatell (), you should get 10 free sms messages
# 2. Install the clickatell gem by typinging: gem install clickatell
# Documentation: http://github.com/lukeredpath/clickatell
api_id = ENV['CLICKATELL_ID']
username = ENV['CLICKATELL_USERNAME']
password = ENV['CLICKATELL_PASSWORD']
require 'rubygems'
require 'clickatell'
def index
@games = Game.all
respond_to do |format|
format.html #so we can still respond to requests from browsers
format.xml do
render :xml => @games.to_xml
end
end
end
#added this method to Game model
#To see more about reading and writing csv files, see http://fastercsv.rubyforge.org/
def self.convert_games_to_csv(games)
require 'fastercsv' #<= This require statement really belongs at the top of the config/environment.rb file
csv = ['home team', 'away team', 'home scroe', 'away score'].to_csv
games.each do |game|
csv << [game.home_team.name, game.away_team.name, game.home_score, game.away_score].to_csv
end
csv
require 'rubygems'
require 'json'
require 'rest_client'
def create_person(name)
JSON.parse RestClient.post( "http://localhost:8988/neo4jr-social/nodes", :name => name )
end
def make_mutual_friends(node1, node2)
RestClient.post "http://localhost:8988/neo4jr-social/nodes/#{node1['node_id']}/relationships", :to => node2['node_id'], :type => 'friends'
require 'hpricot'
require 'open-uri'
railscasts_path = File.join(Rails.root, 'tmp', 'railscasts')
FileUtils.mkdir_p(railscasts_path)
feed = Hpricot(open("http://feeds.feedburner.com/railscasts"))
feed.search('enclosure') do |enclosure|
puts "Downloading: #{enclosure[:url]}"
`cd #{railscasts_path} && wget #{enclosure[:url]}`
end
raise 'Rails 2.3.2 to_json method fails if you attempt to load JSON gem before active support is loaded' if defined?(JSON)
require 'json/add/rails'
require 'json/add/core'
#!/usr/bin/ruby
# This was a quick hack to download Facebook URLs from
# http://www.facebook.com/directory
#
# @author Ron Bowes
# @date 2010-07-11
require 'net/http'
require 'uri'