Friday, June 1, 2012

[Gd] Subtyping Functions Without Poking Your Eyes Out

| More

Closure Tools Blog: Subtyping Functions Without Poking Your Eyes Out

Pop quiz: suppose you see two Closure Compiler type annotations.

A) {function(Object)}
B) {function(Array)}

Which one is the subtype?

Telling you that the right answer is (A) feels a lot like driving on the wrong side of the road. Try reading it out loud.

Right Answer: "A function taking an Object IS A function taking an Array"
Wrong Answer: "A function taking an Array IS A function taking an Object"

Saying the right answer feels so wrong! Saying the wrong answer feels so right! We often have to do multiple rounds of whiteboarding the problem to try to explain it to other JS engineers.

This is not a unique problem to JavaScript. Most object oriented languages have the same issue. But JavaScript engineers are used to living without types. With Closure, suddenly you have types. And you have lots of complex function types that real OO languages don't have, and that you're probably unfamiliar with if you haven't used a functional language.

The problem, I think, goes back to a lot of "Intro to Objects and Classes" books that teach the "is-a" relationship. An apple IS A fruit. A blog IS A website. A werewolf IS A man but also IS A wolf.

The "is-a" wording is an oversimplification that breaks down if you're not careful. This wikipedia page gives a good counterexample, obtusely explained. Suppose you define "A Doctor" as a person that can treat all patients, and a Pediatrician as a person that can only treat children. If we need a Doctor that can treat all patients, then a Pediatrician is not an acceptable substitude. So, counterintuitively, a Pediatrician is not a subclass a Doctor.

Oddly, a Pediatrician is a superclass of this "Doctor." If you need a pediatrician, a doctor that can treat all patients is an acceptable substitute.

What you really want is to define a Doctor as "a person that can treat at least one patient." You might call this the Empty Doctor or (for the calculus nerds) the Epsilon Doctor. This doctor can treat some patient, somewhere. But if you go to see the Epsilon Doctor, it's likely that they won't know how to treat you. A pediatrician is a subclass of the Epsilon Doctor, because a pediatrician can treat some patients.

Conversely, when you have a {function(Object)}, this does not mean "a function that can take some object". It means "a function that knows how to handle all objects." A {function(Object)} is substitutable any place you need a {function(Array)}.

Posted by Nick Santos, Software Engineer
URL: http://closuretools.blogspot.com/2012/06/subtyping-functions-without-poking-your.html

[Gd] Fridaygram: world wonders, fruit freshness, stunning sky

| More

Google Developers Blog: Fridaygram: world wonders, fruit freshness, stunning sky

Author Photo
By Scott Knaster, Google Developers Blog Editor

If you write code, you’re stuck at your desk or laptop for long hours at a time. There’s no substitute for getting out into the world, but when you just can’t travel, you can use our new World Wonders Project to virtually visit amazing sites around the world. World Wonders has used really cool tricycles equipped with Street View cameras to film Stonehenge, the Trulli of Alberbello, the Ogasawara Islands, Shark Bay, Český Krumlov, and many more places. And when you visit, you don’t even get jet lag.


Cesky Krumlov page in World Wonders

When you do leave your home or office, you might go to the market occasionally for fresh fruit and vegetables. Your fresh food experience might improve thanks to new sensors made at the Massachusetts Institute of Technology. These sensors can figure out when fruits and veggies are getting too ripe. The sensors work by detecting ethylene, a gas that helps plants ripen.

Finally, when you’re not at the market or virtually visiting world heritage sites, take a look at this photo of lightning over a rainbow during a storm in China. You can relax and check it out while you’re munching on your fresh fruit and veggies.


Each week we publish Fridaygram, featuring stuff from Google and beyond that you might have missed during the week. Fridaygram items aren't necessarily related to developer topics; they’re just interesting to us nerds. This week we’re giving a special shout out to HyperCard on its (approximate) 25th anniversary. HyperCard, you were awesome.
URL: http://googledevelopers.blogspot.com/2012/06/fridaygram-world-wonders-fruit.html

[Gd] Stable Channel Update

| More

Chrome Releases: Stable Channel Update

The Chrome Stable channel has been updated to 19.0.1084.53 on Mac to support the transition to OS-X Mountain Lion.   

Full details about what changes are in this release are available in the SVN revision log. If you find a new issue, please let us know by filing a bug.
 

Anthony Laforge
Google Chrome
URL: http://googlechromereleases.blogspot.com/2012/05/stable-channel-update_31.html

Thursday, May 31, 2012

[Gd] Email Overload!

| More

Google Apps Developer Blog: Email Overload!

Editor’s Note: This blog post is authored by Blair Kutzman, who developed the Gmail Delay Send script. - Eric Koleda

Update: To start using this script simply open this spreadsheet and follow the instructions contained within.

In today’s connected world, when you get your email could be just as important what’s in it. In 2011 over 107 trillion emails were sent to 1.97 billion internet users. Studies have shown that the average person can only effectively process 50 emails in a day. That leaves 100 emails per person per day that are not processed effectively. How can you be sure that the emails you send fall into the former category and not the latter?

Luckily, there are tools to assist with email overload. One such tool is Gmail Delay Send.


What is Gmail Delay Send?

Gmail Delay Send is a Google Apps Script that allows you to schedule emails to be delivered on a specified date and time. Using this tool you can ensure your email is sent to its destination at a time when you can capture your recipient’s full attention. For example, receiving an email at 4:59 PM on friday might not receive the same attention as an email received on Monday at 10:00 AM.

Designing Gmail Delay Send

A primary requirement of Gmail Delay Send was that it needed to work everywhere Gmail is available. There are already many browser add-ons and services available to enhance Gmail with similar functionality, so the purpose was not to duplicate that work. In order for the service to be available on all platforms, it needed to utilize native Gmail features.

We needed a native way that Gmail could:

  1. Store a composed, but unsent message.
  2. Store in that composed message two pieces of metadata:
    • Whether or not the message meant to be sent at a later time
    • If it is, when the message should be sent

Gmail already contains a 'Draft' folder which is exactly what is required for item 1. The real problem was where and how to store the metadata for item 2, without any new Gmail functions. I chose to encode the metadata in the subject of the message because it would contain less text, which would mean a smaller chance of mis-parsing. Text such as “5 hours” and “next tuesday” were turned into a date-time using an open source library called datejs and a few modifications. See below for details of how this potentially cumbersome process was improved.

Basic structure

The script works as follows:

  1. The user composes an email, noting the date-time they want the message to be sent in their subject line after a delimiter (eg. "Lets go surfing -- 3:30PM")
  2. The email is then saved as a draft and optionally a label is applied marking it as a message that we want to send at a later time.
  3. When the script executes, all draft messages are checked (optionally looking at messages that have a specific label applied) to see if they should be sent now.

Usability improvements

Although using datejs to parse the dates from the subject line was easy to implement, it introduced some usability issues. First, how would a user know if a certain string can be parsed by datejs (eg. is “5 minutes before 4PM” parsable)? To assist the user in knowing which dates datejs supports, the script offers a mechanism to test a given string directly in the spreadsheet that Gmail Delay Send is installed inside of. In this way a user can test various strings to see if they are valid and, if so, when they would be sent. A wiki page is dedicated to helping people through this process.

Another possibly confusing part of using Gmail Delay Send was setting up triggers. Thanks to some recent improvements of the Script Services, this is now done automatically for users as they install.

Improving script reliability

Adding retry logic to the script was another important step in improving its reliability and user experience. Occasionally, users were getting emails from their trigger informing them that a certain Google Script API could not be contacted. Some retry logic was required to make things work correctly. As shown in the snippet below, the function executeCommand() takes any function and will try to execute it a specified number of times, retrying if an error is thrown:

function executeCommand(fp) {  
var msg;
var ret_val;
var last_error;

for(var retries = NUM_RETRIES; retries > 0; retries -= 1) {
try {
ret_val = fp();
break;
}
catch(err) {
last_error = err;
msg = "Exception:" + err + " thrown executing function:" + fp;
debug_logs.push(msg);
Logger.log(msg);
Utilities.sleep(SLEEP_TIME);
}
}

if(retries == 0) {
msg = "Attempted to execute command:" + fp + " " + NUM_RETRIES +
" times without success. Error message: " + last_error +
". Aborting :-(";
Logger.log(msg);
throw(msg);
}

return ret_val;
}

Using this method, statements like those below will automatically retry if the service is not available.

executeCommand( function() { GmailApp.send( … ) });
executeCommand( function() { UrlFetchApp.urlFetch(url) } );

Summary

Gmail Delay Send was a fantastic project for learning about Google Apps Script and I hope that it will continue to prove useful to its users. If you’re interested in using Gmail Delay Send or just interested in the development process please check out the homepage or source.

Blair Kutzman   profile

Blair currently works on scan firmware at Hewlett Packard. When not scanning he likes to hang out with family, run and surf. Check out his profile for other projects.


URL: http://googleappsdeveloper.blogspot.com/2012/05/email-overload.html

[Gd] Beta Channel Update

| More

Chrome Releases: Beta Channel Update


The Beta channel has been updated to 20.0.1132.21 for Windows, Mac, Linux, and Chrome Frame. This build contains updates to v8 (3.10.8.11) and fixes for bugs and stability. Full details about what changes are in this build are available in the SVN revision logInterested in switching release channels? Find out how. If you find a new issue, please let us know by filing a bug.

Dharani Govindan
Google Chrome
URL: http://googlechromereleases.blogspot.com/2012/05/beta-channel-update_30.html

[Gd] Upgrade now to the new Google Analytics Core Reporting API

| More

Google Developers Blog: Upgrade now to the new Google Analytics Core Reporting API

Jeetendra
Nick
Pete
By Pete Frisella, Nick Mihailovski, and Jeetendra Soneja, Google Analytics API Team


Core Reporting API Migration Update

Back in December we launched the Core Reporting API to replace the Data Export API. We also announced that we would be shutting down the old Data Export API and that all applications should migrate to the new version.

The time has come for us to shut down the old version. So this is our last reminder to migrate to the new Core Reporting API.

Starting next week, we’ll begin redirecting a portion of Data Export API requests to the Core Reporting API as we prepare to shut down the Data Export API on July 10th. So you'll begin to see Data Feed requests return a Core Reporting API response, and requests for the Account Feed will produce an error.

If you do not migrate, your application will experience service outages.

For more information, visit:
Reminder: Migrate to the new Core Reporting API
Migration Guide: Moving from v2.3 APIs to v2.4 & v3.0


New Guides To Get You Started Fast

It’s important for the Google Analytics APIs to be open and accessible to all developers. It’s common practice for developers learning a new API to start off with the basics and incrementally build from this foundation.

So with that in mind, we wrote a new Hello Analytics API tutorial to give you that basic foundation. The tutorial includes sample code for Java, PHP, Python, and JavaScript. It also walks you through the basic steps of using the Google Analytics API, including registration, authorizing users, retrieving account and profile information, and querying for a report. Once complete you will have a working example that you can customize.

To make it even easier to build applications, we’ve also updated the developer guides for both the Core Reporting API and Management API. Examples for a variety of programming languages have been included, but more importantly the basic concepts have been highlighted.

So whether you’re just starting, updating, or migrating to the new version, you should check out the Hello Analytics API tutorial and Developer Guides before settling down to write that awesome application.


Pete Frisella is a Developer Advocate for Google Analytics, interested in encouraging and promoting awesome Google Analytics integrations. Pete loves to talk tech, travel, and hit the golf course when he can.

Nick Mihailovski is a Senior Developer Programs Engineer working on the Google Analytics API. In his spare time he likes to travel around the world.

Jeetendra Soneja is the Technical Engineering Lead on the Google Analytics API team. He's a big fan of cricket – the game, that is. :)

Posted by Scott Knaster, Editor
URL: http://googledevelopers.blogspot.com/2012/05/upgrade-now-to-new-google-analytics.html

[Gd] Join us at Random Hacks of Kindness this weekend

| More

Google Developers Blog: Join us at Random Hacks of Kindness this weekend

Author PhotoBy Christiaan Adams, Developer Advocate, Google.org Crisis Response Team

Cross-posted with the Google.org Blog

On June 2nd and 3rd, volunteers around the world are coming together for the Random Hacks of Kindness Global Hackathon. Born in 2009, Random Hacks of Kindness (RHoK) is the brainchild of a partnership among Google, Microsoft, Yahoo!, HP, NASA and the World Bank. The RHoK international community is over 4000 strong, encompassing not only computer programmers but also engineers, designers, web experts, project managers and other tech-savvy do-gooders, as well as subject matter experts in areas as diverse as disaster risk management, climate change, water, health care and human rights. This group of unlikely collaborators works together to define challenges facing humanity in local communities all around the world, and then to rapidly prototype solutions during an intensive weekend of round-the-clock work.

logo
Fueled by plenty of coffee and a strong desire to make a difference in the world, "hackers for humanity" working alongside subject matter experts have created innovative solutions to pressing problems in their communities.
In the three short years since its inception, RHoK communities have sprung up in close to 50 cities around the world, with the support of over 180 diverse partner organizations, from government and academia, to the non-profit and private sectors.

RHoK Global in June 2012 will be taking place simultaneously in 21+ cities globally, from Seattle to Santo Domingo, from Philadelphia to Prague. Googlers will be attending the events in San Francisco, Prague, and other locations, and we hope you can join us.

Be a part of this global movement to make the world a better place through the innovative use of technology. Register at www.rhok.org/events and come out to hack for humanity in a city near you on June 2nd and 3rd, 2012!


Christiaan Adams is a Developer Advocate with the Google Earth Outreach Team and Google.org’s Crisis Response Team, where he helps nonprofits and disaster response organizations to use online mapping tools. When he’s not at work, he likes to go hiking or mountain biking, using Google Maps, of course.

Posted by Scott Knaster, Editor
URL: http://googledevelopers.blogspot.com/2012/05/join-us-at-random-hacks-of-kindness.html

Wednesday, May 30, 2012

[Gd] Now you can polish up Google’s translation of your website

| More

Official Google Webmaster Central Blog: Now you can polish up Google’s translation of your website


Webmaster level: All
(Cross-posted on the Google Translate Blog)

Since we first launched the Website Translator plugin back in September 2009, more than a million websites have added the plugin. While we’ve kept improving our machine translation system since then, we may not reach perfection until someone invents full-blown Artificial Intelligence. In other words, you’ll still sometimes run into translations we didn’t get quite right.

So today, we’re launching a new experimental feature (in beta) that lets you customize and improve the way the Website Translator translates your site. Once you add the customization meta tag to a webpage, visitors will see your customized translations whenever they translate the page, even when they use the translation feature in Chrome and Google Toolbar. They’ll also now be able to ‘suggest a better translation’ when they notice a translation that’s not quite right, and later you can accept and use that suggestion on your site.

To get started:
  1. Add the Website Translator plugin and customization meta tag to your website
  2. Then translate a page into one of 60+ languages using the Website Translator
To tweak a translation:
  1. Hover over a translated sentence to display the original text
  2. Click on ‘Contribute a better translation’
  3. And finally, click on a phrase to choose an automatic alternative translation -- or just double-click to edit the translation directly.
For example, if you’re translating your site into Spanish, and you want to translate Cat not to gato but to Cat, you can tweak it as follows:


If you’re signed in, the corrections made on your site will go live right away -- the next time a visitor translates a page on your website, they’ll see your correction. If one of your visitors contributes a better translation, the suggestion will wait until you approve it. You can also invite other editors to make corrections and add translation glossary entries. You can learn more about these new features in the Help Center.

This new experimental feature is currently free of charge. We hope this feature, along with Translator Toolkit and the Translate API, can provide a low cost way to expand your reach globally and help to break down language barriers.

Posted by Jeff Chin, Product Manager, Google Translate
URL: http://googlewebmastercentral.blogspot.com/2012/05/now-you-can-polish-up-googles.html

[Gd] Dev Channel Update

| More

Chrome Releases: Dev Channel Update

The Dev channel has been updated to 21.0.1155.2 for Windows, Mac, Linux, and Chrome Frame.  This build contains following updates:


Full details about what changes are in this build are available in the SVN revision log. Interested in switching release channels? Find out how. If you find a new issue, please let us know by filing a bug.

Dharani Govindan
Google Chrome
URL: http://googlechromereleases.blogspot.com/2012/05/dev-channel-update_29.html

Tuesday, May 29, 2012

[Gd] The YouTube Player: Now with 30% More Playlistiness!

| More

YouTube API Blog: The YouTube Player: Now with 30% More Playlistiness!

When we launched support for lists of videos in the YouTube player in March, it was greeted with a lot of enthusiasm. However, some developers pointed out that at first glance it didn’t look very much like a playlist. In particular, they wanted the list of video thumbnails to be visible all the time.

Well, you guys asked for it, and we listened. If you pass a parameter, showinfo=1, when creating the player, the list of video thumbnails will be permanently visible. Here’s an example:

<iframe width="560" height="315" src="http://www.youtube.com/embed/?listType=user_uploads&list=GoogleDevelopers&showinfo=1" frameborder="0" allowfullscreen></iframe>

The corresponding embedded player is shown below:



To see all of the parameters that the YouTube player supports, refer to the documentation. If you have any questions, feel free to post them to the YouTube API Google Group.

Cheers,
—Shannon -jj Behrens, YouTube API Team

URL: http://apiblog.youtube.com/2012/05/youtube-player-now-with-30-more.html

[Gd] Stable Channel Update for Chromebooks

| More

Chrome Releases: Stable Channel Update for Chromebooks

The Google Chrome team is happy to announce the arrival of Chrome 19 to the Stable Channel for ChromeOS.  More detailed updates are available on the Google Blog.  

The Stable channel has been updated to 19.0.1084.52 (Platform version: 2046.107.0) for Chromebooks (Acer AC700, Samsung Series 5, Samsung Chromebook Series 5 550, and Samsung Chromebox Series 3).  Machines will be receiving updates to this version over the next several days.

This build contains a number of new features, as well as security & stability improvements.

Some highlights of these changes are:

  • Entirely redesigned UI and updated Window Manager (Learn more).
  • New modes for multiple monitor handling: mirrored (highest common resolution only), show only on primary, show only on secondary (Switch with Ctrl + F5)
  • New open source trackpad stack
  • Updated Scratchpad app
  • New file types supported (Learn more)
  • Functional and visual refresh of the Chrome OS Settings
  • Recovery tool supports re-formatting recovery media (use a previous recovery image USB)
  • Introduced new Japanese fonts (Motoya G04 Gothic/Mincho).

If you find new issues, please let us know by visiting our help site or filing a bug. Interested in switching channels? Find out how. You can submit feedback using ‘Report an issue’ under the wrench menu.

Orit Mazor
Google Chrome
URL: http://googlechromereleases.blogspot.com/2012/05/stable-channel-update-for-chromebooks.html