Sunday, March 18, 2012

How to validate Fund ISIN Code

Below is a Java code to validate fund ISIN code..

import java.util.regex.Pattern;


public class TestISINCode{

public static void main(String args[]){

System.out.println(TestISINCode.checkIsinCode("GB00B0XWN709"));

}

private static final Pattern ISIN_PATTERN = Pattern.compile("[A-Z]{2}([A-Z0-9]){9}[0-9]");



public static boolean checkIsinCode(String isin) {

if (isin == null) {

return false;

}

if (!ISIN_PATTERN.matcher(isin).matches()) {

return false;

}



StringBuffer digits = new StringBuffer();

for (int i = 0; i < 11; i++) {

digits.append(Character.digit(isin.charAt(i), 36));

}

digits.reverse();

int sum = 0;

for (int i = 0; i < digits.length(); i++) {

int digit = Character.digit(digits.charAt(i), 36);

if (i % 2 == 0) {

digit *= 2;

}

sum += digit / 10;

sum += digit % 10;

}



int checkDigit = Character.digit(isin.charAt(11), 36);

int tensComplement = (sum % 10 == 0) ? 0 : ((sum / 10) + 1) * 10 - sum;

return checkDigit == tensComplement;

}

}

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);

Sunday, October 17, 2010

Installing Windows XP using USB Flash Drive

Below article will guide you in installing Windows XP using USB Flash Drive.

For that, you need to download and install WinToFlash tool from given link: http://wintoflash.com/home/en/

Once its installed, run the application and create your flash drive as bootable windows XP drive.

Provide the Windows XP file path where Windows Setup files are and choose the USB drive e.g., E:\ as per the screenshot.



This will copy all the windows XP files in the flash drive along with bootable files.

Next, restart your machine and boot your machine using flash drive and proceed with the Windows XP installation.

Please note that this has worked for me. This may or may not work for you.

Saturday, June 14, 2008

Web 2.0 - Read Write Web

Web 2.0 is still a buzzword for many people. There is a significant shift in the thinking after web 2.0 hits the internet world. Tagging a media content, personalizing the content based on user profile, making a peer to peer network instead of centralized accessing had never been easy with web 1.0. We call it a read web.

According to the O'Reilly media:

"Web 2.0 is the business revolution in the computer industry caused by the move to the internet as platform, and an attempt to understand the rules for success on that new platform. Chief among those rules is this: Build applications that harness network effects to get better the more people use them."

In short web 2.0 is a read write web. Whether you are uploading a video content on you tube or participating on eBay community, doing online auctions or creating online documents using Google apps or creating pages on wikipedia or blogs, all these applications uses web 2.0 technologies extensively.

Some of the principles governing web 2.0 may be highlighted as:


















Some of the technologies fuelling the web 2.0 are: portals, AJAX, Flex, web services, PHP, MySql, XML etc.