Discover the power of algorithms

Complexities of algorithm, thier applicability. Optimization techniques associated with diffrent algos.

Discover Power of Blogging

What is Blogging , is it a Dream or Passion or Award or Making Money ?

Think Diffrent, be creative

Let's see how much conclusion one can draw from it. This will help testing your creativity.

Discover the power of technology

Technolgy, Programming, Optimization , Gadgets and more...

Discover the power of Blogging

Google widgets and gadgets.

Sep 23, 2011

Google In Page Analytics

Yet another awesome innovation from Google.A very important SEO tool, it actually helps one to visualize click views performed on a web page. Google recently launched In Page Analytic  for this which can be found under Content section of Google analytic.


 It enables you to visually analyze your website pages in order to assess how users interact with those pages, and helps you understand the answers to questions as per Google Analytics such as:






  • Is my page layout optimal for what I want users to accomplish on the page?
  • Are my users seeing the content I want them to see?
  • Are my users finding what they're looking for on the page?
  • Are my calls to action motivating or visible enough?
  • Which links are users clicking?
Here is the image for my web page:-


It's really great to see In-Page-Analytic report.
For more details one can refer :- 
http://www.google.com/support/analytics/bin/answer.py?answer=178902

For SEO purpose this analysis report is very helpful, Try it out.



Sep 20, 2011

How to add adsense to blog using javascript

Untitled Page
Google Adsense can be easily added with the help of javascript in any poart of post.

 Lets look at the simple steps for doing it :- 
1) Go to the edit post of your blog.
2) Select HTML edit mode.
3) Insert following javascript to your HTML.

Below is the example of leader board Adsense :-
-------------------------------------------------------------------------------------------------------------------------
          

<script type="text/javascript"><!--
google_ad_client = "ca-pub-9274462217825187"; //change your pusblisher id
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "E8E7D0"; //change background color from here
google_color_bg = "dcdcdc"; //change back ground coloe from here                  
google_color_link = "B96F17"; //change link color from here
google_color_url = "B96F17"; //change url color from here
google_color_text = "000000"; //change text color from here
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
script>
-------------------------------------------------------------------------------------------------------------------------
4) Save your post and you done with Adsense emebed into your post.
Above adsense javascript code will return some thing like below in your blog post :-



















How to change the Adsense Unit Size ?

Next important point is to change the adsense layout using javascript.
Follow below step to change the :-
1) Go to the adsense javascript.
2) Change the hieght and width field , get the value of hieght and width from the image shown below:-
:
3) After changing the hieght and width, change the "google_ad_format" value in "width_height_as" format, example :-
     google_ad_width = 336;
     google_ad_height = 280;
     google_ad_format = "336x280_as";


4)  Just save it after changing the value, and you are ready with new Adsense unit size. Choose unit size according to your website/blog.









Sep 18, 2011

List of Blog Post Gadget for blogger using javascript

Blogger Data API Sample

Following post will help in retrieving the information related to list of post from a blog. One can use this to display the list of blogs by following easy step mentioned below

 1) Add one html/javascript gadget to your blog.

2) Copy paste below code to your gadget.

3) Replace feeduri with your blog feed uri.

           var feedUri = 'http://www.blogger.com/feeds/10861780/posts/default';

 4) just save the gadget and its ready to use. Here goes the code for list of post for a blog :-








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

/* 
* Retrieve a list of blog posts
*/

// Obtain a reference to the 'content' div
var content = document.getElementById('content');

// Create the blogger service object
var bloggerService =
    new google.gdata.blogger.BloggerService('com.appspot.interactivesampler');

// The feed for a single blog. (In this case, the Official Google Blog.)
//
// The ID included in this URI can be retrieved from the
// <link rel="service.post"> element in the Blog's HTML source
var feedUri = 'http://www.blogger.com/feeds/10861780/posts/default';

// A callback method invoked getBlogPostFeed() returns data
var handleBlogPostFeed = function(postsFeedRoot) {
  var posts = postsFeedRoot.feed.getEntries();
  
  // This variable will buffer HTML output until function completes
  var html = '';
  
  // Display blog's title
  html += '<dl>'
       + '<dt><strong>Blog:</strong> '
       + '<a href="'
       + postsFeedRoot.feed.getLink('alternate').getHref()
       + '">'
       + postsFeedRoot.feed.getTitle().getText()
       + '</a></dt>';
  
  // Display blog posts
  html += '<dd><ul>';
  for (var i = 0, post; post = posts[i]; i++) {
    var postTitle = post.getTitle().getText();
    var postURL = post.getHtmlLink().getHref();
    html += '<li><a href="' + postURL + '" target="_blank">'
              + postTitle
              + '</a></li>';
  }
  html += '</ul></dd>';
  
  // Write out buffered HTML, and clear the "Loading..." message
  content.innerHTML = html;
};

var handleError = function(error) {
  content.innerHTML = '<pre>' + error + '</pre>';
};

bloggerService.getBlogPostFeed(feedUri, handleBlogPostFeed, handleError);

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

 

Below is the demo of above code for my blog :-

 





Loading...



Sep 15, 2011

Postfix to Infix Algorithm


I have come across one very interesting query about Postfix to Infix conversion.

Let’s understand first the importance of having Postfix notation:-


·         To reduce computer memory access.
                     The automatic stack permits the automatic storage of intermediate results for use later: this key
               feature is what permits RPN calculators to easily evaluate expressions of arbitrary complexity: they
               do not have limits on the complexity of expression they can evaluate.
·         To utilize the stack to evaluate expressions.
·         To reduce the complexity of expression while evaluation.
·         Postfix notation is often used in stack-based and concatenative programming languages.

Postfix to Infix Algorithm
Let’s look out for the algorithm for converting postfix to infix expression:-
§  While there are input symbol left
§  Read the next symbol from input.
§  If the symbol is an operand (i.e. value)
§  Push it onto the stack.
§  Otherwise, the symbol is an operator.
§  If there are fewer than 2 values on the stack
§  (Error) The user has not input sufficient values in the expression.
§  Else, Pop the top 2 values from the stack (operand1 & operand 2).
§  Put the operator, with the values as arguments and form a string (like : operand1 operator operand2).
§  Encapsulate the resulted string with parenthesis. (like: (a+b)  if operand1 =’a’, operand2 =’b’, operator = ‘+’ )
§  Push the resulted string back to stack.
§  If there is only one value in the stack
§  That value in the stack is the desired infix string.
§  If there are more values in the stack
§  (Error) The user input has too many values.



Postfix to infix will not give you exact expression in terms of parenthesis, though it will give you same result on evaluation.

e.g. (a+b+c)*2
Postfix will be :- ab+c+2*
And postfix to infix will give :- (((a+b)+c)*2)





Distance Google MAP API demo

Google Maps API Sample


Google Maps API Directions Illustrated

Enter Location in format #place,#city

Experimenting with google maps api, i have developed this quick utility to show the distance and duration between locations. TRY IT OUT

From:    To: 
Language: 
Distance:  KMs
Duration:  Minutes



Formatted DirectionsMap



Sep 14, 2011

Distance between two locations with Google Map API

One can easily calculate distance between two location with the help of Google Map APIs. Google Map APIs comes with a set of classes which helps in doing such tasks.
class GDirection, helps in getting the travel distance between the two different location.
So example shown below targets following features :-

  •  Getting distance between two location. 
  •  Getting duration between two location. 
Here goes the complete java script code for it
-------------------------------------------------------------------------------
    <script type="text/javascript">
    var map;
    var gdir;
    var geocoder null;
    var addressMarker;
    var distance;
    
    function initialize({
      if (GBrowserIsCompatible(){      
        map new GMap2(document.getElementById("map_canvas"));

        gdir new GDirections(mapdocument.getElementById("directions"));
    
        GEvent.addListener(gdir"load"onGDirectionsLoad);
        GEvent.addListener(gdir"error"handleErrors);
    
        setDirections("San Francisco""Mountain View""en_US");
      }
    }
    
    function setDirections(fromAddresstoAddresslocale{
      gdir.load("from: " fromAddress " to: " toAddress,
                "locale"locale });
    }
    
    function onGDirectionsLoad()
        // Use this function to access information about the latest load()
        // results.
        // e.g.
      distance gdir.getDistance().meters;
      
      alert("Distance is : " gdir.getDistance().meters "and Duration Is: " +
            gdir.getDuration().seconds/60);
        
      document.getElementById("fdistance").innerHTML gdir.getDistance().meters;
      document.getElementById("fduration").innerHTML gdir.getDuration().seconds/60;
      
    }
    script>
 -------------------------------------------------------------------------------




Can we call GDirection without creating GMap ?
  So the answer is yes, one can create GDirection without pasing GMap also.
So the output will only contain text format.
sample code
       gdir new GDirections(nulldocument.getElementById("directions"));
so instead of map object null is passed in above code line, it will
display direction information in only text format.
One can also use above logic to design their own Google Gadgets too.



Sep 11, 2011

new vs malloc ?

C++ often confuses beginners with its multiple way to allocate and free memory. Most of them understand them that free must be used with malloc and delete with new. But still they are not clear with the differences. This article will help in understanding the concept behind new and malloc.

Lets see the broader level differences first :-


  •  'new' helps in constructing an object (calls constructor), malloc does not. One of the most important differences between them.
           e.g. Consider a
           Class A { 
           public : A() { cout <<"In constructor"; }
           }
           
          A* pobjA =  new A(); //this will call constructor and displays "In constructor"
          A* pa       = (A*) malloc(sizeof(A));  //this will not call constructor
  • new requires type of object to be allocated, malloc requires you to specify the total number of bytes to allocate.
  • operator new is an operator, malloc is a function.
  • operator new throws an exception if there is not enough memory, malloc returns a NULL.                   As both function help allocating memory dynamically, there are chances for run-time failure due to non availability of memory. For such cases both shows different behavior and hence need to be handled accordingly.
          very important pint to be noticed over here is
When new is used to allocate memory for a C++ class object, the object's constructor is called after the memory is allocated.
  • operator new can be overloaded, malloc cannot be overloaded.
  • operator new/new[] must be matched with operator delete/delete[] to deallocate memory, malloc() must be matched with free() to deallocate memory.
Another big question is

How to choose between malloc and new ?

While working with C++, its always recommended to use "new", because it has additive advantage over malloc which are:-
  • Its type safe.
  • It calls constructor and helps in implementing very important Object Oriented feature Inheritence (constructor chaining). 
One can though use malloc while working with buffer (non class and struct base) , which they want to resize with time with the help of realloc. But still it can be achieved with the combination new/delete too.

How much one can allocate ?

One more query one can have now is, "How much one can allocate"? The largest possible memory block malloc can allocate depends on the host system, particularly the size of physical memory and the operating system implementation. Theoretically, the largest number should be the maximum value that can be held in a size_t type, which is an implementation-dependent unsigned integer representing the size of an area of memory. The maximum value is 2power(CHAR_BIT*sizeof(size_t) − 1), or the constant SIZE_MAX in the C99 standard.

More relevant article:-





Sep 10, 2011

Post a Suggestion/Query

Open post for adding suggestions/queries to be considered for next posting.


Queries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and SuggestionsQueries and Suggestions