Programming
Agile (XP) Game
Feb 1st
Last week we had the excellent opportunity to host the agile, XP planning game at Plug and Play in Midvalley, KL. We had a lot of fun, and from what we saw after the game, so did the participants – it’s a great ice breaker, and great learning tool to understand the complexities of XP Iterations. We took pictures too, and they can be found here!
At the end of the games, a bunch of the participants asked us about our presentation slides. We had feedback that the slides were awesome – as the instructions were very clear – and we’re glad to hear it was so
. As a consequence, we’ve uploaded our slides on scribd (it’s being processed, so check back soon for a link! UPDATE: here it is!)
If you’re interested in organizing the game for your organization, you can check out Vera Peeter’s (Tryx) and Pascal Van Cauwenberghe’s (Nayima) XP game setup. If you want us to host it (which we’d be happy to
) you can contact us here
If you participated in the games we had last week, tell us what you think in the comments below!
Useful git tutorials
Jan 19th
We’ve been using git for as our version control management system since the day we started, and have never looked elsewhere. It’s fast and easy to use and with github, it’s even gone social!
So, for those of you who have heard of git, but don’t really know how it works, and are interested to learn, here are some of the very useful git tutorials that have helped us with our understanding of git and how to work with it.
Of course, the biggest repository for git tutorials is Gitcasts, but our favorite from that lot is Scot Chacon’s git talk at RailsConf 2008
Other good tutorials sites are:
http://net.tutsplus.com/tutorials/other/getting-the-hang-of-github/
http://net.tutsplus.com/videos/screencasts/terminal-git-and-github-for-the-rest-of-us-screencast/
http://www.gitready.com/beginner/2009/03/09/remote-tracking-branches.html
Happy learning! If you’ve got other git resources you liked, put them in our comments and we’ll be happy to update our post with it!
Ruby Version Manager
Oct 23rd
I’ve been meaning to start using ruby1.9 but always stuck at maintaining codes in production that depends on Ruby1.8.6. Fortunately, there’s this thing called Ruby Version Manager where you easily change between different rails version. I have nothing but praise for the guys who made life easier for us programmers to do our job better & faster with RVM.
The only thing is you have to install your gems for each ruby version. It does make sense because there are quite a few gems that depends on different built. Installing gems are not that hard imho. So no issue there.
Now I can change between different ruby version as easy as this:
$ rvm 1.9.1 # For ruby 1.9.1
$ rvm 1.8.7
What’s excellent about this is the ruby version is sandbox in just that one terminal you’re using. It doesn’t interferes with your already *original ruby installation. * rvm calls is your ruby system. To revert back to your original ruby installation just do
$ rvm system
Or if you want to set a default ruby throughout your system. You can simply do so like this:
$ rvm 1.9.1 –default
If you haven’t tried it before, go try it. Don’t worry, it won’t mess up anything on your current ruby system
Authlogic is Awesome
Oct 22nd
Have been tinkering around with authlogic. The most I love about is its out-of-the-box functionality. I used to wrestle with restful_authentication to get certain things that I need. Not in anyway that I’m bashing it but seeing how easy authlogic I couldn’t believe why I didn’t use it sooner.
I like it so much that I even made a rails template base on authlogic. This rails template has the usual basic signup/login/logout and I threw in some cucumber steps & stories in it. Here it is in flesh & bytes http://github.com/fadhlirahim/myrails-template/blob/master/template_authlogic.rb
Div’s does not wrap tr’s
Sep 16th
I tried to update a HTML div elevement wrapping around a table row inside a table.
<table> <tr> <td>Pomme</td> </tr> <div id="placeholder"> <tr> <td>SomethingElse</td> </tr> </div> </table>
I wasted 1 hour to find out why my ajax calls aren’t updating the right table row.
Apparently it’s not valid HTML. The div will always be on top and then the table tag.
A workaround that I found to put a placeholder id inside a table is by using <tbody>. So simply substitute the div with a tbody tag and you’re done.
My little contribution to a rails plugin (sort of)
Jun 14th
Getting your bug fix/code pulled into the main repo really gets you excited & satisfied.
I never thought it could give me this much sense of enjoyment. Check it out.
Includes & Eager Loading
Jun 8th
I’m figuring out something in my rails app. I’m figuring out which one’s the worst:
Eager loading 100 rows of data you don’t actually need at the moment
or
10 queries giving 10 result set at once?
Here’s the code to explain it.
1 2 3 | @event = Event.find(params[:event_id]) @event_attendees = @event.attendees.paginate(:page => params[:page], :per_page => 10) |
In the view, for each attendees, it’s calling a purchase record. Since I’m using will_paginate and setting 10 records per page, for every 10 record of attendees, there’s 10 queries for a purchase record. Here’s the following SQL that will be generated:
1 2 3 4 5 6 7 8 9 10 11 12 | SELECT * FROM `attendees` WHERE (`attendees`.event_id = 4) SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 1) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 2) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 3) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 4) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 5) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 6) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 7) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 8) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 9) LIMIT 1 SELECT * FROM `purchases` WHERE (purchasable_type = 'Attendee' AND purchasable_id = 10) LIMIT 1 |
Clearly you can that see the above code creates a n + 1 problem.
So I tried to modified it using eager loading like the following:
@event_attendees = @event.attendees.paginate(:include => :purchase, :page => params[:page], :per_page => 10)
Here’s the following SQL query generated:
1 2 3 | SELECT * FROM `attendees` WHERE (`attendees`.event_id = 4) SELECT `purchases`.* FROM `purchases` WHERE (`purchases`.`purchasable_id` IN (1,2,3,4..100) AND `purchases`.`purchasable_type` = 'Attendee') # query is shorten for brevity |
You can see that it’s using 1 query that fetches 100 rows of data. At first I thought that it will limit the eager loading with my will_paginate per page settings. But clearly for every page that I’m viewing, it’s calling that query hence returning 100 rows of data for each page I’m viewing.
At the moment I’m using the query without eager loading. Simply because I’m concern the app is fetching 100 rows that I don’t need at once. I have no idea how to limit an eager loading association base on will _paginate per_page. Or probably I could eager load once and keep in cache. Or does rails does that automatically?
Will investigate though. Oh well, back to work!
Routes Gotcha
Dec 18th
Something peculiar happened when I was doing something trivial.
If you accidently named your restful route the following
resource :roles instead of resources :roles
When you point your app to /roles it won’t go to your index controller action but it will instead call your show action.
git svn can't locate SVN/Core.pm
Dec 7th
I had a problem when running git svn command on my ubuntu.
Can’t locate SVN/Core.pm in @INC
It turns out all I had to do is install libsvn-perl.
Rebuilding Ferret Index
Nov 20th
I had trouble reindexing the ferret index using the rake command (rake ferret:rebuild). I got this non-descriptive error regarding failing to rebuild it (Even in my development mode). So after googling for it, all one has to do is so simple.
Go into your rails script/console and just type
Model.rebuild_index
And you’re done.

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=4390e2e2-1ab5-480f-a48f-6a49d2422156)

