Sunday, October 27, 2013

Git: List branches on your system with time since last update

For local branches you can do this:

for k in `git branch | perl -pe 's/^..(.*?)( ->.*)?$/\1/'`; do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1`\\t$k; done | sort -r


And to check obsolete branches in the remote repo

for k in `git branch -r | perl -pe 's/^..(.*?)( ->.*)?$/\1/'`; do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1`\\t$k; done | sort -r

Wednesday, February 27, 2013

Unable to install Ruby version 2.0.0-p0 via RVM on Fedora 18

Ruby 2.0.0. version 2.0.0-p0 to be exact, was released on 24th Feb 2013 and as any Ruby programmer would do, i too tried to upgrade to Ruby 2.0.0
Fedora 18 Linux being a new OS, which too was released recently in the mid of January wasn't very helpful in the installation.

Tuesday, February 12, 2013

RSpec test failing when testing for parameters using "should_receive" and "with"

So, another weird and frustrating thing happened to me while i was running my app's tests using rspec.
I got 1 failing spec showing the following error:


Spec::Mocks::MockExpectationError in 'FeedsController#get_recent_feeds gets the recent feeds for live deals'

#[Feed:0x3fa7ffc8de1c @name="Feed_1001"] received :all with unexpected arguments
  expected: ({:include=>:feedable,  :order=>"updated_at desc, feedable_type desc"})
       got: ({:include=>:feedable, :order=>"updated_at desc, feedable_type desc"})

Monday, January 14, 2013

Get original urls from short urls created by services like bitly, tinyurl, twitter etc using ruby and open-uri

Pretty straight forward it is. Writing it here coz i couldn't find anything like this explained for ruby, found a lotta blogs for python though.

So i thought of explaining it here. So here goes. Sometimes we come across urls like http://bit.ly/y2uy321oy3 which can be for any website. There's this simple way to retrieve its original url.

The not so famous before_remove/before_add & after_remove/after_add callbacks.

Well, this is another rails feature and a quite nice one which is not documented properly.

While using has_many :through associations, we can use before_remove, before_add, after_remove, after_add callbacks.