Monday, December 20, 2010

Mapping drive letters to local folders in Windows XP

Windows XP provide a commmand to map any local folder with a drive name.

Say, if you want to map a local folder newfolder of your d drive (D:\newfolder) to a new drive say K:\  you can easily do this by command subst.

subst <drive_letter> <complete_folder_path>

In our case, command would be

subst K: D:\newfolder

Saturday, December 18, 2010

how to create gadgets using google gadget

Google gadgets are small components that are offered by Google that can be easily plugged into your website. Google gadgets allow you to create a dynamic reusable components that can be placed on any webpage on the web. Creating gadgets using google gadget editor is very easy.

First you have to create the gadget xml file using google gadget editor (GGE).

http://code.google.com/apis/gadgets/docs/legacy/gs.html

A google gadget input file is an xml having parent Module tag.

Module tag contains ModulePrefs and Content tag.

A typical google gadget xml file is shown below:

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="My Gadget"
         directory_title="My Gadget"
         description="This is a sample gadget"
         author="your_name"
         author_email="your_name@xyz.com"
         author_location="your_location"
         author_link="http://www.your_name.com"
         width="300" height="200">
                  <Require feature="dynamic-height" />
                  <Require feature="analytics"/>
                  <Require feature="setprefs" />
  </ModulePrefs>
  <UserPref name="refresh"
         display_name="Refresh Interval (seconds):"
         default_value="20"/>
  <UserPref name="resize"
         datatype="bool"
         display_name="Resize text based on % change:"
         default_value="true"/>
  <UserPref name="bold"
         datatype="bool"
         display_name="Bold Text:"
         default_value="true"/>
  <Content type="html">
          <![CDATA[  
                  <script>
                           // your javascript code here
                           /**
                            * _IG_Prefs will allow you to access the value of UserPref
                            * that you have defined like refresh, resize and bold.
                            */
                           var prefs = new _IG_Prefs();
                  </script>
                  <style>
                           // your css style code here
                  </style>
                  <div id="contentdiv"></div>
         ]]>
  </Content>
</Module>

Next you need to publish it using google GGE. Once you're done with your gadget publishing it will be ready for your website. You can personalize your iGoogle webpage by adding your newly created gadget. Also, you can add your gadget to Google gadget directory from your gadget dashboard. You can also add your gadget xml file on your website directly without hosting it to Google gadget directory.

Friday, December 17, 2010

Accessing shared folder of host in guest pc using virtual pc 2007

Folders can be shared by installing virtual pc additions from virtual pc 2007. Select the virtual pc addition from virtual pc 2007 and click continue. Next access your cd drive in guest operating system. Windows OS iso image should be mounted on guest pc cd drive. Auto running the cd will install the virtual pc additions.

After virtual pc additions are installed, you will be able to view shared files and folders of host pc in guest. Also, you will be able to drag and drop files between guest and host.

Thursday, December 16, 2010

Sorting a javascript array by custom sort function

Suppose you have a javascript array which contains objects of Employee as shown below. Sorting the array can be performed by writing custom sort function.

function Employee(lastName, firstName) {
     this.lastName= lastName;
     this.firstName= firstName;
}
var employeeArray = new Array();
employeeArray.push(new Employee("Kennedy", "John"));
employeeArray.push(new Employee("Marshall", "Kevin"));
employeeArray.push(new Employee("Adams", "Bryan"));

// printing in loop gives Kennedy Marshall Adams
alert(employeeArray[i].lastName);

Sorting the array based on employee's last name

// define the sort function
function employeeLastNameComparator(emp1, emp2){
     var emp1LastNameInLowerCase=emp1.lastName.toLowerCase();
     var emp2LastNameInLowerCase=emp2.lastName.toLowerCase();
     if (emp1LastNameInLowerCase < emp2LastNameInLowerCase){           
            return -1;  
     }  
     if (emp1LastNameInLowerCase > emp2LastNameInLowerCase){
          return 1;
     }
     return 0;
}
employeeArray.sort(employeeLastNameComparator);

// after sort prints Adams Kennedy Marshall
alert(employeeArray[i].lastName);