Route

September 5th, 2012 No comments
Categories: Random Thoughts Tags:

Javascript site template

July 28th, 2010 No comments
//global.js
(function() {
    //core methods
    function addEventDelegation( eventType, container, className, callBackFn, args ) {
        if ( !className || !callBackFn || ! eventType || typeof callBackFn !== 'function' ) {
            return;
        }
        $(container)[eventType]( function (evt) {
            var target = $( evt.target );
            if ( target.hasClass( className ) || target.parents().hasClass( className ) )  {
                evt.preventDefault();
                callBackFn(evt, args || "");
            }
        });
    }

    //global functions
    function customFunction(){
        console.log("inside customFunction");
    }

    // document on-load handler
    $(function() {
        addEventDelegation( 'click', $('#page_content'), 'class_name', customFunction );
    });
})();

//mypage.js
(function() {
    function customFunction1(){
        console.log("inside customFunction");
    }

    // document on-load handler
    $(function() {
        addEventDelegation( 'click', $('#page_content'), 'class_name', customFunction1 );
    });
})();

myPage.html
<html>
    <body>
        <div id="page_content">
            <a class="class_name" href="testing">click here</a>
        </div>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type='text/javascript' src='global.js'></script>
        <script type='text/javascript' src='myPage.js'></script>
    </body>
</html>
Categories: JAVASCRIPT Tags: ,

Authenticate Using Spring Security

April 16th, 2010 No comments
@Override
public boolean authenticate(String username, String password) {
    try {
        Authentication request = new UsernamePasswordAuthenticationToken(username, password);
        Authentication result = authenticationManager.authenticate(request);
        SecurityContextHolder.getContext().setAuthentication(result);
    } catch (AuthenticationException e) {
       //Authentication Exception
    }
Categories: Spring Security Tags: ,

Unix Directory Structure

April 16th, 2010 No comments
/			Root
|---root		The home directory for the root user
|---home		Contains the user's home directories
|    |----ftp		Users include many services as listed here
|    |----httpd
|    |----samba
|    |----user1
|    |----user2
|---bin			Commands needed during bootup that might be needed by normal users
|---sbin		Like bin but commands are not intended for normal users.  Commands run by LINUX.
|---proc		This filesystem is not on a disk. Exists in the kernels imagination (virtual).
|    |                  This directory Holds information about kernel parameters and system configuration.
|    |----1		A directory with info about process number 1.  Each process has a directory below proc.
|
|---usr			Contains all commands, libraries, man pages, games and static files for normal operation.
|    |
|    |----bin		Almost all user commands.  some commands are in /bin or /usr/local/bin.
|    |----sbin		System admin commands not needed on the root filesystem.  e.g., most server programs.
|    |
|    |----include	Header files for the C programming language.  Should be below /user/lib for consistency.
|    |
|    |----lib		Unchanging data files for programs and subsystems
|    |----local		The place for locally installed software and other files.
|    |----man		Manual pages
|    |----info		Info documents
|    |----doc		Documentation for various packages
|    |----tmp
|    |----X11R6		The X windows system files.  There is a directory similar to usr below this directory.
|    |
|    |----X386		Like X11R6 but for X11 release 5
|---boot		Files used by the bootstrap loader, LILO.  Kernel images are often kept here.
|---lib			Shared libraries needed by the programs on the root filesystem
|    |----modules 	Loadable kernel modules, especially those needed to boot the system after disasters.
|
|---dev			Device files for devices such as disk drives, serial ports, etc.
|---etc			Configuration files specific to the machine.
|    |----skel		When a home directory is created it is initialized with files from this directory
|    |----sysconfig 	Files that configure the linux system for networking, keyboard, time, and more.
|---var			Contains files that change for mail, news, printers log files, man pages, temp files
|    |----file
|    |----lib		Files that change while the system is running normally
|    |----local		Variable data for programs installed in /usr/local.
|    |----lock		Lock files.  Used by a program to indicate it is using a particular device or file
|    |----log		Log files from programs such as login and syslog which logs all logins, logouts,
|    |                  and other system messages.
|    |----run		Files that contain information about the system that is valid until the system is next booted
|    |
|    |----spool		Directories for mail, printer spools, news and other spooled work.
|    |----tmp		Temporary files that are large or need to exist for longer than they should in /tmp.
|    |
|    |----catman	A cache for man pages that are formatted on demand
|---mnt			Mount points for temporary mounts by the system administrator.
|---tmp			Temporary files.  Programs running after bootup should use /var/tmp.
Categories: UNIX Tags:

File Transfers in UNIX

April 16th, 2010 No comments

Connect to a remote machine thru ssh:
$ ssh username@hostname

Download remote file using rsync:
$ rsync -v -e ssh username@hostname:~/path_to_file.txt /destination_folder

Upload file from a local computer to a remote server:
$ rsync -v -e ssh /path_to_file.txt username@hostname:~/destination_folder

Download remote folder using rsync:
$ rsync -r -v -e ssh username@hostname:~/path_to_folder /destination_folder

Synchronize a local directory with a remote directory:
$ rsync -r -a -v -e “ssh -l username” –delete hostname:/remote_dir/ /local_dir

Synchronize a remote directory with a local directory:
$ rsync -r -a -v -e “ssh -l username” –delete /local_dir hostname:/remote_dir

Categories: UNIX Tags: ,

Change the default select list(jQuery)

April 16th, 2010 No comments
$("select#country option[selected]").removeAttr("selected");
$("select#country option[value='INDIA']").attr("selected", "selected");

                           OR

setDefaultForDropDown("country", "newDefaultValue");
function setDefaultForDropDown(objId, defaultText){
    var objElement=document.getElementById(objId);
    for(i=0;i<objElement.length;i++){
        if(defaultText == objElement.options[i].text){
            objElement.selectedIndex = i;
            break;
        }else{
            objElement.selectedIndex = 0;
        }
    }
}
Categories: JAVASCRIPT Tags: ,

Attach submit events to forms on enter keypress(jQuery)

April 16th, 2010 No comments
$(function(){
    $('input').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });
});
Categories: JAVASCRIPT Tags: ,

Round Off to decimal places

April 16th, 2010 No comments
public String roundOff(String s, int decimalPlaces){
        if(s == null || s.trim().length() == 0 ||
            "0.00".equalsIgnoreCase(s) || "0".equalsIgnoreCase(s)
            || "-0.00".equalsIgnoreCase(s)
            || "-00.0".equalsIgnoreCase(s)
            || "-00.00".equalsIgnoreCase(s)
            || "-0".equalsIgnoreCase(s)
            || "-0.0".equalsIgnoreCase(s)){
            return "0.00";
        }

        double d = 0.00;
        int ind = s.indexOf('.');
        if (ind > 0){
            String dec = s.substring(ind);
            if(dec.length() == 1){
                s = s.concat("00");
                return s ;
            }

            if(dec.length() == 2){
                s = s.concat("0");
                return s ;
            }
            if(dec.length() == 3){
                return s ;
            }
        }

        if(ind == -1){
            return s.concat(".00");
        }

        try{
            d = Double.parseDouble(s);
            BigDecimal bd = new BigDecimal(d);
            bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
            d = bd.doubleValue();

            return String.valueOf(d);
        }
        catch(java.lang.NumberFormatException nfe){
            return s.substring(0,ind);
        }
    }
Categories: JAVA Tags:

Ubuntu – Connect Apple Time Capsule

May 22nd, 2009 No comments

Steps to connect Apple Time Capsule to UBUNTU(Hardy Heron)
1. Client Side Software – Install smbfs and smbclient

2. Make a Mount Point -
cd /media
sudo mkdir capsule

3. Interactive Mount Statement -
sudo mount.cifs //windowsShare/“TimeCapsuleName” /media/capsule/ -o pass=password

i. the windowsShare is the IP that you assign to the Time Capsule using your Apple AirPort Utility on a windows/mac machine,
ii. The ‘TimeCapsuleName’ is the name enclosed in double quotes is the name assigned to your Time Capsule when it it set up on the Windows/Mac.
iii. /media/capsule is the name of the mount point that you selected,
iv. password is replaced with whatever password you elected to use during the Airport configuration.

Categories: UBUNTU Tags: ,

Ubuntu – Restore Panels

May 22nd, 2009 1 comment

Command Line

$ gconftool-2 –shutdown
$ rm -rf ~/.gconf/apps/panel
$ pkill gnome-panel

Categories: UBUNTU Tags: ,