Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
#!/usr/bin/env ruby
# My name is Nate Sutton
# I work for Sevenwire <http://sevenwire.com>
# Redis, yet another key-value store:
# * Dataset is non-volatile (unlike memcached)
# * Has four datatypes (unlike memcached, which just has string)
!!! What benchmark? You had to have seen that number somewhere? People get off on that kind of crap.
# * Fast. One benchmark put it at 110k SETs/s and 81k GETs/s. (lies, damned lies, and benchmarks)
## With this code instead of passing a file and being a file object in the params like:
## Parameters: {"commit"=>"Save changes", "authenticity_token"=>"CNHWuiMsSkwK4x3biFGogUnRU2kutvKuCfOTH2Y+PO4=", "painting"=>{"image"=>#<File:/tmp/RackMultipart20100102-3131-9c0z0-0>}}
## it passes just a name of the file like so:
## Parameters: {"action"=>"create", "authenticity_token"=>"atvaDTdf2yhQKea8t/VBhYyT2ENyK9B/ZYGQSRq9414=", "painting"=>{"title"=>"g", "height"=>"1", "picture"=>"Tweetie.gif", "width"=>"1"}, "controller"=>"admin/paintings"}
## Model
default_url_options[:host] = host
def host
Rails.env.development? ? "localhost:3000" : "www.sociapad.com"
end
@radar
radar / gist:302425
Created February 12, 2010 08:50 — forked from anonymous/gist:302424
tags = "blue:1,red:2,purple:3"
output = {}
tags.split(/,/).each{|i|o=i.split(/:/); output[o[0]]=o[1]}
@radar
radar / gist:303831
Created February 14, 2010 04:18 — forked from anonymous/gist:303827
after_filter :setup_generic_variables
def setup_generic_variables()
@controller_name = self.controller_name
@model_name = controller_name.singularize
@instance = instance_variable_get('@'+@model_name)
@edit_path_method = 'edit_' + @model_name + '_path'
@index_path_method = @model_name + '_path'
end
@radar
radar / gist:313320
Created February 24, 2010 10:33 — forked from anonymous/gist:313306
FILTER_TYPES = ['Race', 'Gender']
FITLER_TYPES.each do |ft|
define_method "#{ft.underscore}_names=(new_names)" do
# stuff here
end
end
aasm_event :finish do
transitions :to => :sold, :from => [:active], :guard => Proc.new {|a| a.reserve < a.price}
transitions :to => :unsold, :from => [:active]
end
class CommentsController < ApplicationController
def index @account = Account.find(params[:account_id]) @comments = @account.comments
end
def show @account = Account.find(params[:account_id]) @comment = @account.comments.find(params[:id])
end
def new @account = Account.find(params[:account_id]) @comment = @account.comments.build
end
def create @account = Account.find(params[:account_id]) @comment = @account.comments.build(params[:comment])
if @comment.save redirect_to post_comment_url(@account, @comment)
#failing with undefined method `association_join' for class
#`ActiveRecord::Associations::ClassMethods::JoinAssociation'
/*
Here's a patch to rails that fixes it's failure to quote a table name in one branch
of this monster case statement.
Meanwhile - i'm trying to get this monkeypatch working.
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -2163,10 +2162,10 @@ module ActiveRecord
foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
@radar
radar / t.rb
Created June 28, 2010 00:25 — forked from tanob/t.rb
def cached_result opts
puts opts
end
cached_result :for => 'bleh', :or => lambda { 1+2 }