A new journey begins

Another big change in life is taking place. I’ve landed New York airport (JFK) a few hours ago to start my new life in the USA. After receiving my immigration visa at January 2014; I flew on February 8, 2014 leaving my crying parents along with brothers, sisters, nephews, niches, friends.

The upside (whether only or among many) of this migration is that I never knew that I’m loved by so many people. I wish I can respect all the love and care I’ve got so far and I wish I can settle myself (along with my wife) here in spite of being extremely home-seek.

Getting Started with WebRTC book review

Getting Started with WebRTC

Getting Started with WebRTC

I’ve started reading the book titled Getting Started with WebRTC written by Rob Manson which is published by Packt Publishing.

This is a short book but, my speed of reading is quite slow due to my current workload. Currently I’m reading chapter 2.

Chapter 1 introduces to the high level concepts of WebRTC and what we require for establishing web based real time communication. This is very helpful as you will know your requirements clearly before you dive into work.

In Chapter 2, author shows the technical part of the WebRTC. As I’m currently reading it, I am not ready to write about it but I will update this post when my reading is completed.

Update:
Due to another priorities, I’ve started reading another book titled Mastering Web Application Development with AngularJS. I will update this review once I complete this book but now I’m uncertain about any timeframe. Sorry about that.

No source for ruby-1.9.3-p484 provided with debugger-ruby_core_source gem

I was getting this error when the ruby version is updated to 1.9.3-p484. When you’re using RVM, the solution is quite simple. Install the gem with the following command:

gem install debugger-linecache -v '1.1.2' -- --with-ruby-include=\$rvm_path/src/ruby-1.9.3-p484

If you need to install different version of debugger-linecache change 1.1.2 with appropriate version. If the you’re using different ruby version, change ruby-1.9.3-p484 to appropriate value.

Chance to win free copies of Getting Started with WebRTC ebook

Getting Started with WebRTC

I’m excited to let all of you know that Packt Publishing wanted to give away free copies of their new book titled Getting Started With WebRTC to the beloved readers of my blog.

Three lucky winners stand a chance to win digital copies of the book. Keep reading to find out how you can be one of the Lucky Winners.

Overview:

  • Set up video calls easily with a low bandwidth audio only option using WebRTC
  • Extend your application using real-time text-based chat, and collaborate easily by adding real-time drag-and-drop file sharing
  • Create your own fully working WebRTC application in minutes

How to Enter?
All you need to do is head on over to the book page http://www.packtpub.com/getting-started-with-webrtc/book and look through the  description of the book and drop a line via the comments below this post to let us know what interests you the most about this book. It’s that simple.

Deadline:
The contest will close in 1 weeks or 2 weeks time depending on the response . Winners will be contacted by email, so be sure to use your real email address (No spam, email addresses of winners will be given to Packt Publishing only)!

SSH Tunneling for Ruby on Rails app

It is quite annoying to develop and test an app which is likely to receive data/notification from a third party site if your development computer isn’t globally reachable. You have to deploy to a server and test it and do this each time until it completely works. Examples of such cases include:

  • Facebook app development
  • PayPal or any other payment gateway integration

While there are probably several options, SSH Tunneling is the simplest, at least to me. It needs less than 2 minutes to configure. Let’s do it.

I’m assuming:

  • You’ve a dedicated server/VPS with root access or somehow access to sshd_config file (we’re going to call this remote server)
  • Your domain is dev.awesomeapp.com and which points to the above server with IP 198.198.115.47
  • You wanted the remote server to listen to 80 port
  • You’re running your rails server at port 3000 in your development computer (we gonna call this local server)

(You may have to change the values marked in italic font as your own settings)
Continue reading

Say hello to getUserMedia

It feels like a dream comes true. The HTML5 makes many of our dreams come true. You already know many of it’s dreaming features like localStorage, WebGL, Web Database, Audio/Video, Canvas etc. Fortunately, we can access users’ media devices like Camera, Microphone using browser’s native API. Yes, so, we don’t need any other third party plugins like flash or silverlight.

getUserMedia is a native browser API which allows us access user’s camera and/or microphone (of course upon user’s approval). So, you can capture sounds and videos with a few lines of Javascript and without support of any other plugins.

If you want to learn more and see working examples, you can follow these links:

Lessons learned while working with Backbone.js

I was developing a quite big Backbone.js application with my team of 2 more members. We were working on this project for about 7 months. We’ve learned an awful number of things in this journey as it was our biggest Javascript project for everyone in our team. Among many other things, OOP in Javascript always confuses me though I understand a few things better than earlier. I’ve tried to write a few things I’ve learned while working in this project; however, everything does not directly related to backbone.js

Source Code is the best documentation

I have relied on the backbonejs.org for several months for documentation purpose. However, I’ve found not everything was documented properly in the website. For example, from the website I knew fetch/sync accepts success and error as property of the options hash. What I didn’t know until I read the source code is that it also triggers sync and error events on success and failure respectively. Reading the official doc, I thought it’s possible only for save() method.

Simplified Object Copying

If I need to copy a variable/object attribute, I first need to check it whether it exists or not. Look at this example:

if(this.someAttribute){
  var localAttribute = this.someAttribute;
} else {
  var localAttribute = this.someAttribute = {} //or any default value;
}

However, while reading Backbone.js source code, I’ve learned we could write this in a very simplified one line.

var localAttribute = this.someAttribute || (this.someAttribute = {});

Changing in referenced object does not trigger events

When you change an attribute of a backbone model, change and change:attribute  events are triggered. For example,

object.set(‘name’, ‘The HungryCoder’) will trigger change and change:name events on object.  The following will not work.

var info = model.get('userInfo'); //returns a hash
info['id'] = 101;
model.set('userInfo', info);

The above change won’t trigger a change event. Here info variable is a reference to model’s userInfo and userInfo attribute in the object is already updated when you set info['id'] = 101;

In such cases, if you want to trigger the change events, you need to clone the attribute at first place when you are copying them.

var info = _.clone(model.get('userInfo'));
info['id'] = 101;
model.set('userInfo', info);

This will trigger change and change:info events correctly.

Learn fighting Zombies

If you’re working with Backbone.js for a while, chances are high that you’re already facing this kind of problems. Sometimes, you will notice that a particular action is triggering more than once though it is supposed to perform only once.

This happens because, even though, you remove elements from your DOM, they are still alive in your computer’s memory. Consider the example:

 

var Views.MyView = Backbone.View.extend({
  initialize: function() {
    this.model.on('change', this.render, this);
  },
  render: function() {
    //render template
    alert('hello');
  }
});

You’ve taken instance of this view and added to your DOM. When you wanted to remove these elements from DOM, you’ve called remove() method on this instance. Though the elements are removed from DOM, they are still in memory and can’t be cleaned up by Javascript’s garbage collectors as this object is still referenced from your model. It is due to the following line that you’ve written in our earlier view.

this.model.on('change', this.render, this);

The model has still a reference to this view and a referenced object is not cleaned. So your view is still going to alert you even if they are not visible in the DOM. This has been addressed in Backbone.js 0.9.9 where listenTo (and stopListening) is introduced. So you re-write the above line as following:

this.listenTo(this.model, 'change', this.render);

This will internally keep track of the bounded events and will reliably unbind any events when you call remove() on this view object.

to be updated…

Instant Node.js Starter Review

Instant Node.js Starter

Node.js is a current hype, obviously with valid reasons. Though several times I’ve planned to learn it, I could not manage it. It’s mostly for being extremely busy at home & work and unable to manage time to read big books/manuals. However, I just had a quick look into Node.js when I’ve found a book titled Instant Node.js Starter authored by Pedro Teixeira published by Packt Publishing. This is a part of Packt’s Instant series.

Packt’s Instant series are published for people who struggles with time for reading. These books are very short, fast and jump directly in action.

Continue reading

Sunspot – power up your app with solr before knowing it

The title is a bit skeptical. Isn’t it? But trust me, it’s true. You can implement solr power searching in your Ruby on Rails application without knowing Solr. Yes, you off course know about Solr. What you don’t know is how to make it work for you. Let’s check how can you power your application with Solr using Sunspot gem.

What is Sunspot?

Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. Sunspot is built on top of the RSolr library, which provides a low-level interface for Solr interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful features for indexing objects and searching for them.

Using the sunspots DSL, you can easily implement solr powered searching. Its drop-in support with Rails models let you power your site with a few lines of codes.

Installation

Add the following line in your Bundle file.

gem 'sunspot_rails'
gem 'sunspot_solr'

Then run ‘bundle install’.  Continue reading

Patriotism in TV Commercials

I’m big fan of TV commercials in indian televisions those try to promote patriotism. They nicely talks about their country and to love her even when advertising their products.

Though many of the TV programs (like Reality Shows, family breaking serials) ideas are borrowed from indian televisions, I was always thinking why we don’t see such patriotism in our ads?  Why our commercials do not talk to love our country, to use our local products! I think my days of frustration are over. Recently I’ve seen two tv commercials that are talking about the love for the country and make some change. I’ve embedded those two in this post.

Robi (Mobile operator) TV Commercial:

Frutika (mango juice) TV Commercial

These two are ads I watch in full each time they are broadcasted. Each time I see them I see like I’m seeing it for the first time.

If these ads can change a single person, or at least make him to think different; that’s a big success. I wish to more like these in coming days.