Wednesday, February 2, 2011

How to make a remote call synchronous in Rails

new Ajax.Request('/controller/action?username=praveen', {asynchronous:false, evalScripts:true, parameters:'page_offset=' + page_offset + '&authenticity_token=' + encodeURIComponent('e060znd6JcrMCU6Bf4ZZnfyBac4tl1YXQ6HuEHZGY58=')});

What to do to get that "asynchronous:false" thing in your link_to_remote or any other helper function available in rails :)

I know its not a big thing and there is/are very few requirements to make an Ajax call synchronous but one might face this requirement sometimes, and the answers is
<%=remote_function(:url => {:controller => "controller", :action => "action", :username => "praveen"}, :type => :synchronous, :with => "'page_offset=' + page_offset") -%>

And you are done... so now till the time this thing is taking place, everything in browser will be waiting to complete the process first and then only proceed next.
Hope you stumble on me looking in for me.

Thursday, January 20, 2011

How to handle wrong car parking!

Hi

I am back but not with any thing on computer but for car commuters.
Have been putting up in Delhi for around i think 12 years now and it has been phenomenal and i love Delhi as it is but there are challenges to deal with everyday and rather than showing anger and swearing on it, it would be good if we try to resolve them in some what funny manner and i did :)

Well addressing to all those owning a car(vehicle) and thinking blank road is car parking area(in Delhi), just before leaving for office today i saw a parked Mahindra Scorpio consuming the rest of road which was half flooded with building materials (as a house construction is going on, common! in areas of Delhi).

But i need to get way so that can reach office i can't take my car from that 1.5 feet of space. Me and my mom tried looking in for that super talented person who has parked his/her car and was lost by now and even by so many queries from neighbourhood no one knew about it and now it was high time i should be doing something about it rather than shouting on air but my love towards cars didn't allowed me to break the car but how can i teach lesson to this person now.

So what i did is that 1 took two a4 blank sheets of paper and stick it with glue (like people paste movie posters) on drivers side of windshield and wrote.. "Hope next time your intelligence can use parking sense!! All the best"

and then i took my car from back road and believe me taking car from that place required 3 people to assist me to drag my car inch by inch(it was that narrow)

But later on came to know form my dad, that driver appeared after about 1hr and was shocked to see it. My mom, dad and even my sister was like all over him and he accepted his mistakes and it took about 20 mins to takes those two sheets out from his windscreen and i don't know whether text written, was even understood by the driver or not. and hopefully this will keep a guard on him next time doing a wrong parking..

So i dealt with it this way.. how about you?

Thursday, December 30, 2010

2 steps to install sqlite 3 on ubuntu for ruby

open a console and write two steps one by one
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby
And you are done :)

Thursday, October 7, 2010

MTNL broadband not opening certain websites

:) then what to do.. i just got one MTNL TriBand broadband unlimited connection for my home in Palam Colony, New Delhi. Everything was great except that it was not opening certain web links like linkedin.com, assembla.com, cricketnirvana.com most of the time and within two days of installation, frustration was so severe that i looked up for google for any help(mind you MTNL,Delhi people they are awesome at NOT resolving any issues like this)
On a random look out for solution i found two things..
1. Change PrimaryDNS and SecondaryDNS to 208.67.222.222 and 208.67.220.220 respectively
and
2. Change TCP MTU Option(in interface page of ADSL router) to 1400

and Final step, Do a restart (one of the option in 'Maintenance' page)
and see if it works for you.. it worked for me :)

Just for information i am having a ADSL router of Sterlite(Firmware Version :2.11.38.0(UE0.C2)3.9.9.5)(provided by MTNL) and am using my own netgear wifi router on top of it,

Monday, October 4, 2010

How to Stop an Ajax request in prototype.js

Question is what will you do if you are using prototype.js(which is not having any abort method) for making a Ajax request and due to some circumstance you want to abort the ajax request raised. Well one can think that this is a narrow requirement, why will anybody need to do this because in the meantime request will be done and one might be having the response in return from server.

I hit this corner case where page content was loading from an Ajax request and which after rendering was firing another Ajax request to update the paginate-r(which is also self firing the request on response completion), but to my surprise i was not able to control the "Ajax request to update paginate-r" and hence i am creating the self firing request but am not able to destroy them.

And i don;t know for what reason there is no "ajaxRequest.abort()" method. And i found the answer from a narrow corner of http://blog.pothoven.net/2007/12/aborting-ajax-requests-for-prototypejs.html and it worked and just to increase the find-ability of this solution am re-writing the post.

introduce a method abort like this for prototype.js
Ajax.Request.prototype.abort = function(){
this.transport.onreadystatechange = Prototype.emptyFunction(); //prevent state change callbacks from being issues
this.transport.abort(); //abort the XHR
Ajax.activeRequestCount--; //updates the request counter
};

and then in your code
write it somewhere so that it is executed only once
<script>
var cw_paginator_request = null;
</script>

and then to assign the request if null else abort the request and fire a new request, like this
<script>
if(cw_paginator_request != null){
cw_paginator_request.abort();
}
cw_paginator_request = <%=remote_function(:url => {:controller => "some_controller", :action => "update_paginator", :id => @selected_id }) -%>;
</script>

Hopefully it might help somebody in need :)

Tuesday, July 13, 2010

Now what will you interpret from this?


This is from the showcase of a bookstore in CP, Delhi. What you(hindi reading) all can interpret from this?
Posted by Picasa

Monday, May 24, 2010

3 step Memcache install in ubuntu with rails binding

#To Install memecache
sudo apt-get install memcached
#To restart memcahce
/etc/init.d/memcached restart
#To install ruby binding gem to memecache
sudo gem install memcached




and to start memcache automatically on system startup
sudo gedit /etc/default/memcached
# Set this to yes to enable memcached.
ENABLE_MEMCACHED=yes

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...