Thursday, April 24, 2008

INSTALLING AND SETTING UP APACHE & MONGREAL ON FEDORA

Make sure u r are a root user

1. installing apache
yum install httpd

2. install and setup mongrel
gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies

3. Configuring the cluster
cd /var/www/app_directory
[u in app directory]$ mongrel_rails cluster::configure -e production \\
-p 8000 \\
-a 127.0.0.1 \\
-N 3 \\

-e : which type of setup.. production or development
i used development. since mine was under dev..

-p : starting port for mongrel_cluster
-a : ip address
-N : number of mongrel instances u wanu run...

this will create a mongrel_cluster.yml file inside /var/www/app_dir/config

4. commands to start and stop mongrel_cluster

[u in app directory]$mongrel_rails cluster::start/restart/stop

Completed this part ur mongrel setup is done dona done done.....

Next step is to configure apache..

5. now move on to ur /etc/httpd/conf directory
Since there is lotta junk in the httpd.conf file
we wil make separate config files for our app...

there ll be four config files in all.. which are as follows...
myapp.common
The common portions of our configuration. Refactoring this out makes it easier
to add additional VirtualHosts down the road (e.g., SSL) while still maintaining
exactly the same configuration.
myapp.conf
The main entry, tying everything together to produce a working Rails app.
myapp.proxy_cluster.conf
A proxy balancer with which to interface with the Mongrel cluster.
myapp.proxy_frontend.conf
An (optional) HTTP front-end for managing the proxy load balancing configuration
on the fly.

===============
myapp.common
===============

ServerName myapp.com
DocumentRoot /var/rails/myapp/current/public


Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


RewriteEngine On

# Make sure people go to www.myapp.com, not myapp.com
RewriteCond %{HTTP_HOST} ^myapp\.com$ [NC]
RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
# Yes, I've read no-www.com, but my site already has much Google-Fu on
# www.blah.com. Feel free to comment this out.

# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml
application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html

# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflate


============
myapp.conf
============

Include /etc/httpd/conf.d/myapp.common

ErrorLog logs/myapp_errors_log
CustomLog logs/myapp_log combined

======================
myapp.proxy_cluster.conf
======================
This is loaded by Apache to configure a mod_proxy_balancer cluster mapped to
the internal Mongrel servers.

BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002

=======================
myapp.proxy_frontend.conf
=======================

This provides a front-end for the proxy load balancing, which you can access
from inside your server at http://localhost:8080.

Listen 8080
SetHandler balancer-manager
Deny from all
Allow from localhost

6. restart ur httpd
[u in app directory]$/sbin/service httpd restart

Actaully i posted it for my personal reference..
U will find a very good document on the same here
Thanx to Coda Hale... :)

Mongrel cluster restart issues...

hi,
Error : !!! Path to pid file not valid: tmp/pids/mongrel.8000.pid
mongrel::start reported an error. Use mongrel_rails
mongrel::start -h to get help.


Solution : jump into ur application directory
mine is
/var/www/MY_APP
go to config directory..
open your mongrel_cluster.yml file



check out for the log file path
log_file: log/mongrel.log

which is relative... mongrel cant find it... so change it to ...:

log_file: /var/www/MY_APP/log/mongrel.log

similarly, u l have to change the path for pid file

which ll be ... :
pid_file: tmp/pids/mongrel.pid

change it to ... :
pid_file: /var/www/MY_APP/tmp/pids/mongrel.pid

replace MY_APP with ur app name..
and u r done..

Monday, March 31, 2008

javascript array comparison


var master = new Array("11", "12", "13", "14", "15","16","17","18","19");
var all = new Array("11", "12", "13", "14", "15","16","17","18","19");
var has_app = new Array("11","12","16", "17", "19");
// expected out put = 13,14,15,18
var exp = "13,14,15,18";
var count = 0;
function compareAndRemove(){
outer :for(var i=0; i(is less than)master.length; i++){
inner :for(var j=0; j(is less than)has_app.length; j++){
if(master[i] == has_app[j]){
count = i - j;
all.splice(count,1);
}
}
}
alert(" All:"+all+" exp :"+exp);
}

Thursday, March 20, 2008

OS:Passing data to apps and navigation

Passing data to your application through requestNavigateTo()

If you are using the opensocial.requestNavigateTo() calls, you may supply an optional parameter containing data to be passed to the new page.

The following code passes two variables: foo and bar to the canvas surface of the current application:

  function gotoCanvas(params) {
var canvas_surface = new opensocial.Surface("canvas");
opensocial.requestNavigateTo(canvas_surface, params);
};

var my_params = {
foo : 12345,
bar : "Bar value"
};

gotoCanvas(my_params);

In the canvas view, check for these values with the following code:

  var prefs = opensocial.getEnvironment().getParams();
var foo = prefs["foo"];
/* foo contains 12345 */

var bar = prefs["bar"];
/* bar contains "Bar value" */

You should see that after the navigation has taken place, your URL will look similar to:

http://sandbox.orkut.com/Application.aspx?appId=xxxxxx&uid=xxxxxx&appParams=foo%3D12345%26bar%3DBar%20value

This follows the same format as discussed in Passing data to your application through the querystring

Wednesday, February 27, 2008

OS: passing params to views..

var my_params = {
thumUrl : thumb
};
if(viewer != null){
document.getElementById("some_id").onclick = function(){gotoCanvas(gadgets,my_params);};
}

/*********************************************************/
//function definition...
function gotoCanvas(gadg,params) {
var canvas_view = new gadg.views.View("canvas");
gadg.views.requestNavigateTo(canvas_view, params);
}

/*********************************************************/
retrieve this on canvas page using :
// name matches the myparams variable declared on top...
var xx = prefs["thumUrl"];

OS: content navigation

[content type="html" view="profile"]
[!--[CDATA[ [h1]Profile[/h1][br /] ]]--]
[/content]
[content type="html" view="canvas"]
[!--[CDATA[ [h1]Canvas[/h1][br /] ]]--]
[/content]
[content type="html" view="canvas,profile"]
[!--[CDATA[ [h2]This shows up in canvas and profile views[/h2][br /] ]]--]
[/content]
[content type="html"]
[!--[CDATA[ [h1]Default[/h1][br /] [h2]The content in this section only shows up if no other content sections are applicable[/h2][br /] ]]--]
[/content]


Note : replace all "[" with "<" and "]" with ">"