Google Loco – A Lesson on Event Handling

In the GoogleTV post, the video mentions (briefly) a Google service called Loco. I have decided, for fun, to make this service. Introducing Google Loco. I don’t make a dime from it and I redirect all search traffic to Google.com. Just a funny joke site to show your friends. 😉

Google Loco has some pretty nifty JavaScript that I’d like to share. The main interest is in the script that:

  • In Firefox: flips around the text you type in
  • In all browsers: randomizes the colors

I will cover the text flipping in another post. This one will focus on event handling.

Event Handling Mini-Lesson

What the heck is event handling anyway? Well, that’s the “onclick” or “onmouseover” stuff you have probably encountered. It’s a term for telling the computer to handle and event when something happens. Thus,

onclick=”SOMETHING”

Is read as “do SOMETHING when a CLICK event happens”. Event handling is an advanced topic in JavaScript. So how do we do it in Google Loco?

First of all, I added an event handler that fires when the page loads.  You see, in the old days, people used stuff like this:

<body onload=”initializeOnLoad()”>

But we’re in 2007 now. Things are done differently. The above command now can be redone using event handlers in the following syntax (see the actual site for the advanced, error proof syntax):

window.addEventListener(‘load’, initializeOnLoad, false) // syntax different for IE, see .js file

I know the second one looks more confusing, but it’s better. Why? Because you aren’t mixing business logic with your presentation layer (JavaScript separate from HTML). Secondly, this line can be put anywhere on the page, making it more portable since it can reside inside a JS file.

You’ll notice in the event handler example, initializeOnLoad doesn’t have parentheses after it. This is because, in short, JavaScript treats functions like variables.

When the parentheses are removed it’s like saying “don’t execute me, I’m just the messenger.” My, that was a very clever pun…

Or in other words,  initializeOnLoad() executes whatever is inside that function. InitializeOnLoad (no parentheses) refers to the contents, but doesn’t actually execute anything. This allows you to copy it around, modify it, reassign it, or whatever else you might do with a regular variable. In our case, we assigned it to the event handler for when the page loads.

The page itself uses a “loco” variable. You’ll notice there’s stuff like:

addEvent(document.getElementById(‘typed-box’), ‘keydown’, loco.locoEffects);

This, for example, would grab the element “typed-box”, and cause loco.locoEffect to fire whenever a key is pressed on it. If I had used “window” instead of “document.getElementById(‘typed-box’)”, the event would fire when a key is hit anywhere on the page.

Anyway, that loco.locoEffects thing… That’s a class. Well, a faked class. It’s really a variable called loco with another variable called locoEffects inside it. This inner variable just so happens to be a function.  Why did I do this? Oh, just to keep the global namespace uncluttered (as in, so I don’t have to worry about overwriting a native JavaScript function).

Make Text Come Out Backwards!

This is a very little known secret, but there is a special character that causes browsers to reverse the text it encounters. This feature exists so that right-to-left languages can be displayed, but it can be applied to languages like English!. This character is displayed by typing &#8238; at the beginning of a sentence block. Here is a sample:

Source:

&#8238;Wow, is it all backwards?

Comes out as:

‮Wow, is it all backwards?

Pretty neat huh? To see this in action, visit Google Loco with Firefox. Google Loco will use JavaScript to add this special character as the first character of the search term box. It is mostly invisible in regular browsers, although it can cause a strange square or space to appear at times.

LetsTorrent.com – An Experiment in Google Coop

Last night, I decided to give Google Coop a try. I created LetsTorrent.com.

It’s best features are:

  • I didn’t just pile on every torrent site I could find. I filtered out tons. I only chose ones that described the torrent files, didn’t have popups, didn’t require registration, and didn’t link to content on other torrent sites.
  • No direct links to torrent files so you don’t have to try to decipher gibberish like S03ZSub6_-AAA-325581-[zan].tar.torrent. I had to omit some popular torrent sites due to a lack of having details pages in order to stick to this philosophy. I hope the trade off is worth it.
  • It searches over 70 torrent sites in one shot. And the results are highly relevant.
  • No mirror bullshit. Since I hand-screened every site in the engine, I made sure no two sites stole content from each other. The goal is to ensure you don’t get the same file linked from 10 different sites as 10 different results. You get one.
  • It uses the Google Engine, thus it’s much faster than using the search engine on a torrent site.

The site uses some relatively simple event handler JavaScript. I plan on writing about it in my next entry when I unveil the other, more JavaScript intensive experiment. Stay tuned. 🙂

LetsTorrent.com. I know I’ve made something good when my girlfriend says she wants to use it. 

Enjoy. 🙂

P.S. I posted this earlier, but the domain wasn’t fully registered yet. It should be now.

GoogleTV – Examining the Evidence

Is this GoogleTV video a hoax? Well, I saw the famed video (below) and noticed the relatively detailed “congratulations” email. I decided to figure out exactly what this email says.

With careful analysis, I have copied the supposed “Congratulations on finding GoogleTV” email text:

From Gmail Team – Received 10:00PM

Congratulations on finding GoogleTV, [his email address]!

With GoogleTV Beta you can now watch streaming television shows at your leisure. We’ve embedded ads that are personally tailored to you and your specific tastes. That’s how we provide free content to you.

Built-in player, keyboard shortcuts, customized suggestions and more. Sound cool? We think so too. Say goodbye to that clunky set in your living room. Welcome to GoogleTV, the future of television.

We hope that this email will help you learn about some of the features that make GoogleTV unique. To get started, you may want to:

  • Watch new episodes of your favorite current [??????]ion shows
  • See what others are watching by navigating the “Most Popular” section
  • Visit our Help Center to learn more about GoogleTV features

As you’re watching GoogleTV, you might notice it functions seamlessly with other Google products. You’ll (sic) can sign up for email alerts when shows become available. We’re designed a fully integrated service. Just for you.

Please keep this email for your records as it contains an important identification code that you may need should you ever encounter problems.

Login to your account at

Enjoy!

The Gmail Team

Verification code [couldn’t decipher]

That’s a pretty wordy and well thought out letter for a portion of the hoax that most people probably wouldn’t even bother to make out in a grainy YouTube clip. Although, there is that typo in the second to last paragraph. And a verification code seems like an odd way to track someone who is already logged into your servers using their Gmail account. Nevertheless, I want to reemphasize that there is an extraordinary amount of well-written details in this congratulatory letter.

According to the comments on this video, it seems to be legit. Users have noted that Google seems to have closed this beta due to the Easter Egg being leaked. One user complained:

too bad they closed it down. i watched the first three episodes of prison break (never saw it on tv). when i came back to my pc and logged in, the site was gone. too bad, the vid was really awesome! does anybody know a way to reactivate it? do i need to do the rollover thing again?!

One interesting thing to note about this new service is that it is not using YouTube’s UI. See the screen shots for what I am referring to.

Here is what Google Video’s interface looks like:

And in comparison, here is from the screen capture:

Clearly, it’s Google Video’s UI, not YouTube’s.

This is a strange because other factors indicated Google was going to focus its video service on YouTube and let Google Video become a search engine for videos. And YouTube finally is beginning to have hosted content from major content producers. Why split the attention of potential users?

Perhaps the intention is to keep YouTube as a clip site full of user submissions and snippets, while GoogleTV will contain nothing but full length shows with embedded ads. This would allow YouTube to remain relatively ad free. Meanwhile, Google Video would take a strong emphasis on being a video search engine. This would allow each product to focus on its niche.

Of course, the most important piece of this entire puzzle comes from this snippet (from above):

We’ve embedded ads that are personally tailored to you and your specific tastes.

Because GoogleTV requires your Google account to use (unlike YouTube), Google is able to leverage everything they know about you to determine what ad to show you. Truly targeted TV ads. They know what you search for, which ads you’ve clicked on, what you write about in your Gmail, what you talk about in your Google Chat, what TV shows you watch, etc. A little scary? Well, that’s what we will all have to come to expect in the future. Well, in this case, the present.

For the first time ever, TV ads will be personally tailored and, most importantly, interactive in that users can click on the ad if they are interested (which also helps Google fine-tune the ads even more!).

If this goes live, I might just cancel my cable subscription.

Is it a hoax? You decide.

Boolean and 0.00

ARG. I encountered another potential issue in PHP that is due to loose types that is common if you are using a database back end.

$amount = 0.00;
if($amount)

Versus

$amount = ‘0.00’; // how data from databases comes
if($amount)

Guess what happens. Well, most people might say both should be TRUE, but that’s not true!

The first one evaluates like this:

  1. 0.00 is the same as 0
  2. 0 is the same as FALSE.
  3. Evaluate the IF condition as FALSE.

The second one evaluates like this:

  1. “0.00” is a string.
  2. A non-empty string is the same as TRUE
  3. Evaluate the IF condition as TRUE.

This is a predictable problem, but highly annoying when working with databases. Most people forget that a float field in the database could equal 0.00, but would evaluate as a TRUE when placed in a condition.

As in, when you get results from the database, the NUMBER 0.00 becomes the WORD “0.00”.

So the lesson here is to make sure you always convert your variables before doing conversions like that. As in:

$amount = ‘0.00’;
if(floatval($amount))

Of course, the best solution is always making comparisons explicit:

$amount = ‘0.00’;
if(0 < floatval($amount))

The Internet Commons Tax Deduction – Why We Need It

Today, I was visiting tinyurl.com, trying to figure out how the site makes money. I noticed some Yahoo ads. So what happens if they run out of donations? Do people donate? TinyURL is just an example. There are definitely other sites that do give free services with nothing but donations in return.

How many websites get ad spammed or simply close down because the owner can no longer afford to host the material for free? This is when it hit me. Free Internet services needs a tax break.

It would need to encourage giving and have a benefit ceiling to ensure only people that need the protection get it. Here’s an example of how the Internet Commons Tax Deduction could work:

  1. A site owner receives a tax deductible credit up to the same amount as all donations received that year.
  2. The total tax deduction granted can never exceed the hosting costs. **

In other words, this acts as a tax deductible item for the owner, making it beneficial for people that have popular hobby projects running off of their personal bandwidth. And, of course, it only kicks in so long as you’re running at a loss. And, it encourages and amplifies giving. It will never counter the losses 100%, but it certainly softens their effect.

The Internet is where it is today thanks largely to much of it being free. While the cost of bandwidth is ever decreasing, it is still expensive to run a popular site. This means that as a person’s contribution to the net grows, their costs due to bandwidth also grows (see orange chart).

There are plenty of very important websites that contain information to help consumers that are entirely non-profit. Even the non-profit Wikipedia had to start somewhere. Then there’s the websites that merely provide value to the web as entertainment. Finally, there are open source projects. These sites have to deal with all the same costs that for-profit websites do, in some cases their costs are even greater.

The current model requires begging for donations while letting companies (leeches) like Paypal take a percentage. Or slapping on a thousand ads. Okay, we can deal with Paypal, and maybe the ads, but what happens if donations and ads don’t cut it? Should a site be subject to destruction simply because its owner can’t afford to spawn a company around it? Can’t the owner get a break for providing stuff for free to the entire world?

No, the person supplying the free goods gets shafted.

Once, long ago, I wrote a dating site engine. For fun. It was my second major project in PHP that I did as a learning experience. After I completed it, I just left it up for anybody to sign up. Did I have intentions of monetizing it? Not in the slightest. The only reason it is still up today is because I could afford the bandwidth costs, but not everybody could have.

Or last year, I wrote a AIM profile tracking service for fun. That too is also sitting around without being monetized. And hopefully, I’ll never have to take it down due to financial short comings.

There are so many cool little projects that turn into amazing things on the net. Many of them become companies, but this is because, currently, monetizing a particular idea is the best and only way to keep it alive. This is also why many companies die on the net – some ideas just can’t float an entire company. Those are the ideas I am targeting here.

Is this essentially a small business tax break? That’s not the direct intention, but it certainly could have that consequence if the revenue cap is set too high. But it also helps many others:

  • The government – a lot more concept websites will mature from infancy into profitability (tax generating businesses) without dying a premature death.
  • Average Joe – even more free web services will pop up, many of which may have never seen the light of day otherwise.
  • Open source – this will help many of the smaller open source projects afford their hosting costs as well as encourage even more donations.
  • Code junkies like myself – it gives us a true financial incentive to share (and host) our work with the world.

My real point here is that hosting stuff on the web is not free. It costs somebody, somewhere, a ton of money. The little guy, who often is the innovator on the Internet, is the one who gets screwed when too many people take his/her work for granted. It’d be nice if those innovators got a little break from Uncle Sam.

Hey, I can dream, can’t I?

**Here is some hypothetical fine print that would probably need to exist (for you nitpickers):

  • There is a annual cap of $XXXX that can be credited in this way. The credit given plus donations reported must be less than the annual revenue generated from the site.
  • Limit of 2 sites are eligible for this deduction per person/company.
  • If revenue generated (including donations) from the site exceeds twice the annual cap ($XXXX), this tax deduction no longer applies.

Google Groups Out of Beta – Google’s Commitment to Integration

Here’s some interesting Google news that hasn’t really been covered anywhere yet (except in Google’s blog): Google Groups is now out of Beta. I’ve never understood how a particular product gets out of “beta”, but I’ll take extra features with a smile. From the post:

Now you can customize the look of your group, create and edit web pages, upload and share files (including photos), and view member profiles. And for your discussions, there’s no need to struggle to follow interrupted conversations, as Google Groups now includes the same style of organization that Gmail users love.

This reminded me of something Sergey Brin said a few months ago:

What we are concerned about is that if we continue to develop so many new individual products that are all their assorted silos, you will have to essentially search for our products before you can even use them… There’s a whole set of initiatives that’s now going on in the Company to make our product offerings simpler and more consistent for all of our users.

The newest features in Groups shows this commitment. From the tour, I pulled two images. One shows an interface that looks and acts just like Gmail.

It even has Adsense on the right side!

Another image shows something that is strikingly similar to Google’s Page Creator.

Google has taken their groups concept and given it a turbo boost.

Simply looking at these two examples of technology integration, we should expect an event organizer in the near future that syncs with your Google Calendar as well as Web Album integration for publishing photos. One of the most obvious integration with Google Maps is missing, and I hope we can see that in the near future. There are many, many ways they can do this as demonstrated by the web-soup of Gmaps mashups out there. Most particularly, member and event locations comes to mind. Lastly, I’d love to see further integration of Gchat, much in the same way as they have done in Gmail. Being able to do group chatting on the web would be cool. Well, realistically, Gchat should work anywhere on Google.com so long as you are logged in…

Someday, I’ll use Groups to organize my poker games, but until I see integration with Google Calendar, I think I’ll continue using mailing lists. Having a centralized way to group up a recurring event is exactly what Calendar needs, while a way to better coordinate “when and where” is what Groups needs. Let’s cross our fingers and hope somebody is listening.

Google Video Ads in Adsense

Big news. Google is expanding its testing of embedded video ads.

The repercussions of this are huge. I would imagine these ads would, potentially, appear directly in YouTube videos, as well as begin a new technology arms race on determining video context. Like the age before Google, right now, there is no search engine that can understand context in visual or audio data without looking at user-submitted data such as tags, descriptions, and the title. I sincerely hope Google has already made significant progress into this ever important research. If they don’t, someone else will.

Will this catch on? No, not yet. US bandwidth is just too constricted (crappy) at this point. We should expect to see non-beta, non-test video ads from Google some time next year. Of course, if Google was really smart, such ads would only be served to customers that aren’t on dial-up.

The article links to a mockup. I disagree with its implementation. Google gained popularity due to its minimalist and unobtrusive approach to advertising. They will never place a huge banner like that above search results. However, little YouTube-esque video ads on the right are entirely possible.

What the Heck is YouTube Doing?

I predicted that YouTube would eventually stream something live (or very close to live). This most readily applies to events that are long. This is important because “sponsored” content could be longer than their current 10 minute cap.

It is difficult to find the “right” event to stream. You’d need something with wide appeal and yet easily licensed. Well, last night was the State of the Union Address, and YouTube blew it. I wanted to watch it, but did I find it there? No.

Thousands of people probably went online to watch that speech, but were unable to find it on YouTube. Instead, I had to resort to crappy Real or Windows Media Player streams (shitty) on some random website.

This could have been an easy home run. But they didn’t even realize it was their turn to bat.

Sports events, award ceremonies, or news broadcasts. Take your pick, YouTube. Pay attention!