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
| From 1be13d1c88ca518996135e89454c17691afbcc51 Mon Sep 17 00:00:00 2001 | |
| From: Ernie Miller <[email protected]> | |
| Date: Thu, 6 Jan 2011 20:06:29 -0500 | |
| Subject: [PATCH] Fix polymorphic belongs_to associationproxy raising errors when loading target. | |
| --- | |
| .../belongs_to_polymorphic_association.rb | 5 +++++ | |
| .../associations/belongs_to_associations_test.rb | 9 +++++++++ | |
| activerecord/test/models/sponsor.rb | 2 ++ | |
| 3 files changed, 16 insertions(+), 0 deletions(-) |
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
| namespace :javascripts do | |
| desc 'minify the javascript files residing in app/javascripts to public/javascripts' | |
| task :minify do | |
| RakeFileUtils.verbose false do | |
| Dir["app/javascripts/*.js"].each do |filename| | |
| outfile = filename.sub(/^app/, 'public').sub(/\.js$/, '.min.js') | |
| puts "#{filename} -> #{outfile}" | |
| sh( | |
| 'java', | |
| '-jar', |
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
| Article.joins{person.comments}.where{person.comments.body =~ '%hello%'}.to_sql | |
| # => "SELECT \"articles\".* FROM \"articles\" INNER JOIN \"people\" ON \"people\".\"id\" = \"articles\".\"person_id\" INNER JOIN \"comments\" ON \"comments\".\"person_id\" = \"people\".\"id\" WHERE \"comments\".\"body\" LIKE '%hello%'" | |
| Person.where{(id + 1) == 2}.first | |
| # => #<Person id: 1, parent_id: nil, name: "Aric Smith", salary: 31000> | |
| Person.where{(salary - 40000) < 0}.to_sql | |
| # => "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"salary\" - 40000 < 0" | |
| p = Person.select{[id, name, salary, (salary + 1000).as('salary_after_increase')]}.first |
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
| $ godaddy buy wynn.fm | |
| -- Reading CC Info from .godaddy... | |
| -- THANK YOU FOR PURCHASING YOUR DOMAIN WITH GODADDY! | |
| -- WHILE OUR SERVERS THINK ABOUT REGISTERING YOUR DOMAIN | |
| -- NAME, PLEASE GIVE CAREFUL CONSIDERATION TO THE | |
| -- FOLLOWING SPECIAL OFFERS!!! | |
| Would you like to also register the following and SAVE 64%? | |
| wynn.net |
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
| # These are nothing fancy. Stick them in your .profile for quick access. | |
| # Tail the log of a pow application | |
| function powl { | |
| tail -f ~/.pow/"$1"/log/development.log | |
| } | |
| # Restart a pow application | |
| function powr { | |
| touch ~/.pow/"$1"/tmp/restart.txt |
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
| require 'benchmark' | |
| $LOAD_PATH << './lib' | |
| require 'arel' | |
| def grouping_any(range) | |
| literal = Arel.sql('1') | |
| literal.eq_any(range.to_a) | |
| end | |
| def grouping_all(range) |
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
| # So, a SELECT DISTINCT on some DBs requires that all order values are in the select clause. | |
| # I'm hoping there's a better cross-platform way of doing this without branching, and I | |
| # kind of think I must be overlooking something that's already built-in. | |
| # Open to suggestions! | |
| def distinct_relation(relation) | |
| offset, limit = relation.offset_value, relation.limit_value | |
| klass.select('DISTINCT subquery.*'). | |
| from(Arel::Nodes::As.new( | |
| Arel::Nodes::Grouping.new(relation.except(:offset, :limit).arel.ast), | |
| Arel.sql('subquery') |
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
| require 'benchmark' | |
| haystack = (1..1_000_000).to_a | |
| needles = 1.upto(100).map {|n| n * 10_000} | |
| module EachDetector | |
| def self.find(haystack, needle) | |
| haystack.each do |v| | |
| return true if v == needle | |
| 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
| module Enumerable | |
| def any?(&block) | |
| self.each do |v| | |
| return true if yield(v) | |
| end | |
| false | |
| 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
| rs = (0..10000).to_a.sample(30) | |
| rs.each do |r| | |
| case r | |
| when :zero?.to_proc then puts "#{r} is zero" | |
| when :even?.to_proc then puts "#{r} is even" | |
| when :odd?.to_proc then puts "#{r} is odd" | |
| else | |
| raise 'unpossible' | |
| end |