Skip to content

Instantly share code, notes, and snippets.

View tiegz's full-sized avatar
👋
Working from home

Tieg Zaharia tiegz

👋
Working from home
View GitHub Profile
response body => \037\213\b\000\000\000\000\000\000\0033624550\006\000,/\327T\a\000\000\000
net/http interpretation => 3624550,/?T
response body => \037\213\b\000\000\000\000\000\000\0033624550\001\000\217\272\263\312\a\000\000\000
net/http interpretation => 3624550????
response body => \037\213\b\000\000\000\000\000\000\0033624550\005\000\031\212\264\275\a\000\000\000
net/http interpretation => 3624550???
response body => \037\213\b\000\000\000\000\000\000\0033624550\a\0005\353\272S\a\000\000\000
# Rails 2.3.2
# Ruby 1.8.6
# Appears to be weirdness when you override a class method that
# is also a method_missing finder. Check out the SQL output:
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts, :force => true do |t|
t.string :title
end
def loggable(logger)
@@logger = logger
def method_missing(meth, *args)
if meth.to_s =~ /^log_/
@@logger.info "#{Time.now.to_s} - #{meth.to_s.split('_')[1..-1].join(' ')}"
else
super
end
end
end
@tiegz
tiegz / gist:111107
Created May 13, 2009 16:25
An alternative to String#next/#succ for incrementing strings
describe String do
describe "#increment and #increment!" do
it 'should increment nothing to 1' do
"Something".increment.should == "Something1"
end
it 'should increment the digits in the string' do
"789".increment.should == "790"
end
# Put this in your app config to omit the div that wraps error fields in form_for
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag }
class Statistic < ActiveRecord::Base
named_scope :by_month_and_year, :select => "DATE_FORMAT(created_at, '%b %y')", :group => "DATE_FORMAT(created_at, '%b %y')", :order => :created_at
end
>> Statistic.by_month_and_year.size
=> 6 # SELECT count(DATE_FORMAT(created_at, '%b %y')) AS count_date_format_created_at_b_y FROM `statistics`
>> Statistic.by_month_and_year.all.size
=> 5 # SELECT DATE_FORMAT(created_at, '%b %y') FROM `statistics` GROUP BY DATE_FORMAT(created_at, '%b %y') ORDER BY created_at
module TrueFalseComparison
def <=>(other)
return nil if ![TrueClass, FalseClass].include?(other.class)
self.is_a?(FalseClass) ? (other.is_a?(TrueClass) ? -1 : 0) : (other.is_a?(FalseClass) ? 1 : 0)
end
end
TrueClass.send(:include, TrueFalseComparison)
FalseClass.send(:include, TrueFalseComparison)