Monday, September 5, 2011

code Reference

Remove duplicate values in an Array using javascript 

Remove duplicate values in an array using javascript
var a = new Array(1,2,2,2,3,4,4,5,5,6,6,6,7,8,9,9);
alert(uniqueArr(a));

//it will remove duplicate values and return array
function uniqueArr(a) {
  temp = new Array();
  for(i=0;i < a.length;i++){
    if(!contains(temp, a[i])){
      temp.length+=1;
      temp[temp.length-1]=a[i];
    }
  }
  return temp;
}

function contains(a, e) {
   for(j=0;j < a.length;j++)if(a[j]==e)return;
   return false;
}

-----------------------------------------------------------------

Java script to validate any number of radio button in html page... 

var ips,ckd;
var RadAry=new Array();
var GrpAry=new Array();
function CheckRadio() {
   ips=document.getElementsByTagName('INPUT');
   RadAry=new Array();
   for (i=0;i < ips.length;i++) {
     if (ips.type=='radio') {
       RadAry[RadAry.length]=ips;
     }
   }

  GrpAry=new Array();
  GrpAry[0]=new Array();  

  for (i2=0;i2 < RadAry.length;i2++) {
     GrpAry[GrpAry.length-1][GrpAry[GrpAry.length-1].le- ngth]=RadAry[i2];
     if (RadAry[i2+1]&&RadAry[i2+1].name!=RadAry[i2].name) {
        GrpAry[GrpAry.length]=new Array();
     }
  }
  for (i3=0;i3 < GrpAry.length;i3++) {
    ckd=1;
    for (i4=0;i4 < GrpAry[i3].length;i4++) {
      if (GrpAry[i3][i4].checked==true){
        ckd=0
      }
    }
    if (ckd){
      alert('Radio Group '+GrpAry[i3][0].name+' is not checked');
      return false;
    }
  } 

form.submit();  

-----------------------------------------------------------------

 XMLout Usage in Perl 

#If user want to write each child node in different file then use XMLout function in perl.

$tbmfile = `mktemp -f`;
$xml      = XMLin(xml_file, suppressempty => 1, ForceArray => 1);
$child     = $xml->{'ChildNode'};
foreach my $x(@$child) {
   $tbmfile = `mktemp -f`;
   my $xml_dump = XMLout($x, RootName= "ChildNode");
   open(FD,">/tmp/$tbmfile");
   print FD $xml_dump;
   close(FD);
}

-----------------------------------------------------------------

 Regular expression in Mysql 

The basic syntax to use regular expressions in a MySQL query is:
SELECT something FROM table WHERE column REGEXP 'regexp'

For example, to select all columns from the table events where the values in the column id starts with 5, use:
SELECT * FROM events WHERE id REGEXP '^5.'
regular expression metacharacters
. match any character
? match zero or one
* match zero or more
+ match one or more
{n} match n times
{m,n} match m through n times
{n,} match n or more times
^ beginning of line
$ end of line
[[:<:]] match beginning of words
[[:>:]] match ending of words
[:class:] match a character class
i.e., [:alpha:] for letters
[:space:] for whitespace
[:punct:] for punctuation
[:upper:] for upper case letters
[abc] match one of enclosed chars
[^xyz] match any char not enclosed
| separates alternatives  

-----------------------------------------------------------------

 Date difference in Javascript 

Calculate the days difference between two dates in Javascript.

var knownDate = new Date(2008, 10, 25) //Month is 0-11 in JavaScript.
var today = new Date(); // Tue Dec 16 11:42:52 IST 2008
var one_day = 1000*60*60*24;
var Diff_date = Math.ceil((knownDate.getTime()-today.getTime())/(one_day));  

-----------------------------------------------------------------

Vi Editor user guide 

Below link provide full reference to vi editor... enjoy
http://www.cisco.com/univercd/cc/td/doc/product/atm/l2020/l2020r21/clicard/npos/viedit.htm#xtocid84161

No comments:

Post a Comment