Wed Sep 17 11:38:00 UTC 2008
flickr scaling guru cal henderson talks django and rails
this is a hilarious talk that flickr scaling guru cal henderson gave on the current state of the art with frameworks and what they are lacking. Mr. Henderson has some great comments on what is lacking with the current popular frameworks. Also, I haven't seen someone this funny give a talk in a long time. He should do standup comedy... enjoyFri Sep 12 14:51:00 UTC 2008
more on testing your tests with rcov
If you ever wondered how good your testing is doing I highly recommend seeing how much coverage your tests are fulfilling. You can do this by running rcov. It will run your tests and figure out which parts of your code are being run when you run your tests. Its pretty simple you just runsudo gem install rcov
#then from your RAILS_ROOT path
rcov -o /path/to/output/results test/unit/*_test.rb test/functional/*/*_test.rb
and you will end up getting results that SHOW things like so:
the teal color shows the code thats covered, the red, the code that is not covered by your tests. prett slick huh?
Mon May 19 17:01:00 UTC 2008
script to find and replace a string in all files and subdirectories using shell programming
#!/bin/sh
if [ $# -ne 2 ]; then
echo 1>&2 Usage: $0 [string to replace] [replacement]
exit 127
fi
for file in $(find . -type f | grep -v .svn | grep -v .jpg | grep -v .gif | grep -v .tmp | grep -v .zip
| grep -v .png | grep -v .ttf | grep -v .psd | grep -v tempfile.tmp)
do
sed -e "s/$1/$2/g" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done
for file in $(find . | grep -v .svn | grep tempfile.tmp)
do
rm $file
done
Fri Feb 01 17:39:00 UTC 2008
fast date values for fixtures
one of my annoyances while porting to rails 2 … and edge has to do with fixtures. they’ve decided to use the rathole plugin . . . but alas i was using the fixture_references plugin, and it seems they do not play nicely together. however, one thing i have learned is that i can do this:
3.weeks.ago.to_s(:db)
=> "2008-01-11 17:38:26"
>> (Time.now + 3.weeks).to_s(:db)
=> "2008-02-22 17:38:42"
>>
Tue Jan 29 13:48:00 UTC 2008
unitialized constant PASSTHROUGH exception in rails 2
You need to upgrade to ruby 1.8.6 . . .Wed Jan 09 10:44:00 UTC 2008
hacking irb and console for ruby and rails
Two things you need for your console. Imagine the following./script/console
>> helper.users_path
"/users"
#(then highlight and copy to clipboard the following code.)<br/>
>> pastie
#(browser opens to a pastie URL of the code you just copied to the clipboard<br/>
I also recommend installing wirble so you can have history in your console as well. ( sudo gem install wirble )
To get these helpful commands going in your irb or console session just add the following to your ~/.irbrc file.
# load rubygems and wirble
require 'net/http'
require 'rubygems' rescue nil
require 'wirble'
# load wirble
Wirble.init
Wirble.colorize
def Object.method_added(method)
return super(method) unless method == :helper
(class<<self;self;end).send(:remove_method, :method_added)
def helper(*helper_names)
returning $helper_proxy ||= Object.new do |helper|
helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize }
end
end
helper.instance_variable_set("@controller", ActionController::Integration::Session.new)
def helper.method_missing(method, *args, &block)
@controller.send(method, *args, &block) if @controller && method.to_s =~ /_path$|_url$/
end
helper :application rescue nil
end if ENV['RAILS_ENV']
def pastie
url = URI.parse("http://pastie.caboo.se/pastes/create")
parameters = {}
IO.popen('pbpaste') do |clipboard|
parameters["paste[body]"] = clipboard.read
end
parameters["paste_parser"] = "ruby"
parameters["paste[authorization]"] = "burger"
pastie_url = Net::HTTP.post_form(url, parameters).body.match(/href="([^\"]+)"/)[1]
IO.popen('pbcopy', 'w+') do |clipboard|
clipboard.write(pastie_url)
end
pastie_url
system("open " + pastie_url)
end
Tue Dec 11 11:01:00 UTC 2007
testing your tests in rails
Wed Dec 05 18:15:00 UTC 2007
rails inserts heinous html sometimes
Using button_to in rails inserts unnecessary div tags into your html and i recommend using the following override code in your application helper.def button_to(value, link, options={})
if not options.empty?
return super(value, link, options)
end
return "<input type=\"button\" value=\"#{value}\" onclick=\"location.href='#{url_for(link)}'\"/>"
end
That way you get clean return values like
<input value="Submit" onclick="http://yoururl.com" />
rather than getting:
<div>
<form method="post" action="http://yoururl.com" class="button-to"><div><input type="submit" value="Publish it" /></div></form>
</div>
However this doesn't solve the method post problem
Mon Dec 03 18:54:00 UTC 2007
Controller Partials in rails
I've noticed lately that I reuse a lot of code between controllers, in some cases entire methods. What if you could do something likedef comment_posted
<%= render :controller_partial => 'common/blog_posted' %>
end


