Pages

Saturday, April 28, 2012

Google Drive


Finally, Google Drive is out there in market for use and  I got it configured for myself. Currently it gives 5GB of free space. 

Note! As of now Google Drive client is not available for GNU/Linux.  After setting up all this in Mac, I gave it a try in Ubuntu also. When I login to Google Drive web application, there is no option to download client, as it's now available yet :) 

Here we go, setting up Google Drive and client in Mac.

Read more about Google Drive on their official blog.

Get started with Google Drive at drive.google.com/start
Download the Google Drive (In my case it's for Mac)
I got the .DMG file
Double click .DMG file. You will see "Install Google Drive" icon
Double click
To install it, drag Google Drive.app to Applications
Verify Google Drive in applications and click it to launch
Might get this message, allow forever
Enter userid password

You will see this icon, on click below menu pops

Sign in with your google email id / password


Click Next

Start sync

You will see this message

Google Drive is created and synched

After logging in menus does change.

Friday, April 27, 2012

Take screen shot of iPhone & iPod Touch

To capture iPhone screen as an image, press Home and Sleep button at the same time. You can see the captured image in Photos.

Press Home and Sleep button together


JavaScript to get the browser window's height and width

While working on a web application I came across a scenario where in I wanted to adjust height and width of my component as per browser's resolution. And here is the code snippet to do that in JavaScript.

function getScreenHeightWidth() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        // Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement
            && (document.documentElement.clientWidth 
                        || document.documentElement.clientHeight)) {
        // IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body
            && (document.body.clientWidth 
                        || document.body.clientHeight)) {
        // IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    window.alert('Width = ' + myWidth);
    window.alert('Height = ' + myHeight);
}

I have tested this in latest versions of all modern browsers including Chrome, Firefox, Safari and Internet Explorer. Also I have tested it in Windows 7, Ubuntu 11.10 and Mac Snow Leopard.

HTML Codes for arrow keys

In order to display left, right, up and down arrow keys in HTML we have the following codes.

Key
Code
Output
Left Arrow
←
Right Arrow
→
Up Arrow
↑
Down Arrow
↓

More HTML codes here.

Shrink and extend disk partitions in Windows 7

Its been a long time since I played with partitioning hard drives and creating and deleting volumes. Way back in Windows era, there was no way to shrink and extend disk partitions. Recently I installed Ubuntu in my machine hosting Windows 7 and found one very useful option in Disk Utility i.e. to shrink and extend volumes. Here we go.

 Here is how we can shrink a volume. This will create an empty partition or unallocated space in your disk. Inn the similar way you can extend a volume where in you can assign extra space from unallocated disk space.

My Computer → Right Click → Manage

Select Disk Management → Select the partition

Right Click → Shrink Volume

You might see this message

Enter the amount of space to shrink in MB

ExtJS 3.2 Grid and jQGrid performance

ExtJS Grid and jQGrid are really nice to have kind of UI components. Based on the preference of ExtJS or jQuery framework one can choose which one to use. As I was assigned a task of improving performance of existing web application created in ExtJS 3.2, I got to evaluate grids in ExtJS and jQuery.

To evaluate ExtJS and jQuery grids and their performance, I created separate projects for them. And of course I am using server side pagination. No server side caching, client side caching for this evaluation. 

ExtJS performance 
Data Set
Page Size
Initial Load
Avg Next
Avg Prev
Avg Last
Avg First
853
100
1.06 s
100 ms
90 ms
30 ms
30 ms
853
200
1 s
250 ms
200 ms
250 ms
250 ms
853
500
1.48 s
350 ms
350 ms
250 ms
250 ms
853
800
976ms
350 ms
350 ms
400 ms
500 ms

jQuery performance 
Data Set
Page Size
Initial Load
Avg Next
Avg Prev
Avg Last
Avg First
853
100
200 ms
50 ms
50 ms
40 ms
40 ms
853
200
3 s
150 ms
130 ms
150 ms
150 ms
853
500
913 ms
200 ms
200 ms
250 ms
250 ms
853
800
938 ms
200 ms
200 ms
40 ms
100 ms


So, with my tests I found jQuery little faster compared to ExtJS. There could be n-number of reasons for this. 

Summary: 
Finally for the shake of maintainability of existing code base, I have chosen ExtJS over jQuery. However I have also experimented plugging in jQGrid in place of ExtJS Grid and that too worked for me. Initially I was not sure whether both can work together or not but they did.

Run jetty on a specific port using Gradle

I usually start jetty using Gradle build file as given below, but it will run it on HTTP port 8080
gradle jettyRun

But to specify user defined port use -DhttpPort as given below.
gradle jettyRun -DhttpPort=9999

Know more.

Thursday, April 26, 2012

Set max connections in MySQL database

Problem Statement: I was working with MySQL database and all of a sudden my code started throwing this error.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

The similar kind of error I got in MySQL Workbench also. Here is the snapshot.























Problem Solution: Increase the maximum concurrent connections. You can do this with the command below.

set global max_connections = 1000;

Modify parameters from ExtJS 3.2 Grid Paging next button

Problem Statement: I have a data store define in ExtJS 3.2 as given below. The problem is when clicking next button in paging bar, the agencyStatus is not passed in.

var agncGridStore = new Ext.data.Store({
    url : '/webui/advertiser/agenciesList.json',
    method : 'GET',
    autoLoad : false,
    reader : new Ext.data.JsonReader({
        root : 'agencies',
        totalProperty : 'agencyCount',
        fields : [ 'id', {
            name : 'name',
            type : 'string',
            sortType : Ext.data.SortTypes.acUCString
        }, 'address', 'status', 'currency' ]
    }),
    listeners : {
        load : function() {
            resizeGridHeight('agncGridID', 200, 300);
        }
    },
    remoteSort : true,
    sortInfo : {
        field : 'name',
        direction : 'asc' | 'desc'
    },
    baseParams : {
        'firstResult' : 0,
        'fetchSize' : pageSize,
        'searchStr' : searchText,
        'agencyStatus' : searchFilter
    }
});
agncGridStore.load();

Problem Solution: After trying different possibilities, finally I got done with the help of beforeload event.
var agncGridStore = new Ext.data.Store({
    url : '/webui/advertiser/agenciesList.json',
    method : 'GET',
    autoLoad : false,
    reader : new Ext.data.JsonReader({
        root : 'agencies',
        totalProperty : 'agencyCount',
        fields : [ 'id', {
            name : 'name',
            type : 'string',
            sortType : Ext.data.SortTypes.acUCString
        }, 'address', 'status', 'currency' ]
    }),
    listeners : {
        load : function() {
            resizeGridHeight('agncGridID', 200, 300);
        },
        beforeload : function(store) {    
            store.baseParams.agencyStatus = searchFilter;
            store.baseParams.searchStr = searchText;
        }
    },
    remoteSort : true,
    sortInfo : {
        field : 'name',
        direction : 'asc' | 'desc'
    },
    baseParams : {
        'firstResult' : 0,
        'fetchSize' : pageSize,
        'searchStr' : searchText,
        'agencyStatus' : searchFilter
    }
});
agncGridStore.load();

Use Hibernate Criteria API to Order By based on Association

Problem Statement: I am working with Hibernate to read database table. Not able to apply order by on associated object's attributes.

Problem Solution: Solution is to use criteria alias.

Sort by Cat.name.

List cats = sess.createCriteria(Cat.class)
    .addOrder( Order.asc("name") )
    .list();
In the statement below associated objects's name property is used for sorting. In this case sort will be on Cat.kittens.name
List cats = sess.createCriteria(Cat.class)
    .createAlias("kittens", "kt")
    .addOrder( Order.asc("kt.name") )
    .list();

Read more