Categories
Tips

Using Firebug Console to log from GreaseMonkey Scripts

This is for all Greasemonkey developers who also use Firebug. Firebug is one of the best Firefox extension for developers.

To start with, almost every Greasemonkey developer uses built-in API method “GM_log()” to log debugging messages to Firefox’s javascript console.

While normal javascript developers use Firebug’s API method “console.log()” to log debugging messages to Firebug console.

Now problem is, if you try calling “console.log()” directly from Greasemonkey scripts, it will not work. As Firebug’s console object reside outside Greasemonkey scripts scope.

ADVERTISEMENT

There are few workarounds to use Firebug console to log Greasemonkey debugging messages. But one which always work for me is detailed below.

Simplest way is to use…

unsafeWindow.console.log()

You can use other firebug logging functions similarly by prefixing unsafeWindow to them. Complete information about Firebug console can be found here.

ADVERTISEMENT

Next what if you are editing your older Greasemonkey script! A simple way to use text-editors search-and-replace feature and replace all occurrences of “GM_log” with “unsafeWindow.console.log”.

Well it may be nice for some but geeks way is different! I will recommend adding following lines of code at the beginning of your Greasemonkey scripts.

if(unsafeWindow.console){
   var GM_log = unsafeWindow.console.log;
}

The beauty of above codes is, it will first check if Firebug console is available. If yes, then all output from GM_log will be sent to Firebug console. And when Firebug is not available, it will simply use Firefox’s built-in javascript console without any error!

Next if you want to switch back to Firefox’s built-in javascript console, you can do that by just removing or commenting above code.

ADVERTISEMENT

Disable logging for all GM_log calls…

While developing Greasemonkey scripts, we use GM_log a lot to speed-up coding. But once we are done, ideally we should remove all unnecessary GM_log calls from script as keep Firefox or Firebug console busy.

But this may not sound good idea for some guys who code scritps for sites which changes so often. So better approach is to disable logging via GM_log by adding one line of code, as below, in the beginning of script.

var GM_log = function (){};

This will basically assign an empty function to GM_log. Even smarter approach is to use code like below…

var GM_Debug = 0;

if(!GM_Debug) {
   var GM_log = function(){};
}

Now all you have to change one character to enable/disable logging.

If you have noticed you are basically assigning a different function to GM_log to override it. Those who are new to javascript may find it little strange, but its perfectly valid!

Categories
Tips

How I Made $332 From One Post!

Yep, you got it right, its $332 I made from one single post! And now as I look back I feel I could have made at least twice more than that!

If you are a reader of this blog, then you may have came across my post titled – Get Unlimited Bandwidth & Storage with Dreamhost. It was about a very limited, once-in-a-lifetime kinda offer.

I not only host this and many other websites/blogs with Dreamhost but also actively use its affiliate program. But $332 with one single post was unthinkable. Well it happened with me and here is my analysis but first let me show you screenshot of my Dreamhost reward panel.

As you can see there are five $47 and one $97 reward entries in 7 days window i.e. from September 5 (when I made post) to September 10 (last day to fetch ‘unlimited’ offer). Now lets do some simple math : 5x$47 + $97 = $332.

Apart from this jackpot, I have been always successful with Dreamhost affiliate program because…

ADVERTISEMENT
  1. Dreamhost is really best webhosting service overall. Mind my use of word “overall” as its unfair to compare performance of Dreamhost with a dedicated server solutions.
  2. Dreamhost is beyond a webhosting service. There is a large community of Dreamhosters, who runs dedicated forums, wikis, blogs where you will find lots of information as well how-to guide on every single topic related to webhosting.
  3. They have nice affiliate program which not only pays your webhosting bills but also generate lots of hard-cash if used smartly. By the way I was not aware about this fact while signing up for Dreamhost. I was not aware about promo-codes either! It still hurts to loose those $97 in discount. πŸ™
  4. Above all is about Dreamhost’s greatness but what I think works best is the fact that I am promoting something which I use myself. πŸ™‚

I was sure about nice response to that post about as it was really a great offer. But at the most I was expecting 1 or 2 signups. And now when it brought me $332 via 6 signups, I feel I underestimated it because…

ADVERTISEMENT
  1. I don’t use “Featured Post” like option as Darren Rowse use on Problogger. I am sure that in this special case, it would have helped me get at least 5 more signups.
  2. I did not use service like Digg, Stumble Upon to promote that post.
  3. I know some people who were thinking about switching to Dreamhost from long time. I guess I should have mailed them that article.
  4. I could have written a follow up or reminder post on say September 9, with title like “Last Day to Grab Unlimited Webhosting” or something like that.
  5. There are popular forum related to webhosting. I could have used them.

Well opportunities are countless. Next time, I may follow above 5 points only to discover more of them at the end of the party.

Anyway my purpose of posting this story is to tell you that affiliate programs do work if used smartly. AlsoΒ  there are more ways to monetize your blog beyond Google AdSense! πŸ™‚

Link: Signup for Dreamhost (promo code included in link)

Categories
Tips

Google Chrome for Mac and Linux

Google’s open source browser is now unofficially ported to Mac and Linux by geeks at CodeWeavers.

Officials ports for non-Windows OS are under-development and will take some time to hit your desktops. But those who are eager, can try Crossover Chromium.

On Mac, it will support Intel based OS X 10.4 or higher. PowerPC Macs are not supported. On Linux side you can run it on almost all distributions.

Crossover is a standard Mac app which allows you to install many popular Windows applications and games on your Intel OS X Mac.

I tested it on my Macbook Pro. It took a lot of time for first-time initialization. And Overall application performance is also bad. I hope Linux users find some better result. Personally, I will wait for official Port. I don’t like Chrome much but as a web-developer I have to check my designs and services in Chrome to as it is gaining large pie of browser market share.

Link: Crossover Chromium

Related: Googles Chrome’s Features and alternative Firefox Plugins for same

Categories
Reviews

Dreamhost Allows 50 GB of Personal Backup Officially!

A good news for all Dreamhosters and people considering moving to Dreamhost.

As you many know Dreamhost offers 500GB storage which increases further by 2GB per week. But many people are unaware that this large storage space meant to store data related to your website and using it for personal backup used to result in violation of Dreamhost terms of service (ToS).

Above ToS clause created a lot of debate in past and listening to requests from community, Dreamhost, in their recent newsletter announced that they will allow 50 GB of personal backup. If you need more space then its available too at unbelievable price of 10 cents per GB per month.

Now if you use a good FTP client with nice sync feature then you can backup your important folders automatically without buying any expensive backup solution.

ADVERTISEMENT

Only restriction on this 50 GB is that you can not server files from it on your website or share them with others. I see this is no problem at all as you have your other 500 GB to do that.

Actually this backup will be maintained by special backup user. You can activate it from Dreamhost web panel.

For those who care about security, you can select between normal FTP or secure FTP access for this special backup account. Its nice to care about security, specially when you have your personal data at stake!

Link: Get $50 off while signing-up for Dreamhost (Read More…)

Categories
Tips

Enable Right-Click On Any Website (Including Orkut)

There are many websites which prefer to disable right-clicking on web-pages specially images. To do this they normally use one of JavaScript ways.

The most popular way is to add following code to element tag on which you want to disable right-clicking.

oncontextmenu="return false;"

For example, say you have code for an image like below…

ADVERTISEMENT

<img src=”something” />

Change it to…

<img src=”something” oncontextmenu="return false;"/>

Now reason I am posting about this is, popular social networking site Orkut, which I use quite often, started using code like above and disabled right-clicking on album images.

ADVERTISEMENT

So as usual, we got to do something to get back our right to β€œright-click”!

GreaseMonkey Script: If you use Firefox and GreaseMonkey, then easiest way to enable right click on any website is to install right to β€œright-click” script.

JavaScript: If you are not fond of GreaseMonkey, then you can try following JavaScript.

javascript: var items = document.evaluate('//*[@oncontextmenu="return false;"]', document, null, 7 , null); for ( i = 0; i < items.snapshotLength; i++){items.snapshotItem(i).removeAttribute('oncontextmenu');};void(0);

Bookmarklet: You can also use this bookmarklet in Firefox and other standard-compliant browser.

ADVERTISEMENT

Internet Explorer: If you are an IE user, specially IE 6 then paste following code in address bar and hit enter whenever you stuck. Please note code below is for Orkut only and most likely to break anytime.
javascript: document.getElementById('m').oncontextmenu="";void(0);

Important Note:

From above all solutions, I am planning to take GreaseMonkey solution further. I will add more anti right-clicks hacks soon. As of now this script takes care of most famous way so it should work on many sites.

We can not blindly set “oncontextmenu” attribute to null or “return true” as some sites provides useful functions by overriding browser context-menu. WordPress, Google docs are some popular examples.

If you find a site where right-click is disabled and this script is failing to work,Β  please leave a comment below with page URL and element description where it failed to work. I will try to update this script ASAP.

Link: Install Right to β€œRight-Click” Script (How?)

Related: JavaScript to Unmask Password on Web Pages

Categories
Reviews

Dreamhost Pending Rewards Calculator [Greasemonkey Script]

I have just created a Greasemonkey script exclusively for Dreamhost. So those who do not use Dreamhost may not find this of any use.

Now this script makes it easy to track your pending rewards under Dreamhost referral program. If you ever used it, then you may know that whenever someone sign-up using your referral link, any commission you earned kept pending for 97 days.

By default, Dreamhost reward panel shows date of joining with other information. I found its quite painful to calculate mechanically how many days left for each pending referral to cash-out. So this script simply add “X days Left” kind of meta-information next to each pending link.

Here are screenshots…

#Before Script:

#After Script:

This is Greasemonkey script. So you will need Firefox and Greasemonkey to make it work.

Link: Dreamhost Pending Reward Days Calculator

Related: Get $50 off while signing-up for Dreamhost (Read More…)

Categories
News

New Facebook with New Application Menu

Facebook recently added new application menu to their new interface. With the new application menu, they are making better use of screen-space. Facebook’s bottom-chat bar is now useful to users who do not like to chat at all or like to chat using desktop clients.

This is good news for facebook application developers too as they were little disappointed by new facebook design which is more “user-centric”.

As a user, I just hope that applications won’t be able to add themselves to this new application menu on their own. Between I think there is limit of only 6 icons in bottom-bar which will prevent applications cluttering up your page.

From last few weeks, I observed very less application spam-invitation. I am not sure its about new facebook or my low usage of facebook. If you have noticed any improvements, please share with us.

If you are still having problem with applications’ invitation spam, you may consider using our Block-All or Ignore-All applications invitation with one-click scripts which are still better than Facebook’s “ignore-all” option.

Categories
Analysis

What Made Google Drop β€˜O’ From Its Logo! [Answer]

Form last few days a post by Brian Brown on SEOMoz about Dropping β€˜O’ from Google logo on search result page is creating buzz. After investigating entire issue in detail, here I am posting my reasoning.

First and most important, if you have missed it, appending &num=100&start=990 to any search URL forces Google to drop second β€˜o’ from logo they display on search result page.

To make difference clear, I am posting original and modified query around with relevant portion of Google search result pages…

Original Query: http://www.google.com/search?q=Rahul

Rahul - Google Search-1.jpg

Modified Query: http://www.google.com/search?q=Rahul&num=100&start=990
rahul - Modified Google Search .jpg

As you have might have noticed there is no yellow colored β€˜o’ in modified search result page.

You can also obtain same modified search result page from appending &start=991 to original query. In fact any number equal to or greater than 991 after β€˜start’ will force yellow β€˜o’ to be dropped. Try This.

ADVERTISEMENT

Lets move to reason part now…

ADVERTISEMENT

Google is fooling us… πŸ˜‰

If you have noticed, on modified query page, just below search box Google says, β€œSorry, Google does not serve more than 1000 results for any query.”

First conclusion – Google is fooling us by saying it has few million results for popular search term like paris hilton. In fact they never had more than 1000 results for any search term! May be they had it in past, but today, even for sex, they says sorry… like above.

Mysterious yellow β€˜o’…

ADVERTISEMENT

On Google search result pages, Google logo we see is made of separate images. Yellow and red β€˜o’ are rendered from different images. If there is only one search result page (check this), the Google logo at bottom of search result pages highlighted in below screenshots never shows up. For each extra search result page (upto 10, on each side), a yelllow β€˜o’ image is inserted which link to relevant search result pages.

Check following logo captured from this query page…

rahul - Google Search yello _o_ .jpg

or check this…

_rahul bansal_ blogger pune - Google Search.jpg

As you can see number of yellow β€˜o’ changes for different query.

Conclusion – How many number of yellow β€˜o’ will show up depends on number of search result pages. For β€˜no result’ and β€˜only one result page’ conditions, no Google logo showed at all.

ADVERTISEMENT

Connecting the β€˜o’s…

Its apparent that Google handled two exception conditions but forget to add a condition like, β€˜if user request results beyond first 1000, do not show logo’ at all.

Google is smart enough to prevent user going to error page from navigation links. Check this query. This is last one, so do not loose your patience! πŸ˜‰

Google Search Mystery.jpg

The above one shows results #981-992, just before hitting limit of 1000. Above one does not have next link!

Google in fact, partially anticipated query modification via URL change and put error message β€œSorry…” on search result pages beyond 1000. They just forgot to remove bottom logo generation logic from such pages.

ADVERTISEMENT

As logo logic is there without any linkable result page, Google logo renders without any yellow β€˜o’. NO result page means NO yellow β€˜o’… !

Red β€˜o’ in logo always stand for current page and is not hyperlinked. But depending on search query upto 9 yellow β€˜o’ inserted.

In the end…

Revelation – You come to know how Google fooled us by showing some pseudo-count of millions of search results for popular queries. πŸ˜€

Apart form this, there is nothing else except fun! If you think you owe me something for the revelation (or fun), you can instantly clear your debts by donating some bucks for my baby Orkutfeed! πŸ˜›

Categories
News

PHPCamp Pune – Lets Geek Up!

phpcamppune08 - PHP Camp Pune September 2008-1Those who are familiar with BarCamp can immediately guess that PHPCamp is unconference for PHP.

For rest, PHPCamp is event for all PHP programmers where you can show off your expertise in any area related to PHP. If you are new to PHP you can just attend this event to learn some great things about PHP.

You can register for event by adding your name here. Registration is free of course and you will get a free T-Shirt too. πŸ˜‰

I am attending this event for sure. As of now, I haven’t decided about speaking yet. Actually I am into so many areas of PHP, choosing a topic is little confusing.

ADVERTISEMENT

If I get time, I will most likely prepare a talk on wordpress plugin or facebook apps development, of course from PHP programmers perspective.

Rest, if you want to listen something, please let me know. If I find your suggestion interesting, I will try to prepare a talk on it myself or request any fellow PHP programmer to take initiative.

So lets geek-up at PHPCamp!

Link: PHPCamp | Registration

Date: 20th September 2008 (saturday) .

Time: 10:00am to 6:00pm (Whole day event) .

Venue:

Persistent Systems Pvt. Ltd.,
Plot No. 9A/12, CTS No. 12A/12,
Erandwana,
Near Padale Palace (Opp Sharda Center),
Pune – 411 004

Google Map:
View Larger Map

Categories
Tips

Related Post Solution For Blogspot Blogger

Google for wordpress related posts plugin and you will find many of them but for Blogspot Blogger situation is was quite different.

Mohamed Rias posted a solution which involve some Blogger template hacks but solves long pending related post problem. He described all modifications in very clean and simple manner so I think every Blogger can benefit from it.

Below is screenshot of a blog using this hack…

Related Posts for Blogger

For codes and instructions check Mohamed Rias’s post. Thanks Debajyoti Das.

Link: Related Post Solution for Blogspot Bloggers

Related: Google AdSense Tricks for Blogspot Bloggers