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: [])
    ...
  end
end

 

and from controller

Cancellation::ProcessorAsync.perform_async(requests_ids: cancellation_requests.map(&:id))

Problem:

 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.

Solution

  $(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

http://jyaasa.com/blog/refactoring-javascript-managing-existing-js-code

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