Debugging: What is binding in Ruby?

You might have thought always whenever you wrote code binding.pry in your application to debug your application.

People often say “do binding to see whats going on”. Actually you are not doing binding but prying into the binding. So, its good to say “Please pry into that binding”.

But, what is binding in the first place? Continue reading

Sidekiq : Not supporting Keyword Arguments

class Cancellation::ProcessorAsync
  include Sidekiq::Worker
  sidekiq_options :queue => :cancellations, :retry => 3

  def perform(requests_ids: [])


and from controller



 ArgumentError: wrong number of arguments (1 for 0)

{“class”=>”Cancellation::ProcessorAsync”, “args”=>[{“requests_ids”=>[42]}], “retry”=>3, “queue”=>”cancellations”, “jid”=>”c7fe305852080e26ae4374be”, “created_at”=>1462768111.751091, “enqueued_at”=>1462768257.4815748, “error_message”=>”wrong number of arguments (1 for 0)”, “error_class”=>”ArgumentError”, “failed_at”=>1462768111.7538342, “retry_count”=>2, “retried_at”=>1462768257.4844065}

Refactoring javascript : managing existing js code

As an web developer we always have so many problems regarding Javascript as our lines of codes in our app grow. The root cause of these problems are

  • There are so many files. In any of the files you might have missing semicolons, or used undefined variables
  • You often forget to put var before variable declaration, and this put the variable in the global scope
    • This variable might conflict with same variable name you used in other part of your code.


  $(function () {
    if ($('body.shares').length == 0 && $('body.pact_profile_page').length == 0)  return false;

  // Basic syntax would be
  $(document).ready(function () {
    var target_element_is_not_loaded = ($('.your-target-selector').length > 0);
    if (target_element_is_not_loaded) return false;

The basic idea is, you only execute your code if your targeted page is loaded. Means if your JS code is meant for posts page then you do not need to load this code else where.


Other Links

git delete all local branches except some

Sometimes after a sprint, all the remaining branches are just taking up space.
Here’s a small snippet to remove all your local branches in one go.

$ git branch | grep -v "master" | xargs git branch -D 

grep -v "master" # will exclude the `master` branch

For an easier reuse you could also alias this useful snippet.

$ echo 'alias gbr="git branch | grep -v "master" | xargs git branch -D"' >> ~/.bash_aliases

Now you only need to type `gbr` to delete all the local branches except `master` 

>>‘ will append the file with the line above

Rails : Deface : Route helpers

By default rails’s route helpers are not available in Deface module.

    <li><%= link_to "Home", home_path %></li>
    <li><%= link_to "Game", game_path %></li>
    <li><%= link_to "Community", community_path %></li>

Should be used like

    <li><%= link_to "Home", main_app.home_path %></li>
    <li><%= link_to "Game", main_app.game_path %></li>
    <li><%= link_to "Community", main_app.community_path %></li>

Ruby : Writing Very long string in multiple lines

Using backward slash (\) at the end of line tells the ruby parser that the line is still incomplete. Also the parser concatenates the two string into one.

> long_sentence = "This is a very long sentence and this line even cannot"\
> " be written in one line"
 => "This is a very long sentence and this line even cannot be written in one line"


RSpect : need to be taken care of while writing UnitTesting

Ok let me show an example

let(:role) { create :role, name: 'parent' }
let(:user) { create(:user1, roles: [role]) }
let(:pact) { create :pact, parent_id:, renews_at: 1.hour.ago }

it 'should renew pact and also schedule the drug test whose renews_at date is today' do
  expect{execution}.to change{pact.pact_years.count}.by(1)
  expect(pact.renews_at).to eq(pact.renews_at + Pact::RenewalYear)
Failure/Error: expect(pact.renews_at).to eq(1.year.from_now)
 expected: 2017-02-28 09:20:41.204897017 +0000
 got: 2016-02-28 08:20:40.980794147 +0000

Did you notice what went wrong?. Well what I was doing wrong was, I was expecting the value of stale object to be updated by the execution.


it 'should renew pact and also schedule the drug test whose renews_at date is today' do
  expect{execution}.to change{pact.pact_years.count}.by(1)

  updated_pact = Pact.find(
  expect(updated_pact.renews_at).to eq(pact.renews_at + Pact::RenewalYear)
Failure/Error: expect(updated_pact.renews_at).to eq(pact.renews_at + Pact::RenewalYear)
 expected: 2017-02-28 08:27:50.125348477 +0000
 got: 2017-02-28 08:27:50.125348000 +0000

This time the issue was: I was comparing the DateTime object and for them to be equal, even the milli/micro seconds have to be equal.


updated_pact = Pact.find(
expect(updated_pact.renews_at.to_date).to eq(pact.renews_at.to_date + Pact::RenewalYear)
should renew pact and also schedule the drug test whose renews_at date is today
Finished in 5.76 seconds (files took 5.35 seconds to load)
4 examples, 0 failures, 2 pending