aws

Saturday, December 8, 2012

CSEDWeek.org

CSEDWeek.org Learn Computer science transform the future. The only field where you are getting paid for your learning. Only field which is ever changing, never boring and keep you agile both in and out!

Wednesday, May 16, 2012

How to connect MySQL with Mojito


Mojito is a open source MVC framework from Yahoo! This framework is a cocktail of HTML5, CSS, JQuery, YUI and build on top of Node.js, the unique feature of Mojito application is, it works in the browsers, even if they doesn't support JavaScript, the server and client application can be written in the same language JavaScript. The framework support multiple devices, there is no need to create a separate application for Android or iPhone,  single application works on the web browser and also on the smart phone web browsers.

Mojito libraries does not ship with MySQL libraries, we need to install the node modules for MySQL and include them with Mojito.

Below command installs the node modules for MySQL. (assuming Node.js is already installed in the system).

$ npm install mysql

Once the node modules for MySQL is installed, just copy the mysql folder in the node_modules to the mojito node_modules folder. (bit hacky ).

cp -Rp /home/umatg/node/node_modules/mysql  /home/y/lib/node_modules/mojito/node_modules

Since Mojito is a MVC framework written in JavaScript, we need to write the model, view and controller code in JavaScript.  The folder structure for a Mojito application looks like below.  Please refer the Mojito documentation (http://developer.yahoo.com/cocktails/mojito)  for creating a Mojito project and your Mojit.

 

To establish the connection with MySQL, we need to create the MySQL client object and invoke the query method.  The methods to create the client and execute the query are in the mysql.js library file.

The MySQL client object has to be created in the model and the methods in the model can be invoked from the controller and data sent to view in the form of a JSON.

The code below, establishes the connection and query the product table in the ads database in MySQL.

/* models/foo.server.js */
YUI.add('DashboardModel', function(Y) {
    var mysqlCli =require('mysql');
    var mysqlClient = mysqlCli.createClient({
        'host' : 'localhost',
        'port' : 3306,
        'user' : 'root',
        'password' : 'root'
    });

/**
 * The DashboardModel module.
 *
 * @module Dashboard
 */

    /**
     * Constructor for the DashboardModel class.
     *
     * @class DashboardModel
     * @constructor
     */
    Y.mojito.models.DashboardModel = {

        init: function(config) {
            this.config = config;
        },

        /**
         * Method that will be invoked by the mojit controller to obtain data.
         *
         * @param callback {Function} The callback function to call when the
         *        data has been retrieved.
         */
        getProduct: function(callback){
          mysqlClient.query(
            'SELECT * FROM ads.product',
            function selectCb(error, results, fields) {
              if (error) {
                  console.log('getProduct Error: ' + error.message);
                  mysqlClient.end();
                  return;
              }
              var result ={
                      meta:{
                          totalRecords: results.length
                      }
                };
              result.results = results;
              callback(result);
          });
        } 

    };

}, '0.0.1', {requires: []});

We are creating the MySQL client object by invoking the createClient() method from the mysql reference object, by passing the connection details.  Here the password is hard-coded, we can also encrypt the password and retrieve it from a file.

The query to select the products from the table executed by invoking the query method by passing the SQL Select statement and invoking the selectCb callback function.  The result of the query is sent back to the callback in the form of JSON.

Reference:

Tuesday, December 27, 2011

You will never reach your destination If you stop and throw stones at every dog that barks. Better, keep biscuits and move ahead ~Dhirubhai Ambani

Friday, November 11, 2011

Life style today

Get a Professional degree to earn Money.
Marry a spouse who has a equivalent degree and earns money to make more Money.
Get a job, come to USA to make more money in Dollars.
Find a job for the spouse to make more and more money in Dollars.
Now two income in the family, more Income TAX needs to be paid for every pay check, to reduce the Income TAX, get Housing loan, buy a house, pay the EMI.

Result, wife goes to work, no cooking at home, unhealthy and junk outside food everyday, causing health diseases, no love, misunderstanding, heart burn, heading towards break up in the family.

Reason Money, More Money, More and More Money.. no peace of Mind.

Heart Vs Mind

During production support on call duties, I have the opportunity to work overtime and can bill extra hours for the work I did. If I charge more hours I will get more money.

Mind tells to claim more hours and charge more money, but heart doesn't. Heart says charge correctly, claim for the hours your worked.

I am at peace and have contentment if I follow the heart. But sometimes somebody may think I am stupid and doesn't know how to utilize the opportunity and make money and wealth. Somebody tells I am gentle and professional.

I think true professionalism comes by following the Heart not the mind.

Friday, January 21, 2011

Can we escape from these Private school atrocities in Chennai?

Parents from middle class family like me should admit our children in Government schools in and around our residence. The amount we spend in private schools can be saved and utilized for our children’s training. We can arrange the training classes outside the school after the school hours, what these private schools are having in their syllabus. In Government schools there are fewer syllabuses and less homework, the child can concentrate on extra-curricular activity. The child can learn computers, a foreign language and martial arts outside the school in an affordable way. There are additional benefits as well, you can avoid the morning stress to you and your children, the transportation charges from home to school, the heft donations and of course the class room teacher and the principle atrocities.

By putting our children in Government schools we can save a lot of money every month, part of this saved money can be spend for the welfare of our Government schools, like providing class room materials and sanitary materials. The able and available parents can volunteer themselves once in a week to take care of the school sanity, the supplies for their class room and can work closely with the teachers to improve the quality of the classroom and the teaching methodology.

The parents here at California (USA) are not sending their children to Private schools. Here they are sending their children to Government schools and the highlight is every classroom has a room parent every day. Parents can volunteer as room parent, they can work closely with the class teacher and help the children in various classroom activities, this helps in bridging the gap between the teacher and the parent. We are following the west in most of the things, why don’t we take this idea from the west and implement in our schools to eradicate the private school atrocities and the stress it’s causing to the middle class parent community.

The time has come to revamp our thinking. Our children can’t grow alone (isolated from the society) and be happy in a society where there are poor and uneducated children around. Instead of thinking about our own son or daughter and her high-tech education, we have to think about the children in our street, the school in our street and the way to improve the school and its standards.

I think by changing our thinking a little bit, we can overcome the troubles we are facing today due to these private schools.

Feel free to challenge this post with your comments and brickbat.