Halp!

If you were to buy a good laptop, what would it be?

Update: August 03, 2007
Finally decided to buy Macbook Pro only. I love it.

Pownce Invites!

I have around 7 Pownce invites. If you are interested, please let me know through the comment form. I would send invite to the first seven now, keep sending later. Please put right email address in email-field of comment form below.

VIM for Ruby on Rails development

 

I use VIM editor for coding Ruby on Rails. I am very proud of it. I liked VIM editor when I started used it long ago. In my college we had subjects which involved writing all C programs on Linux/Unix machines. We would use VIM editor for it.  From that time, I got involved in VIM.  Actually many colleagues at that time considered it as VI editor but it was VIM(VI-Improved), the only command we typed was VI and it opens VIM on Redhat machines.

When I started my career with ROR, nearly 1 year back. I was not aware of using a specific editor for coding. I started with TextPad, everything was fine with it. Then I came to know about RadRails from my Boss (Shashank Date, he visited Rails Conf 06 and met with the guys who developed RadRails plugin for Eclipse). So I downloaded RadRails and started using it. It was buggy at that time. Many features were not working as expected. I quit using RadRails very soon and came back to TextPad.

After sometime, I was working on my first paid project. I was using TextPad that time. I found the need of a nice IDE for development as I had to navigate through many files as fast as I can. TextPad was not proving to be the best. I decided to use Eclipse with RadRails plugin this time. RadRails was more stable this time. And it proved to be the one only best IDE for Ruby on Rails.

But after some weeks, I found the need of fast editing a single file. I was tired of pressing arrow keys to navigate through file. I thought to give VIM a try. I downloaded it and started using it. I configured my vimrc for Ruby development. Initially it took some days to get familiar and have habit of using VIM to my hands. This time I used VIM a lot. Days went…

At MangoSpring, initially we decided to use common development environment. We chose Eclipse as IDE. My colleagues here were familiar with Eclipse and with RadRails, it became more easy for them. I helped to setup Eclipse for Rails development. And still all of them are using Eclipse with RadRails for Rails development. :) But I already very much addicted to VIM, I chose to use VIM as my editor/IDE.

I am not going in details of how to use VIM for editing, but following are some tips, plugins, configurations that I use for VIM as Ruby on Rails editor. Getting knowledge of these plugins and tips will help you improve typing code for ROR.

plugins that I use.

rails.vim : This plugin adds many commands and shortcuts specific to Rails development. It is one of the best VIM plugins I have found. see link for more info. It is written by Tim Pope(nice guy, helps a lot, specially you can find him in #rubyonrails and #vim irc channel on irc.freenode.net).

matchit.vim : This is a must. It helps you using % to match or traverse through if else end, ( , ), and {, }. It helps a lot. Even Eclipse with RadRails don’t have such feature. :)

blockcomment.vim: select some block of code in visual model and just press .c to comment it and .C to uncomment it. Saves time.

colorschemes that I like the most.

oceandeep : If you care about eyes, you must have light dark background for the text editor.  As white background can damage your eyes. I decided to use this colorscheme as I found frequent aching of eyes due to white background. I recommend it for VIM.

vividchalk : If you are familiar with TextMate, and if you saw which theme most people use for Rails development, it is Vibrant Ink. Vividchalk is based on Vibrant Ink theme for TextMate. It’s very nice to see Ruby and Rails code in vividchalk. I use it sometimes.

some configurations.

Ctags: You use VIM and you don’t know about Ctags. Oh yeah, it’s possible. Even I did not know about ctags for long time. Abdul told me how he uses ctags, some months back. And now I can’t think VIM without ctags. I feels it should be the part of VIM setup. Ctags allows you to browse through your source code in a very efficient manner. You have to generate a tags file for your project code. And then you will be able to traverse through classes, methods, variables of your code. You just have to press Ctrl + ] on a method name and it takes you to that method. Similar for class names and variables.

vimrc: Instead of telling you, how I configured my vimrc. You can checkout latest version of it from Google code repository. It is well commented there.
You have to configure it again, as it is mostly compatible to my machine.

svn checkout http://my-vimrc.googlecode.com/svn/trunk/my-vimrc

vim-ruby gem: you can install this gem using command “gem install vim-ruby” and then you can go to the directory and run script which configures VIM for ruby development and adds some plugins (vim-ruby-install.rb). Well, It works with rails.vim plugin.

other useful links:

http://rails.vim.tpope.net/
http://wiki.rubyonrails.org/rails/pages/HowtoUseVimWithRails
http://del.icio.us/anildigital/vim
http://del.icio.us/popular/vim

Barcamp Pune 3

Writing this post at night after organizing the Barcamp Pune 3 today. Almost every Barcamp I attended is memorable event for me and this Barcamp is no exception.

I went to Persistent Building (near Nal Stop, Karve Road, Pune) early in morning, there I met with Jatinder, Kiran, Hrishikesh. The registrations were on 7th floor and sessions on 4th floor. I helped in setting-up things, registrations, distributed stuff (T-shirts, notepads, …), helped campers to find what they wanted. This time campers response was very good. Most of the campers came on time and they had nice breakfast after registrations.

I attended most of sessions. Two sessions were of Rakesh Raju ( first was about tvguide.in(seems a Rails app) and other was about Game development). Both were good ones and quite informative.

Aditya gave a session about Mircosoft Silverlight (if you are hearing it for the first time, you are missing something). I liked demos which he showed. One thing he told that, Silverlight is not like flash in which the swfs are compiled and that’s why search engines cannot crawl it. But Silverlight uses something called xaml, which is crawlable and search engines would be able crawl it. If it is like that then it is definitely nice thing than flash, but I don’t know much about the details.

Most of time in between slots went in meeting people and in discussing about coolest technological things. All people were interesting ones. I specially liked to meet friend Akshay. We are in touch for long time and meeting personally was cool experience. We discussed about some tech topics. I got excited to hear his future plans and his working habits. We also had lunch together.

My company presented two sessions at Barcamp this time. One was by Anjali, Oraganization 2.0 ( which I missed :-( as I was attending Freeman’s talk) but was very good as told by my colleagues). The other was by Isha about Push technology Comet. I think it was one of the best sessions of this Barcamp.

Decided already, attended Freeman’s session (Freeman is very nice person, I like him). It was about open source education. At first I got confused about the word open source education, I though it must be about open source software, but it meant free learning material for people. It was the best session of the day. I like his thoughts (one sentence of his I liked today is “your certificate is how you are shown up on Google, instead of having real certificates or three to four ending lines on resume, we can know more about a person by his Google results“, makes sense). Came to know about nice website http://codekata.pragprog.com beacuase of him. I also discussed with him at the end of day about the concept of open source education.

One talk which I was planning to give but didn’t ,was about writing a Facebook application with Ruby on Rails. But the same topic was covered by the session of Abhijit Gadgil. It was quite good one.

I also liked the session Open source beyond software by Paritosh Pungalia and Ajay Sanghni(IT Vidya man). I learned something which I never thought of.

At the end of day, I had photo sessions, one with my company colleagues and the other was with all organizing guys. I will try to update this post with the flickr links as I get those photos.
………………………

Update: 9th July, 2007

We, organizers
BarCamp Pune 3 organizers

Link to above photo: http://www.flickr.com/photos/coolfrog/754190822
Other related to organizers
All Barcamp Pune 3 photos

Update: 13th July, 2007

We Springsters (MangoSpring-sters)

Link to photo http://www.flickr.com/photos/anildigital/773769699
………………………

Rahul and Vikrant were with me whole day. We had plenty much discussions through-out day. We traveled together while returning with our bikes.

I was supposed to give the discussion topic about how to use VIM for Ruby on Rails development, which I couldn’t due to no free time slots. I already have written a post about it. I am going to make some minor changes to it and will post it on Monday as I am going to visit Lonavala with my friends tomorrow.

Group results by week, month using group_by

I have a table named stats made up of two important columns ’stat_type’ and ‘count’. We run a rake task which populates TaskBin related statistics at the end of every day into the stats table. Column count holds count of users signed up per day is stored.

To generate the report, I fire the query from my controller action as

@stats = Stat.find(:all, :conditions => ["stat_type = 'signup_confirmed'"])

These model objects(@stats) are stored as per day basis. Now, I need to display the @stats grouped by month and grouped by week.
Rails enumerable class has a method called group_by which is very super-powerful and allows us to group, active record objects by a passed parameter.

So here is the code which I wrote.

Add the following methods in model ( in Stat model),

def week
  self.created_at.strftime("%W")
end

def month
  self.created_at.strftime("%y%m")
end

Now just add following two magical lines in same controller action

#returns a hash, with key as week number and value as grouped results as array.
@weekly_stats = @stats.group_by(&:week)
@monthly_stats = @stats.group_by(&:month)

(one point, use of &: is dangerous as pointed out by Pratik, you can use @stats.map{|i| i.week} and @stats.map{|i| i.month } instead of &: symbol.

And your view code will look similar like this (shown for week only).

<% @weekly_stats.each do |week, stats| %>
  <tr>
    <td>
      Week <%= week %>
    </td>
    <td>
      <% count_array = stats.collect{|i| i.count}%>
      <%= count_array.sum %>
    </td>
  <tr>
<% end %>

I hope you enjoyed this simple trick. Do comment if you have other tricks/suggestions.
Keep tasking. visit TaskBin.com.