1
2
3
4
# This is what an application build with our framework would look like.
# Run with:
#   rackup app.ru
...

Ruby Very Simple Rack framework

by macournoyer, September 14, 2008 18:11, 1 refactoring, tagged with rack

I'll be presenting http://r...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
class Fixnum
  def <=>(b)
    self % b
...

Ruby Challenge: Ugliest Ruby Fiz...

by jamesgolick, December 20, 2007 21:54, 8 refactorings

So, after seeing some ugly ...

F6eddf2f983d23c2d031e407852625e9 Talk
1
<%= (@post.category ? @post.category.name : '') + ' ' + link_to(@post.title, post_path(@post)) %>

Ruby Handling nil object

by macournoyer, November 14, 2007 02:07, 13 refactorings, tagged with rails, html

@post.category can be nil, ...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
class PostsController < ResourceController::Base
...

Ruby resource_controller: Redesi...

by jamesgolick, November 05, 2007 20:27, 4 refactorings, tagged with rails, resource, restful

Backstory on my blog: http:...

F6eddf2f983d23c2d031e407852625e9 Talk
1
2
3
4
tab() # new tab from current dir
{
osascript -e "
...

Bash Open a new tab in current d...

by macournoyer, October 04, 2007 18:07, 2 refactorings

Here's a small script I wro...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
var Rating = Class.create();
Rating.prototype = {
  initialize: function(element, rating, options) {
...

JavaScript Rating system for this site

by macournoyer, September 29, 2007 14:09, 3 refactorings

Here's the code of the rati...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
def self.requires_role(role, options={})
  before_filter(options) { logged_in? && current_user.send("#{role}?") ? true : access_denied }
end
...

Ruby On restful_authentication role...

by macournoyer, September 27, 2007 11:43 Star_fullStar_fullStar_fullStar_full

What about this:

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk

Ruby On restful_authentication role...

by macournoyer, September 27, 2007 10:45

Really good idea James, but...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
def self.requires_role(role)
...

Ruby On restful_authentication role...

by jamesgolick, September 27, 2007 10:41 Star_fullStar_fullStar_fullStar_full

So, I added this

F6eddf2f983d23c2d031e407852625e9 Talk
1
2
3
before_filter :login_required
...

Ruby restful_authentication role...

by jamesgolick, September 27, 2007 10:40, 7 refactorings

This is a couple of lines t...

F6eddf2f983d23c2d031e407852625e9 Talk
1
2
3
4
class Line
  def parse
    skip_line
...

Ruby On Arrow Code

by macournoyer, September 26, 2007 17:18 Star_full

Why not restructure everyth...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
task :extract_style do
  css = File.read 'public/stylesheets/code.css'
  css.gsub! "{\n", '{'
...

Ruby Extracting style from a CSS...

by macournoyer, September 25, 2007 21:18, 2 refactorings

Here's a Rake task I use to...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
def code
  puts 'cool'
...

JavaScript On Is this year a leap year?

by macournoyer, September 23, 2007 13:13 Star_fullStar_fullStar_fullStar_fullStar_full

Nice tip Gary! I didn't kno...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
class CodeFormatter
  cattr_reader :syntaxes
  @@syntaxes = Uv.syntaxes.sort
...

Ruby [FEATURE] Sections in code!

by macournoyer, September 22, 2007 08:44, No refactoring

Introducing a new feature: ...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
units = %w{ one two three four five six seven eight nine }

File.open('counter.txt', 'w') do |f|
...

Ruby On Sum string sizes

by macournoyer, September 21, 2007 10:13 Star_fullStar_fullStar_fullStar_fullStar_full

Welcome to the site Hampton...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk

JavaScript On Is this year a leap year?

by macournoyer, September 21, 2007 08:20

I'll try to add sections wi...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
def link_to_remote_with_spinner(title, options)
  element_id = options.delete(:id) || ('link_to_' + title.underscore.tr(' ', '_'))
  container_id = options.delete(:container_id) || element_id
...

Ruby On link_to_remote_with_spinner

by macournoyer, September 21, 2007 07:42

With the above code you cou...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
Dir["test/**/*_test.rb"].size.to_f / Dir["app/**/*.rb"].size.to_f 

Ruby On Test file to code file ratio

by macournoyer, September 21, 2007 07:34

Nice! Or even shorter, with...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
Object.extend(Date.prototype, {
  isLeap: function(){
    var year = this.getFullYear();
...

JavaScript On Is this year a leap year?

by macournoyer, September 21, 2007 07:30

I'm pretty sure the last ye...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk

Ruby On Knowing mocha

by macournoyer, September 20, 2007 12:12

Awesome! Mocha has such a n...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
def test_should_create_image_if_necessary_before_trying_to_give_it_data
  file = mock :content_type => "jpg", :size => 10, :original_filename => "something.jpg", :path => "/home"

...

Ruby On Knowing mocha

by jamesgolick, September 20, 2007 11:54 Star_fullStar_fullStar_fullStar_full

After

F6eddf2f983d23c2d031e407852625e9 Talk
1
2
3
4
def test_should_create_image_if_necessary_before_trying_to_give_it_data
  file = mock()
  file.expects(:content_type).returns('jpg')
...

Ruby Knowing mocha

by jamesgolick, September 20, 2007 11:53, 2 refactorings

Before

F6eddf2f983d23c2d031e407852625e9 Talk
1
puts `find test/ -name "*_test.rb" | wc -l`.to_f / `find app/ -name "*.rb" | wc -l`.to_f

Ruby Test file to code file ratio

by macournoyer, September 20, 2007 09:19, 3 refactorings

Hackish script to get the t...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
# With polymorphic URLs you could do
url_for(items.parents + [item])

Ruby On Linking that doesn't suck a...

by macournoyer, September 20, 2007 08:28

In edge Rails there's polym...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
1
2
3
4
def link(item, msg = nil)
  msg ||= item.send([:name, :title, :id].detect {|n| item.respond_to? n})
  method = "#{item.class.name.underscore}_path"
...

Ruby Linking that doesn't suck a...

by jamesgolick, September 20, 2007 08:16, 1 refactoring

Tammer Saleh, creator/maint...

F6eddf2f983d23c2d031e407852625e9 Talk