Wed Sep 17 11:38:00 UTC 2008

flickr scaling guru cal henderson talks django and rails

Posted in Geeking it up, Rails at 11:38 AM by matt

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... enjoy

Fri Sep 12 14:51:00 UTC 2008

more on testing your tests with rcov

Posted in Rails at 02:51 PM by matt

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 run
sudo 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:
C0 code coverage information
Uploaded with plasq's Skitch!
the teal color shows the code thats covered, the red, the code that is not covered by your tests. prett slick huh?
app/controllers/user/home_controller.rb - C0 code coverage information
Uploaded with plasq's Skitch!

Mon May 19 17:01:00 UTC 2008

script to find and replace a string in all files and subdirectories using shell programming

Posted in Rails at 05:01 PM by matt

#!/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

Posted in Rails at 05:39 PM by matt

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

Posted in Rails at 01:48 PM by matt

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

Posted in Rails at 10:44 AM by matt

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

Posted at 11:01 AM by matt

actually modifies your tests to verify what you’re testing

Wed Dec 05 18:15:00 UTC 2007

rails inserts heinous html sometimes

Posted at 06:15 PM by matt

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

Posted at 06:54 PM by matt

I've noticed lately that I reuse a lot of code between controllers, in some cases entire methods. What if you could do something like
def comment_posted
  <%= render :controller_partial => 'common/blog_posted' %> 
end

Sat Aug 25 17:43:00 UTC 2007

Mac OS X USB guru

Posted at 05:43 PM by matt

I'm trying to connect our *new* USB keyboard to an OS X machine and I want to gather the raw input data from it. I've got USB Prober going, but it doesn't look like I can ascertain raw input from that program alone, and frankly, I need help. If anyone is interested in seeing our new keyboard, and helping out with the driver software I'd love to cut you in on the action. I have plenty to worry about besides driver software - including but not limited to: finding some investors/and or just selling the thing. Starting on the User facing application, and creating some marketing buzz around the new product. Would love to hear if anyone is interested in coming in on this for a percentage. contact me at matt@beautifulsimplethings.com . I can give you more details about the new keyboard.

Sat Apr 21 12:16:00 UTC 2007

Welcome to BST

Posted at 12:16 PM by matt

We are Beautiful Simple Things. We beautify, simplify, and innovate new consumer electronics. We make playing Games more fun, and working with computers a beautiful thing. Currently, we are in the process of prototyping our first product. Let's just say, it's a BeaST, and we are very excited.