This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default_url_options[:host] = host | |
def host | |
Rails.env.development? ? "localhost:3000" : "www.sociapad.com" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tags = "blue:1,red:2,purple:3" | |
output = {} | |
tags.split(/,/).each{|i|o=i.split(/:/); output[o[0]]=o[1]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILTER_TYPES = ['Race', 'Gender'] | |
FITLER_TYPES.each do |ft| | |
define_method "#{ft.underscore}_names=(new_names)" do | |
# stuff here | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aasm_event :finish do | |
transitions :to => :sold, :from => [:active], :guard => Proc.new {|a| a.reserve < a.price} | |
transitions :to => :unsold, :from => [:active] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cached_result opts | |
puts opts | |
end | |
cached_result :for => 'bleh', :or => lambda { 1+2 } |