Every Dog has one Blog


ruby tips-and-tricks

Long integer literals in ruby

Posted on .

I am here to share a small tip that I just come to know about Ruby. A simple question. How many zeros are there integer written below?


Difficult to count right? In normal day to day practice, we generally use a comma to separate the digits, for example in US standard we use a comma every 3 digits. So number written above can be re-written as:


Now the same thing can be done with long integers in Ruby using an underscore, something like this:


which is actually same as writing 100000000000, but using underscore makes things easier to read;)

I hope you will find this technique somewhere useful ;)


blog sourcecode

Released the code running codebeerstartups

Posted on .

I got a couple of requests to release the source code running this blog as few people liked the theme :) Glad to hear that. I am sorry for being so late to release the code.If you want to download the code feel free to fork the repo from github. Design credits go to my friend Taroon Tyagi.


  • Heroku as a server
  • Octopress as blogging platform
  • Couple of gems to make things working.

I hope people will find it useful. In case you face any problem to this code up and running. Feel free to contact me.


performance improvements ruby-on-rails

The Law of Demeter for ruby on rails

Posted on .

According to the law of Demeter, a model should only talk to its immediate association, don’t talk to the association’s association and association’s property, it is a case of loose coupling.

##Bad Smell

class Invoice < ActiveRecord::Base
  belongs_to :user

<%= %>
<%= @invoice.user.address %>
<%= @invoice.user.cellphone %>

In this example, invoice model calls the association(user)’s property(name, address, and cellphone), which violates the law of Demeter. We should add some wrapper methods.



Keeping ruby on rails model DRY - MetaProgramming

Posted on .

If you find some methods whose definitions are more or less similar, only different by the method name, it may use meta programming to simplify the things to make your model more clean and DRY.

Consider this simple example where we have an article with three states.


paperclip performance optimizations

How to optimize image uploaded via paperclip

Posted on .

Previously I wrote a post for saving image as progressive image, continuing the same, here is and another gem to reduce the size of the progressive image.

gem "paperclip-compression","~> 0.1.1"