Monday, August 26, 2013

Get a random color in JavaScript

Computer can understand only hexadecimal color code.

As a science student, you might be known.
Converting a base(x) number to base(n) number.

Same logic we are going to use. In JavaScript we have base conversions.

Math.random() will return a float number. Convert this number to integer as well string too.
While your converting string pass "16" parameter to toString(16) function. So, this way it converts a string to base(16) number.

 Solution :  
1. '#'+Math.floor((Math.random()*100000000)).toString(16)
2.  '#'+(( 1<<24)*Math.random()|0).toString(16)

This function will hep you to generate number of colors as you given input number

var getRandomColors = function(no){
    no = no || 0;
    no = parseInt(no,10);
    var i=0,arr=[];
    do{
        arr.push( "#"+(( 1<<24)*Math.random()|0).toString(16) );
        i++;
    }while (i < no);
    return arr;
}

Friday, March 1, 2013

Wednesday, February 15, 2012

html2text

function html2text(){
var o={};
o.txt='';
o.t = document.getElementsByTagName('*');
for(o.i in o.t){
if(o.t[o.i].childElementCount > 0){
console.log(o.t[o.i].childElementCount, o.t[o.i].tagName);
}else{
console.log(o.t[o.i].innerHTML);
}
}
}

The World’s 50 Most Innovative Companies 2012 | Fast Company

Tuesday, December 13, 2011

Code: logout Api for Linkedin

Hmmm!
It's not an API, simple tric...!
Just JS dynamic image tag solves our problem....

open script tag
new Image().src='https://www.linkedin.com/secure/login?session_full_logout=&trk=hb_signout'
close script tag

njoy...

Friday, November 4, 2011

Various Social n/w And Various Mind Sets...




What ever it may be, Finally audience are defining various roots for various social network portals.