Archive for the 'Ruby' Category

Tasty Crunching on LearnHub

Jun 11 2008 Published by under English,Ruby,Toronto

We’ve redesigned our homepage:

And get TechCrunched:

Tasty!

No responses yet

RailsConf 2008 Summary and Review

Jun 11 2008 Published by under English,Ruby,Toronto

We three of us in Learnhub, Wesley Moxam, Carsten Nielsen and my self have attended RailsConf 2008 last weekend. It was a great event for sure. After came back, we did a presentation for Toronto Ruby on Rails Project Night yesterday. Here is the presentation file which we’ve used:

More details are on LearnHub Rails Community:

RailsConf 2008 Summary and Review

No responses yet

DHH & Libin

Jun 03 2008 Published by under English,Ruby

DHH & Libin, originally uploaded by Wes and Faye.

Thanks to my dear co-worker Wesley took this nice picture for me!

It was after David has finished his Keynote in RailsConf 2008.

No responses yet

RailsConf 2008

May 29 2008 Published by under English,Ruby

Stay tuned! More details about RailsConf 2008 will be here soon.

See you in Portland! :D

One response so far

(Re)Enable TextMate Ruby Bundle

May 11 2008 Published by under English,Mac,Ruby,Software

We all love TextMate, by all means. It is the best friend for Ruby Developers.

After our project upgraded to Rails 2.0+ at LearnHub.com, I noticed that there are some very powerful Ruby Bundle Commands just stopped working. Especially these two:

  • Run Focused Unit Test

This is an awesome lovely command in Ruby Bundle, absolutely my favorite! It allows you to run a single unit test out of a whole suite of tests by simply positioning your cursor into the test you’d like to run.

  • Run Rake Task

This is another cool command too. It shows a popup window which list all the available rake tasks you have and it will show a pretty HTML result window after you choose from the list.

This thing really bothers me a lot. I could be fine for the second one, as I do have terminal windows open all the time. But I really really miss the first one, as our test files get longer very soon.

I have to make it work!

After couple of hours trying today, I’ve pretty much got the right reason and the simple solution, for now.

The reason is that TextMate includes its own version of builder.rb, which is conflicting with Rails 2.0′ version of builder.rb.

The simple solution:

  1. Open TextMate Bundlers Editor
  2. Find Ruby -> Run Focused Unit Test
  3. Search for RUBYLIB=”$TM_BUNDLE_SUPPORT/RakeMate${RUBYLIB:+:$RUBYLIB}”
  4. Change to RUBYLIB=”$TM_BUNDLE_SUPPORT/RakeMate”
  5. Reload Bundlers

That’s it! And apply the same changing method to other commands such as “Run Rake Task” as well.

And just want to point out the alternate solution is:

mv /Applications/TextMate.app/Contents/SharedSupport/Support/lib/Builder.rb /Applications/TextMate.app/Contents/SharedSupport/Support/lib/Builder.rb.bak

It’s up to you to choose one of them.

Hope Google can pickup this post quickly so we can save somebody else sometime too. :)

Enjoy!

3 responses so far

Nested Namespace in Rails 2.0

Apr 13 2008 Published by under English,Ruby

$> mate config/routes.rb

map.namespace :admin do |admin|
  admin.resources :user
end

$> rake routes

admin_user_index GET    /admin/user
  {:controller=>'admin/user', :action=>'index'}
......

$> mate config/routes.rb

map.namespace :admin do |admin|
  admin.namespace :user do |user|
    user.resources :profile
  end
end

$> rake routes

admin_user_profile_index GET    /admin/user/profile
  {:controller=>'admin/user/profile', :action=>'index'}
......

No responses yet

Update RubyGems to new Version on Leopard

Apr 03 2008 Published by under Apple,Mac,OS X,Ruby

RubyGems just updated to version 1.1.0. Couple of the major changes are “Index updates are much faster now” and “only updates from a latest index by default”. So, time to update.

As Leopard already has Ruby and RubyGems preinstalled (Thanks, Apple!). So the default update way:

$ sudo gem update –system

will NOT work well.

Here is what you should do on Leopard 10.5.2:

$ sudo gem install rubygems-update
$ sudo update_rubygems

Enjoy!

8 responses so far

First day in LearnHub

Mar 17 2008 Published by under English,Ruby

Today is the day!

It’s my first day in LearnHub. Pretty exciting! Time to have fun with Ruby on Rails fulltime!

Here is our development team at March 17, 2008:

Want to know more?

No responses yet

Fizz, buzz, fizzbuzz

Feb 06 2008 Published by under English,Ruby

I was hit by a simple question today: write a fizzbuzz in ruby. Pretty fun anyway.

What’s Fizzbuzz?

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

I started from this:

class Fixnum
...
end

I think it was a little overkill and slow the coding speed a lot. Here is the result:

def fizzbuzz
(1..100).each { |item|
puts print_value(item)
}
end

def print_value(item)
print_value = ''
print_value += 'Fizz' if item.div_by_3?
print_value += 'Buzz' if item.div_by_5?
print_value.empty? ? item : print_value
end

class Fixnum
def div_by_3?
self % 3 == 0
end

def div_by_5?
self % 5 == 0
end
end

fizzbuzz

Here are some simple samples from internet:
One liner:

1.upto(100) { |n| puts n % 3 == 0 ? n % 5 == 0 ? "fizzbuzz" : "buzz" : n % 5 == 0 ? "fizz" : n }

Another one liner:

puts (1..100).to_a.collect { |i| i % 15 == 0 ? ‘fizzbuzz’ : (i % 5 == 0 ? ‘fizz’ : (i % 3 == 0 ? ‘buzz’ : i)) }.join(’ ‘)

One more one liner

puts (1..100).map{|i|i%15==0?’FizzBuzz’:i%5==0?’Buzz’:i%3==0?’Fizz’:i}

Regular one, pretty close to mine:

(1..100).each{|i|
x = ''
x += 'Fizz' if i%3==0
x += 'Buzz' if i%5==0
puts(x.empty? ? i : x);
}

Want to know more?

  1. Coding Horror:  Why Can’t Programmers.. Program?
  2. Imran On Tech: Using FizzBuzz to Find Developers who Grok Coding
  3. Wikipedia: Bizz buzz
  4. RubyQuiz: FizzBuzz (#126)

Go back to practice more, and more…

2 responses so far

« Prev