Wednesday, April 28, 2010

Adding Custom Search to your Blogspot Blog enhances its value and allows visitors to sift through your posts with ease. Adding Google Custom Search is not simple or for the fain at heart. It requires tons of patience, a keen eye and a good comfort level at playing with code. For a live demo, I have added the same to my blog as well, so feel free to try it out! Adding Google Custom Search is not simple, here are the steps that are required:

Create a static page on Blogger for displaying Search Results

Sign Up for Google AdSense - if you want to earn money

Sign Up for Google Custom Search

Update the static page with Google Custom Search Code

Remove side bar & meta-data displayed on the static page

Add search box on side bar

So here goes, get ready to get down & dirty with the details ...

1. Create a static page on Blogger

Create a static page on Blogger for displaying Search Results. Go to Posting > Edit Pages and click on the New Page button to create a new static page. Set the title as Search Results or anything appropriate and for now, enter placeholder text Search Results in the page. View this page and note down the URL of this page - this will be used in the later steps when configuring Google Custom Search.

2. Sign Up for Google AdSense

If you want to earn some money through the searches that are done on your site, you will need to sign-up for an adsense account. Here I am assuming that you already have one - if not, then just go ahead and sign up for one.

3. Sign Up for Google Custom Search

From inside the AdSense account, click on the link AdSense for Search and then follow the steps below:

Click on Single Page link at the top to view all the options in one page

Search Type: Select Only sites I select

Selected sites: If you have more than one site, enter one site per line for each of the websites you want to include in the search.

Optional Keywords: Enter keywords separated by space if you want to give hints to the search engine.

Opening of search results page: Select Open results within my own site and in the box below for Enter URL where search results will be displayed, enter the URL of the static page created in Step 1 above.

Ad Location: You can choose whichever option you like, but I personally prefer to go for Top and Bottom

Name Your Search Engine: give a name for your custom search engine

Fill in all the other remaining fields as per your requirement

Press the Submit and Get Code button to get the Javascript code that you need to put into the static page

4. Update static page on Blogger

Go to Posting > Edit Pages and click on the Edit link for the static page created above. Then:

Copy code from Search box code and paste it here

Enter a break tag <br>

Copy code from Search results code and paste it here

5. Remove side bar & meta-data displayed on the static page

Now this is the tricky part which requires you to change the template. You can skip this step if you are OK with having the widgets display on the right column.
Note: take a backup of your template before proceeding!
Go to Layout > Edit HTML and check the box Expand Widget Templates. Then add the line:
to the following 3 places:
To remove the Post Metadata (Author, Tags, Time) from Static pageLines 1 and 19 in this code snippet

Thursday, April 15, 2010

A friend asked me to help implementing reCAPTCHA with classic ASP which I successfully managed to implement even though I have not dabbled much with ASP - read the implementation here.
So now the expectations rise and he asks me to validate reCaptcha using AJAX - I do not have any experience of AJAX combined with ASP either.

Going through the resources section of the recaptcha.net site did not help much in this regard. So here are the steps that I did to achieve this. Note that most parts of the solution here have been taken from various pages on the net which are listed at the bottom of this post in the References section.

There are 6 parts of the code as follows:

JavaScript to create reCaptcha on the page that has the input form

Insert the created reCaptcha in the desired location

Generic JavaScript to make AJAX call

Make AJAX call to Server-side component to validate reCaptcha

Handle AJAX validation response from server-side component

Server side component to validate the reCaptcha

1. JavaScript to create reCaptcha on the page that has the input form
Here is the code that needs to be placed in the ASP file to generate the JavaScript which when called, generates the code for reCaptcha. The generated string needs to be placed in your form where you want the reCaptcha to be displayed.

2. Insert the created reCaptcha in the desired location
Here is how you need to place the code in your form where you want the reCaptcha to be displayed.

3. Generic JavaScript to make AJAX call
Here is a generic JavaScript function to make an AJAX call

4. Make AJAX call to Server-side component to validate reCaptcha
Here is the JavaScript "onClick" function that will make the specific call to the server-side component to validate the reCaptcha input.

5. Handle AJAX validation response from server-side component
Here code that needs to be put in the asp file that processes the submitted form.

I had been putting off using Syntax Highlighter for quite some time as it required me to host the files somewhere and then use them. Also, using it for a Blogger Blog did not seem to be so straight-forward and did not produce clean results. This was the status when I had last checked it out quite some time back.

So when reviewed a post I wrote with a lot of code in it, I was saddened that I had not add Syntax Highlighter to my blog. So I decided to take a second look and was pleasantly surprised to see both my issues resolved! Now there was an option for using the hosted version of the files and also there was a very neat blogger mode!

So now finally, you don't need to look around for someone to host the Syntax Highlighter files for you - you can use the hosted version of the Syntax Highlighter files. And there is a very good bloggerMode! which helps to integrates very cleanly with Blogger.

A friend of mine was very impressed with reCaptcha and wanted me to help him implement on his website that uses classic ASP! Going through the posts mentioned in the reference below gave me a bit of an idea but the solution was not very clear. Here's how I finally implemented it...
There are 3 parts of the code as follows:

JavaScript to create reCaptcha on the page that has the input form

Insert the created reCaptcha in the desired location

Server side component to validate the reCaptcha

1. JavaScript to create reCaptcha on the page that has the input form
Here is the code that needs to be placed in the ASP file to generate the JavaScript which when called, generates the code for reCaptcha. The generated string needs to be placed in your form where you want the reCaptcha to be displayed.

Of course, you need to sign-up for a free reCaptcha account at reCaptcha.net.

The code in step 3 above needs to be put in the top of the file which processes your submitted form - the asp file that is mentioned in the action of this particular form. The above code needs to be executed before anything else in that file.

It's regular processing steps should be put in the if block (line 37) that has the comment that the user answered the captcha correctly.

Error message display logic should go into the else block (line 40) that has the comment that the user answered the captcha incorrectly.

Remember to substitute the public & private keys with the ones that you get when you sign up for a free reCaptcha account.

This is a very basic, no-frills version. You can modularize, clean-up, optimize and add more error-handling. But this should be good enough to get you started!

I sure got my travel mug today and got free coffee from Starbucks. Starbucks is offering free coffee today (April 15th) to encourage people to reduce usage of paper cups - read my post about that here. This opens up the debate that whether these kind of programs really work? Here's my take ...First hand experience - lugging around the travel mug is a pain which I am not ready to do everyday. The coffee was good, but cleaning the travel mug that has a narrow bottom was real pain as well. And God save you in case you got caught up in work / meeting and the leftover coffee in the travel mug dries up - cleaning it will require way more effort than you can imagine. These are the non-material negatives to using the travel mug.

Now coming to the material aspect - buying a travel mug costs some dough and if you go in for a "cool" one, get ready to be set back by at least 10 bucks. But that's only one time for however long you can manage to hold onto the mug. However, washing the travel mug with (running) hot water and soap after every use will require investing in soap & scrubber, add to the bill for heating water and use up your time {Remember - Time = Money!}. Also, producing the energy to heat the water may not be exactly soft on the planet either - but we may not know or notice that exactly.

Now for the psychological aspect of this issue. Most people will take this campaign as an opportunity to get *FREE* coffee. Many people may even drive extra miles just for this and in the process end up spending the cost of the coffee on gas instead! And from the very next day - most people will revert to their normal routine and use (and throw away) paper cups, tissues, plastic cutlery left and right as usual. Very very very few people would actually have a change of heart and
change their habits in a single attempt of such a one day campaign.

Even if I had not got the chance to get the free coffee, I would have sub-consciously noted that this is a good company which I should patronize the next time I am going to buy a product that they offer. This gives the company huge advantage over the competition. So in the end, what is gained is that people got free coffee and the company scores brownie points for being & encouraging people to go green as well as get a lot of cheap, effective & useful advertisement.

Wednesday, April 14, 2010

Starbucks is trying to make a difference through its The Big Picture Green Project. Starbucks is asking general public to join the movement and on April 15th, it is encouraging people to reduce their usage of paper cups by giving free brewed coffee to those who bring in a reusable travel mug into their local Starbucks store. Their quote: One person can save trees, together we can save forests. is really worth working towards!

It is good to such big corporations like Starbucks sharing their responsibilities towards our communities and the planet and trying to make a difference. I wish more corporations follow the lead and do such campaigns to make this planet a better place to live in!

Thursday, April 8, 2010

My friend has an ASP shopping cart running on Windows 2008 Server + IIS7 + SQL Server. This cart does not support SEO / user friendly URLs and apparently due to that, his site was getting very low rankings on the search engines. He called me in to help him out implement URL Rewriting to resolve this. Here is my experience with this problem and finally how I went about resolving this.
So the first step was to install the URL Rewrite Module 2.0 for IIS. Next was to configure the rewriting of the URLs - the cart produced URLs of the form store/listItems.asp?cat=123&item=456. The item id number and the corresponding category id number changed for different items so putting in a generic regular expression would not work. So we would need to create static rewrite maps to achieve our goal.

So I created a rewrite map with entries like /store/listItems.asp?cat=123&item=456 mapped to /Item1 and /store/listItems.asp?cat=123&item=457 mapped to /Item2 and so on. This worked but the page did not come up properly. Investigation revealed that this was due to the HTML having relative URLs for CSS, Image & JavaScript files. I changed paths to absolute paths and lo-behold it was working fine! However, when using the user-friendly URL, the pages would come up quite slow compared to the page display using the old URLs.

In fact the pages came up so slow that we had to scrap this idea and look for other alternatives. Finally, after a lot of investigation, we fixed on the ages-old method of creating static HTML index files in folders named by each category. The header, footer & navigation menus would be common and kept in common folder. I know that this is not such a good idea and will result in creation of hundreds of folders with only an index file. But what the heck - it is simple, it works and it gets the job done!

Friday, April 2, 2010

It seems that April is the month for Cheap Web Hosting Deals!!!
Here is a round-up of the cheapest (but not necessarily the best) web hosting deals I found out.

However, my personal favorite is always BlueHost for their excellent support & fast servers. Check out my post on the same here.

NOTE: No guarantees on the validity of the offers or the quality of the services. I am in no way connected to any of these hosting companies and the links provided are direct links (no affiliate tracking code). I do not gain in any way from you clicking on any of these links and/or signing up for any of these offers!!!

Lifetime Webhosting for $79HostSure is offering a full featured lifetime web hosting for only $79 where most companies offer that for $60-$100/year.

Facade HostFacade Host is offering shared web hosting packages for as low as only only $0.85/month where most companies offer that for $2-$5/month. Use coupon code april for a further 20% discount!

Cookie HostCookie Host is offering shared web hosting packages for as low as only only $5/year where most companies offer that for $60-$100/year. Note that the promotion starts on April 7th 2010 and is valid only for new hosting accounts. The good thing is that they do not automatically rebill you at the end of the first year and you will be given the option to renew at the then prevailing regular price.

Just HostJust Host is offering a full featured unlimited web hosting with free domain for the life of hosting for only $3.45/month when prepaying for 2 years. Use coupon code 50OFF for a further discount to bring down the price to $2.95/month when prepaying for 2 years!

Fat CowFat Cow is offering a full featured unlimited "green" web hosting with free domain for the life of hosting for only $66/year!

Dream HostDream Host is offering a full featured unlimited "green" web hosting with free domain for the life of hosting for only $9.24/year with coupon code 777!

Daily RazorDaily Razor is offering a full featured unlimited web hosting for only $2.95/month. Use coupon code 15PD for another 15% discount!