Thursday, September 10, 2015

Homebrew Warning: You have an outdated version of /usr/bin/install_name_tool installed

When using homebrew, you may encounter this error when you run brew doctor :
Warning: You have an outdated version of /usr/bin/install_name_tool installed.
This will cause binary package installations to fail.
This can happen if you install osx-gcc-installer or RailsInstaller.
To restore it, you must reinstall OS X or restore the binary from
the OS packages.


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.

Thursday, December 20, 2012

Rails 2.3 after_create callback doesn't rollback even if returned false

So, this is another mind-boggling thing i came across yesterday. I am working on rails 2.3.11

So i had some after_create callbacks on my app's Order model.

The problem i faced was even when the callbacks would fail, the order was still created and the changes would't ROLLBACK!!

Thursday, November 1, 2012

Unable to install gems when using gem version 1.8.24 on windows


So, i just upgraded my ruby to 1.9.3, and installed the latest gem version 1.8.4.

After installing DevKit and everything i tried to install rails on my system. I wrote

gem install rails

and after a second got this error

ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    SocketError: getaddrinfo: No such host is known.  (http://rubygems.org/latest_specs.4.8.gz)

ERROR:  Could not find a valid gem 'rails' (>= 0) in any repository
ERROR:  Possible alternatives: rails

Sunday, October 28, 2012

Unable to boot into Fedora 17 after upgrading windows 7 to windows 8

Okay, so today i thought of upgrading to the new and improved Windows 8 on my Fedora17 and Windows7 dual boot laptop.

It was a tiring process and took a lot of time, and after finishing the upgrade and playing with Win8 a little, i restarted my system to do some work on Fedora, but after restarting, Win8 started by itself, there were no options to select any option to boot into linux.

That was when i felt like beating myself up for upgrading windows. This feeling was much intensified after reading that Win8 uses SecureBoot and there are no ways to as of now to dual boot it.

Thursday, October 11, 2012

Get value of an attribute before being type-casted by rails

There are times when we might need the value of an attribute before rails type-casting it.

Suppose obj is the object and attrib is the attribute whose value we need before ActiveRecord type-casted it, there's a method we can use to get the value of that attribute it was before being type-casted, which works as follows: