Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
class AddPriceToProduct < ActiveRecord::Migration
def self.up
add_column :products, :price, :decimal,
:precision => 8, :scale => 2, :default => 0
end
def self.down
remove_column :products, :price
end
end
## /users/edit.html.erb
<% form_for [:cp, @user], :url => { :action => 'update', :id => @user.id } do |f| %>
...
<%= collection_select :users, :show_id, Show.find(:all), :id, :name, { :prompt => true } %>
## users_controller.rb
@user.shows << Show.find(params[:users][:show_id])
## error
ActiveRecord::AssociationTypeMismatch in Cp/usersController#update
class Date
def to_words
today = Date.today
case self
when today
"Today"
when today - 1
"Yesterday"
when today + 1
@radar
radar / gist:13400
Created September 28, 2008 02:26 — forked from anonymous/gist:13399
class SubscriptionConfirm < ActiveRecord::Base
@@confirm_sent = Hash.new
def initialize(params = nil)
super(params)
set_default_values
end
def self.subscribe_to_newsletter(params = nil)
@radar
radar / gist:33867
Created December 9, 2008 10:30 — forked from anonymous/gist:33866
desc 'Create YAML test fixtures from data in the existing database.'
task(:extract_fixtures => :environment) do
sql = "SELECT * FROM %s ORDER BY desc(id) LIMIT 10"
skip_tables = ["schema_info", "badges", "badge_groups", "html_links", "hero_plus_status_updates"]
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
i = "000"
File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|
data = ActiveRecord::Base.connection.select_all(sql % table_name)
file.write data.inject({}) { |hash, record|
Hello,
We are http://whol.ly , an ambitious startup based in NewYork with our
new development centre in Bangalore. While you are reading this, we
are making tiny steps towards innovation in the world of social
networking. Our goal is to let people discover and participate in
their local life by exchanging services, organising events and meeting
new people, all for fun and better living. This brings us into amazing
situation where we are surrounded by interesting engineering problems
which are technologically unique and socially relevant.
# Original from Mitchell
def self.first_uninteresting
all_numbers = Number.find(:all).map { |entry| entry.number }.sort
last = 0
all_numbers.each do |number|
if number != last + 1
return last + 1
end
last = number
%a.selected{:href => name, :class => ("selected" if @category == name)}
%span= name
njero - http://neverlet.be
sutto - http://blog.ninjahideout.com
zapnap - http://blog.zerosum.org
tpope - http://tpope.net
reinh - http://reinh.com
bryanl - http://smartic.us
linoj - http://www.vaporbase.com
technicalpickles - http://technicalpickles.com
MaD15 - enlightsolutions.com/
qrush - http://litanyagainstfear.com/
# http://mozy.com/contest
# Question 4
# chendo's solution
require 'benchmark'
year = 0
fibs = [2, 0, 0, 0, 0] # age 0, 1, 2, 3, 4
adults = 0 # age > 5
Benchmark.bm do |bm|