Wednesday, May 30, 2012

DOM Event propagation

1. How to propagate Enter key event on press of some container.

$("#techyHouseDivOrInputField").keydown(function(event){
                                        if(event.keyCode == 13){
                                        propagate further events
                                            $("some_button").click();
                                        }
                                    });
II.  JQuery Live function on Hover/ mouse In , Mouse Out ,Click.

  $("a.link").live('click', function() {
      alert('I am clicked');

     //e.preventDefault();
      //e.stopPropagation();

    return false;
});

  $('internalTag', "#elementId").live({
                            mouseenter:
                               function()
                               {
                                $('anyInnerElment').show();



                               },
                            mouseleave:
                               function()
                               {
                                $('anyInnerElment').show();
                               }
                           }
                        ); 


   III.Unbind live function
    $("#elementId").die();
   $("#elementId").die("click");

 

Tuesday, May 29, 2012

Open source Software Licensing Restrictions



Whenever we think of choosing an  open source library/tools/platform few things which strike in our mind are:
  • Can  we use this open source library or software for commercial purpose?
  • Can we modify these libraries?
  • Whether my product can be distributed if it is using open source platform directly or indirectly ?
  • Is it ok to modify and build upon these third party projects?
  • What are the big differences between these choices (GPL, LGPL, MIT, Apache)? 
  • Can I sell this application or does it have to be open source?

In this Blog We are going to talk about different license types. 

Fr example below are the commonly used open source platform and their license types.
Hibernate                   - LGPL
Spring                        - Apache v2.0 license
Struts                         - Apache v2.0 license
JQuery                       - MIT Lisence
Sun JDK/JRE binary     -Sun's Binary Code License (BCL)
Sun Source Code         -GPL
Expat, PuTTY              -  MIT License
 Ruby on Rails, CakePHP- MIT License
Eclipse                        -Eclipse Public License (EPL)

                         Comparisons of Software Licenses
GPL:
  • The linked software is considered a whole.
  • If you distribute code linked to GPLd code, the whole work be available under the GPL.
  • If you remove the GPLd code, you can distribute the work under any license you want (as long as you own that code). 
  • GPL forces the people who use the code in a project to release the whole project under GPL.
  • Link with code using a different lisence :NO .Proprietary Software linking Not allowed.
  • Release changes under a diffrent lisence: No
  • Distribution of “the Work” is not allowed.
  • Redistributing of the code with changes allowed Only if the derivative is GNU GPL.


LGPL:
  • Link with code using a different lisence :Yes. Proprietary Software linking is allowed.
  • Release changes under a diffrent lisence: No
  • The software that links to the library is not considered a derivative work.
  • Whether a work that uses an LGPL program is a derivative work or not is a legal issue
  • It dooesn't impose the license on software using the library.
  •  If you  modify the library or directly include parts of the code in your software, then your code modification (not your application) would have to be LGPL.In other words you also provide the source code of the LGPL code changes.

Apache Public License:
  • Proprietary Software linking Allowed.
  • Distribution of “the Work” Allowed.
  • Redistributing of the code with changes allowed as long as the name “Apache” isn't used in the name of the derivative work.  
  • We can make changes to an Apache package and can distribute them.However include a copy of the license in any redistribution you may make that includes Apache software. For eg SpringSource Tool Suite shows following:"This product includes software developed by the Apache Software Foundation http://www.apache.org"

MIT License:
  • The shortest and probably broadest of all the popular open-source licenses.
  • MIT License states more explicitly the rights given to the end-user, including the right to use, copy, modify, merge, publish, distribute, sublicense, and/or sell the software.
  • It permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms.Means for any coding issue you are solely responsible not the provider.
  • Proprietary Software linking Allowed.
  • Distribution of “the Work” Allowed.
  • Redistributing of the code with changes Allowed.
  • Compatible with GNU GPL. 
Hope above clarify the licensing restrictions.
 

References:
http://www.apache.org/foundation/license-faq.html
http://en.wikipedia.org/wiki/Comparison_of_free_software_licenses
http://web.archive.org/web/20090317083515/http://developer.kde.org/documentation/licensing/licenses_summary.html




Sunday, May 27, 2012

Organizing Project into Multi Module Structure

The right approach of organizing an enterprise Project is to create a multi module Project.
  
Pom project (top level project that would define all of the modules)
  •   war project (project-web)
  •   jar project (project-services)
  •   jar project (project-common, contains common stuff eg. vo's)
  •   jar project (project-framework, Exception, Security, Logging, Error codes, Encryption)
  •   jar project (project-persistence)
  •   jar project (project-module)
  •   war project (project-web-services, depends upon 'project-services')
  •   jar project (project-report, reporting stuff)
  •   jar project(project-standalone for cron Jobs, depends upon 'project-service



Reasons for using Multi-Module projects :
  • Modulerising related source code: client/web, controller, services, UI,.
  • Deploy only the changes:With multi-module projects, we can regenerate your project and deploy only what changed.
  • Allowing Versioning of diffrenet modules
  • Relase ont module  which is modified
  • Spliting your project into multiple maven projects if your projects are deployed in different configurations.
  • Reuse of sertainn comon modules:Let's assume your project contains some well-written generic-enough code for mail sending. If you later have another project that need mail sending functionality, you can simply re-use your existing module or build upon it (in another module by adding it as a dependency).
  • Easier maintainability on the long run. Maybe now it seems like a small project.
  • Conceptual clarity 

Sample Example:
Pom.xml for Parent Project:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>TechyHouse</artifactId>
        <groupId>org.techyhouse</groupId>
        <version>1.1.0-SNAPSHOT</version>
    </parent>
    <groupId>org.techyhouse</groupId>
    <artifactId>techyhouse-web</artifactId>
    <version>1.1.0-SNAPSHOT</version>
    <name>techyhouse-web</name>
    <packaging>war</packaging>
    <url>http://maven.apache.org</url>
    <properties>
        <java-version>1.6</java-version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>3.0.6.RELEASE</spring.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.techyhouse</groupId>
            <artifactId>techyhouse-service</artifactId>
            <version>1.1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>techyhouse-web</finalName>
        <defaultGoal>install</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>src/main/techyhouse</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


Pom.xml for child module

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>TechyHouse</artifactId>
        <groupId>org.techyhouse</groupId>
        <version>1.1.0-SNAPSHOT</version>
    </parent>
    <groupId>org.techyhouse</groupId>
    <artifactId>techyhouse-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>techyhouse-service</name>
    <url>http://maven.apache.org</url>
    <build>
        <finalName>techyhouse-service</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-orgpiler-plugin</artifactId>
                <version>2.3.2</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <links>
                        <link>http://java.sun.org/javase/6/docs/api/</link>
                    </links>
                    <detectOfflineLinks />
                    <aggregate>true</aggregate>
                    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                    <docletArtifact>
                        <groupId>org.umlgraph</groupId>
                        <artifactId>doclet</artifactId>
                        <version>5.1</version>
                    </docletArtifact>
                    <additionalparam>-operations</additionalparam>
                    <additionalparam>-qualify</additionalparam>
                    <additionalparam>-types</additionalparam>
                    <additionalparam>-visibility</additionalparam>
                    <additionalparam>-collpackages</additionalparam>
                    <additionalparam>-views</additionalparam>
                    <useStandardDocletOptions>true</useStandardDocletOptions>
                    <show>private</show>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.6</version>
                <!-- TODO: choose appropriate rulesets -->
                <configuration>
                    <targetJdk>1.6</targetJdk>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
    <properties>
        <java-version>1.6</java-version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>3.1.0.RELEASE</spring.version>
        <log4j.version>1.2.16</log4j.version>
        <junit.version>4.10</junit.version>
        <aspectj.version>1.6.11</aspectj.version>
    </properties>
    <dependencies>   
        <dependency>
            ...............
            ................
            ...............
        </dependency>       
    </dependencies>
</project>

Friday, May 25, 2012

Virtualization using VirtualBox

Why do we need Virtualization?
   
The first things comes in our mind is "Running multiple operating systems simultaneously".
Actually,  VirtualBox allows us to run more than one operating system at a time. This way, we can run software written for one operating system on another (for example, Windows software on Linux or a Mac) without having to reboot to use it.

So the benefits are:
  •  Easier software installations
  •  Testing and disaster recovery
  •  VirtualBox snapshots
  •   Infrastructure consolidation
Terminology:
  •     Host – The physical machine where you are going to install VirtualBox
  •     Guest – The machines created using VirtualBox ( Virtual Machine )
  •     Guest Additions – A set of software components, which comes with VirtualBox to improve the Guest performance and also to provide some additional features


                     Oracle VM VirtualBox
Oracle VM VirtualBox is an open source virtualization software that you can install on various x86 systems. 
Oracle VM Virtualbox can be installed on top of Windows, Linux, Mac, or Solaris.
 Once It is installed, we can create virtual machines that can be used to run guest operating systems like Windows, Linux, Solaris, etc.
Multiple guest OSs can be loaded under the host operating system (host OS). Each guest can be started, paused and stopped independently within its own virtual machine (VM). 

On a high-level Oracle VM VirtualBox is similar to VMware. Oracle got this VirtualBox technology from Sun.

Virtual Disk Image:VirtualBox uses its own format for storage containers – Virtual Disk Image (VDI). 


VirtualBox's command-line utility vBoxManage includes options for cloning disks and importing and exporting file systems, however, it does not include a tool for increasing the size of the filesystem within a VDI container
Licensing:
    the core package is free software released under GNU General Public License version 2 (GPLv2).

Features of Oracle VM VirtualBox:
  •     Portability.
  •     No hardware virtualization required.
  •     Guest Additions:
  •     Great hardware support.
  •     Guest multiprocessing (SMP).
  •      USB device support        Hardware compatibility
  •      Full ACPI support
  •      Multiscreen resolutions
  •      Built-in iSCSI support
  •      PXE Network boot    Multigeneration branched snapshots
  •      Clean architecture; unprecedented modularity
  •      Remote machine display.
  •      Extensible RDP authentication
  •      USB over RDP

  Refernces:
    http://www.thegeekstuff.com/2012/02/virtualbox-install-create-vm/
     http://www.virtualbox.org

Thursday, May 24, 2012

Reason to use Ruby on Rails


Following are the criteria we should consider while selecting a Language
  •     One simple web page
  •     How media(css, js) is handled in the framework
  •     Connect to a database
  •     One table to store your data
  •     A form to save information into the table
  •     Deploy it live
RoR :
  • RoR is a DSL for webdev, the API distilled to its most pure form. Everything makes sense and can be expressed very easy. Highly readable.
  • RoR is community driven with no commercial entity nagging (springsource?).
  • the secret is not RoR (the framework), the secret is the Ruby language.
  • integrate with JVM via JRuby (mature technology)
  • Java to Ruby is easy (both imperative, object oriented, similar syntax)
  • simple web development, I had previous experience mostly with JSP/JSF, the Ruby approach seemed much simpler and "right" - MVC with simple reusable templates with a lot of helpers ready to be used + all the layers fill in nicely with each other.
  • I really leveraged/understood all kinds of testing - Ruby is full of great testing libraries and I think the Ruby community did most of today's testing innovations
  • You are always in control of the code, if You hit a bug in a library You can quickly deal with it, I know it might sound crazy to be able to "monkey-patch" everything, but it really gives You control over You whole application
  • Rails is more "database-oriented".
    In Rails, you essentially start by defining your tables (with field names and their specifics). Then ActiveRecord will map them to Ruby classes or models.
  • if you use JRuby or Jython, then your Ruby and Python threads are Java threads. So, they are not only as efficient as Java threads, they are exactly the same as Java threads.
  • Ruby seems like a neat platform where all the tools are at your fingertips. It was built to solve your problems fast. It's becoming the most popular on the startup scene

Sunday, May 20, 2012

Backbone Framework benefits






  
Backbone's main benefits, regardless of your target platform or device, include helping:
  • Organize the structure to your application
  • Simplify server-side persistence
  • Decouple the DOM from your page's data
  • Model data, views and routers in a succinct manner
  • Provide DOM, model and collection synchronization

  Benefits of Backbone Frameworks are:
  •     Core components: Model, View, Collection, Router. Enforces its own flavor of MV*
  •     Good documentation, with more improvements on the way
  •     Used by large companies such as SoundCloud and Foursquare to build non-trivial applications
  •     Event-driven communication between views and models. As we'll see, it's relatively straight-forward to add event listeners to any attribute in a model, giving developers fine-grained control over what changes in the view
  •     Supports data bindings through manual events or a separate Key-value observing (KVO) library
  •     Great support for RESTful interfaces out of the box, so models can be easily tied to a backend
  •     Extensive eventing system. It's trivial to add support for pub/sub in Backbone
  •     Prototypes are instantiated with the new keyword, which some developers prefer
  •     Agnostic about templating frameworks, however Underscore's micro-templating is available by default. Backbone works well with libraries like Handlebars
  •     Doesn't support deeply nested models, though there are Backbone plugins such as this which can help
  •     Clear and flexible conventions for structuring applications. Backbone doesn't force usage of all of its components and can work with only those needed.

Saturday, May 19, 2012

Why to go for Rest Services


When should we go for Rest Services? How does it help us in scaling the application? 

Yes .Rest Servives provides a better option to handle a complex application where we expect heavy load and we expect continuously addition of components.

Reasons to go with Rest Services are :
  • Simple.
  • We can deploy the services to any remote location so that load on the server will be reduced.
  • If we find that a specific services are consumed heavily we can distribute those services to a different server.We may not nead to use load balancer.
  •  You can make good use of HTTP cache and proxy server to help you handle high load.
  • It helps you organize even a very complex application into simple resources.
  • It makes it easy for new clients to use your application
  •  It makes it easy for new clients to use your application, even if you haven't designed it specifically for them  probably, because they weren't around when you created your app.
  • Also, because REST relies on the semantics of HTTP, requests for data (GET requests) can be cached.

Friday, May 18, 2012

Akka Framework

Akka framework is generally used in real-time traffic information field distributed over several nodes.whre we can easily compose a system out of actors and messages between several parties.

Consider the case of a car manufacturing plant, where each Car is going to take 10 minutes to get it assembled however while the first car is going through adding accessories, the rest of the cars in queue can be placed on the different pipelines to perform various tasks in parallel. 

Use cases where we can think of using this framework are:
    • Transaction processing (Online Gaming, Finance/Banking, Trading, Statistics, Betting, Social Media, Telecom)
    • Service backend (any industry, any app)
    • Concurrency/parallelism (any app)
    • Simulation
    • Batch processing (any industry)
    • Communications Hub (Telecom, Web media, Mobile media)
    • Gaming and Betting (MOM, online gaming, betting)
    • Business Intelligence/Data Mining/general purpose crunching
    • Complex Event Stream Processing
     
    Fore more info visit http: http://akka.io/

Thursday, May 17, 2012

Maven most useful commands

Resolving conflict using dependency tree

mvn dependency:tree -Dverbose -Dincludes=commons-collections

any nearer dependency chosen first..

To skip running the test cases:

mvn install -Dmaven.test.skip=true

mvn clean install -DskipTests

-e option : generate stacktrace 
mvn  -e install -Dmaven.test.skip=true 

Run specifc test
mvn test -Dtest=MyclassTest

Fix eclipse error
mvn clean eclipse:eclipse
mvn clean idea:eclipse

-DargLine="-DvarNmame=varValue"

Spring boot debug:
mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006 -Dserver.port=8082"


maven phases:
  • validate 
  • compile 
  • test 
  • package 
  • verify
  • install
  • deploy 
Execute FindBugs :
mvn findbugs:gui

Maven  Properties:
${project.basedir} - root folder of the module/project (the location where the current pom.xml file is located)
${project.build.directory} - by default the target folder.
${project.build.outputDirectory} -- the target/classes folder.
${project.build.testOutputDirectory} --t the target/test-classes folder.
${project.build.sourceDirectory} -- the src/main/java folder.
${project.build.testSourceDirectory}--default the src/test/java folder.
${project.build.finalName}- ${project.artifactId}-${project.version}.



Resources Link

         Tools  and resources

Class diagram:
http://www.gliffy.com/
http://www.yuml.me

Sequence diagram:
http://www.websequencediagrams.com/

MVC Client side framework:

Backbone:
http://addyosmani.github.com/backbone-fundamentals

Railwayjs:
http://railwayjs.com 
https://github.com/1602/express-on-railway#readme
https://github.com/1602/express-on-railway/issues
https://trello.com/board/railwayjs/4f0a0d49128365065e008a1d

UI Component:
Bootsrap twitter:
 http://twitter.github.com/bootstrap/components.html
Loading Image genaration:
http://loadinggif.com/
icons:
http://findicons.com
http://www.veryicon.com/
http://wufoo.com/

Templating framework:
http://handlebarsjs.com/

Node JS:
http://search.npmjs.org/
https://github.com/addyosmani/backbone-boilerplates/blob/master/README.md
https://github.com/joshsoftware/tapit
http://lanyrd.com/topics/nodejs/past/
http://www.nodecloud.org/
http://nodeup.com/
http://locomotivejs.org/
http://mongoosejs.com/
http://ql.io/docs/about
http://www.slideshare.net/andypiper/becoming-a-nodejs-ninja-on-cloud-foundry-open-tour-london 

Backbone:
https://github.com/documentcloud/backbone/wiki/Tutorials,-blog-posts-and-example-sites
http://addyosmani.github.com/backbone-fundamentals/#testing
http://addyosmani.github.com/backbone.paginator/examples/netflix-request-paging/index.html

Ruby:
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
http://qastuffs.blogspot.in/2011/02/installing-and-configuring-gembundler.html

Screen Scraping :
http://phantomjs.org/
http://web-harvest.sourceforge.net/

Topology
http://arborjs.org/

Rich app
http://enyojs.com/

Html5
https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills



Monday, May 14, 2012

MongoDB dump Export and restore


Export:
#  mongodb/bin location
                    mongodump -o dumpFolder
 
 Import:
mongorestore  dumpFolder dbpath  /mongodb_db_path