Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
# Validations
validates_presence_of :email, :unless => Proc.new { |user| user.email.blank? }
validates_presence_of :username, :unless => :registered_with_email?
def registered_with_username?
self.username.blank?
end
@radar
radar / gist:574857
Created September 11, 2010 05:17 — forked from danking/gist:574852
test "this is test 1" do
assert true
end
test "this is test 2" do
assert false
end
@radar
radar / next_episodes
Created September 27, 2010 05:49 — forked from maxim/next_episodes
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'time'
# ids of shows to check
movie_ids = %w(tt0773262 tt0121955 tt0182576 tt0460649 tt0903747 tt0412142)
@radar
radar / gist:711424
Created November 23, 2010 07:51 — forked from anonymous/gist:711420
$device ||= Net::SSH::Telnet.new("Host" => "192.168.0.2",
"Dump_log" => "dump_log3",
"Username" => "admn",
"Password" => "",
"Timeout" => 60000,
"Prompt" => /^CMD>$/)
$device.cmd(params[:cmd]) {|c| $output << c}
@radar
radar / gist:711425
Created November 23, 2010 07:52 — forked from anonymous/gist:711420
device ||= Net::SSH::Telnet.new("Host" => "192.168.0.2",
"Dump_log" => "dump_log3",
"Username" => "admn",
"Password" => "",
"Timeout" => 60000,
"Prompt" => /^CMD>$/)
device.cmd(params[:cmd]) {|c| $output << c}
<%= form_for @user do |f| %>
<%= f.fields_for :address do |address| %>
<div class="field">
<%= address.label :street %><br />
<%= address.text_field :street %>
</div>
<% end %>
== MODEL ==
// do a check here to verify the requested subdomain is available
def subdomain_is_unique
business = Business.where( "lower(subdomain) = ?", subdomain.downcase ).first
if !business.nil?
errors.add( :subdomain, 'is already in use' )
else
We couldn’t find that file to show.
@radar
radar / gist:742770
Created December 15, 2010 23:25 — forked from Brook/gist:742767
class TopicAssociation < ActiveRecord::Base
belongs_to :user
belongs_to :topic
after_create :calculate_popularity
validates_uniqueness_of :user_id, :scope => :topic_id
def calculate_popularity
self.popularity = TopicAssociation.count(:all, :conditions=>{:topic_id => self.topic_id})
require 'spec_helper'
describe Bid do
before(:each) do
@user = Factory(:user)
@user.funds = 10
@user.save()
@prediction = Factory(:prediction)
@attr= {
:user_id => @user.id,