Tuesday, June 18, 2013

Allow mongo to connect from remote IP

Access to mongo is controlled with iptables for Linux based OS.

Step 1

Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0

Step 2

Add iptables rules to control the incoming and outgoing traffic for mongo. Here is a sample command if you have the default ports for mongo.

$ sudo iptables -A INPUT -s 198.61.168.XXX,166.78.113.XX -p tcp 
--destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
$ sudo iptables -A OUTPUT -d 198.61.168.XXX,166.78.113.XX -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

Here 198.61.168.XXX and 166.78.113.XX are the IP from where you want to access the mongodb.

Sunday, May 12, 2013

Readable model name with translation support

Use following to have the translated attribute with fallback support,
This will look in to the translation in the following order,
First it will look for the "en.activerecord.models.person.first_name" and then for "en.attributes.first_name" and finally falls back to humanize.

Sunday, May 5, 2013

Encapsulate views in rails

We always hear that we have to keep our code clean and DRY. But I feel that poor view files are always left out from this concern. We do not write html to support the change of DOM. Yes, true for rails we have layouts and partials. But these features some times is not enough for encapsulating views.
Let's say we are using jQuery UI in our application and we want to switch to twitter bootstrap :-S. Now that will be a pain, right? Because you have all sorts of views and DOM structures designed for jQuery UI. So for projects that we plan to maintain for a long time, we should consider to encapsulate almost every thing. Such as we can use unobtrusive Javascript to have the flexibility to switch between JS libraries. But in this post I plan to discuss the view layer and a particular mehod to encapsulate DOM and view logic.
People are already doing it. Rails form builders, simple form, active admin DSL can be some of the examples. Obviously we can use partials to reduce the duplication but here I am talking about dom structure.
So here is the pattern that is used by simple form or form builders, you might call it the builder pattern. Here is a simple example which will clear the cloud I think.

I would prefer to encapsulate the view with a DSL as following,
Here is the helper code to support the DSL.
And the target resulting dom is as follows.

The DSL is fairly simple actually. The two things you need to know before hand is how capture method works for rails template and that you have to pass the self as template so that later you can call the capture method using the template object. Any method that you can run from the view, you can run on template object.
As you can see for widget we I have used an object to as we need related sub blocks(title, content). You can also use the simpler version which is shown in header block. Usually form builders need the object reference as they have states. But for us widgets donot have states. Still it is a good way to go, because later you might have different type of widget and then, you might pass that as argument. In that case your widget will have state and the w object will help you to maintain that state. I hope that helps :)

References

Saturday, March 16, 2013

AngularJs compiling dynamically added dom

Scenario
We have an application where we use angular for a particular tab. So we needed to compile the ajax document.

Wednesday, February 13, 2013

Error Deploying Angular JS

When Deploying Angular JS to rails production server, we were getting the following error,
Error: Unknown provider: eProvider <- e at Error (<anonymous>) ....
Well if you are getting mad to find error in your Angular you can not. Just inject the dependencies as follows,
MyController.$inject = ['$scope']; 
And that is it.

Reference

http://stackoverflow.com/questions/13459452/rails-3-angularjs-minification-does-not-work-in-production-unknown-provider

Monday, February 11, 2013

Ubuntu Teletalk 3G configuration

The basic settings is,
Dial number: *99#
APN Address: gprsunl
PDP Type: IP
Auth mode: PAP
Edit connection -> Mobile Broadband -> Add new ....

Monday, January 14, 2013

Jquery ui datepicker a common gotcha

This post is just to keep me reminding about a jquery datepicker issue.

If you have multiple jqerury ui datepicker with the same html ID, then you are done for. Crazy behavior is observed then. Don't set id to input for datepicker if you have multiple of them, or just assign a new id to each of them.