How to generate rainbow colors

Hi There,
At times you might have to generate few colors which almost covers entire rainbow (visible spectrum) range.

Here in this article I am giving away a function which generates as many colors as you want but those colors will try to cover the entire (visible light) spectrum. i.e if you just generate 3 colors you will get Green, Red and Blue. If you generate 100 colors you will get multiple tints of Green, Red and Blue.

Function Name is : getColor(count)
Input count: Number of colors to generate.
Returns : li items with color (as style attribute).

<li class="color" style="background-color:rgb(254,64,54);">  </li>

How it works?
I have taken 3 sine waves, all are with different phase. Each of these sine curve generates my RGB values. Each sine wave will swing from 0 to 2pie (360deg). There has been a bit of normalization just to make the colors look good (in final code).

function getColor(noOfColors) {
    html = "";
    frequency = 5 / noOfColors; 
    for (var i = 0; i < noOfColors;++i) {
        r = Math.sin(frequency * i + 0) * (127) + 128;
        g = Math.sin(frequency * i + 1) * (127) + 128;
        b = Math.sin(frequency * i + 3) * (127) + 128;
        li = '<li class="color" style="background-color:rgb({r},{g},{b});">  </li>';
        li = li.replace("{r}", Math.floor(r));
        li = li.replace("{g}", Math.floor(g));
        li = li.replace("{b}", Math.floor(b));
        html = html + li;
    return html;

                                                                  Demo jsfiddle 

How to extract people/person names from text? (javascript code)

This is a very simple guide which will answer questions like

1) How to extract people/person names from text?
2) How to extract company names from text?
3) How to extract entities from text?

For all of the above we will use Yahoo's Content Analysis API.

Here is simple code (gist)

function init(){
    var contentanalysisURL="*%20from%20contentanalysis.analyze%20where%20text%3D%22{text}%22&format=json&callback=?";
    //this function will be called on json recieve
    function receiveJSON(data){
        //6. recieve Data

            //7.get list of all entities
            var et=data.query.results.entities.entity;

            var out=[];
            var len=et.length;
            for(var i=0;i<len;i++){
                var eee=et[i];
                //8.get entity name
                var content=eee.text.content;
                var startChar=eee.text.start;
                var etypes="";
                    //9.get entity type
                    var typ=eee.types.type;
                    for(var j=0;j<typ.length;j++){
                        var ttt=typ[j].content;
                          etypes=etypes+" "+ ttt.substring(ttt.lastIndexOf('/')+1); 
                //10.Append to dumo array
            //11.update container with output

    //1. hook click event of btget 
    $('#btget').click(function (){
        //2. Get text, length of text should be less than 512 or less. 
        //Note:when text is too large this will not work
        var text=$('#tu').val();
        //3.Update loding message

        //4.Form a GET request, (YQL table )
        var url=contentanalysisURL.replace("{text}",text);
        //5. inject script block in dom with callback as receiveJSON


  Working Demo  

Limitations with Code

  • Does not work with large data, due to limit of URL size. Get Request fails on large URL size. To Fix this read my this article
  • To Extract location name correctly, use geo.placemaker API of yahoo