Alexandre Bourget

geek joy

Entries tagged “google”

Gmail's undo/cancel feature: introducing Python's WebUndo

written by abourget, on Feb 20, 2010 11:14:00 PM.

From a web point of view, if you want to stop a user from doing stupid things (like submitting a form before reviewing it, sending a heinous e-mail late at night, or clicking a button that launches a nuclear missile), you might want to do one one of three things:

  • Pop-up a confirmation dialog
  • Go to a second page, with yet another submit button asking for confirmation, with a summary of the submitted data
  • Just let it go, but offer a timed “UNDO” or “CANCEL” link, like Gmail implemented for e-mails

Of course, the best of all three is the latter. The difference here is major. It’s the difference between pro-active annoyingness (pop-ups asking confirmation when you know very well you want to send the e-mail), or reactive flexibility. It also gives your user a great boost of confidence in your application, because the user can do stupid things and knows he’ll be able to fix them in a timely manner.

Now here’s how to do it in Pylons, using the just-released WebUndo lib. You can find it on PyPI, so just pip install WebUndo from your project.

We’re lucky Pylons runs as a single application with threads, since that’s what we’ll use to delay our operations and give the user a chance to cancel. PHP apps for instance, wouldn’t give us that flexibility, since everything vanishes once the request is sent. Take a look at the source code to know how it’s built.

Let’s consider this piece of Pylons controller:

class ThController(BaseController):
    def index(self):
        return render('th.mako')

    def save(self):
        open('/tmp/dump.txt', 'w').write(request.params.get('stuff'))
        return "Everything saved"

where th.mako contains a simple form with a text field named stuff. In this case, once you submit the form in th.mako, it’s done: the file is written to disk, and there’s no way you can cancel it.

Now let’s have a look at this version:

class ThController(BaseController):
    def index(self):
        return render('th.mako')

    def save(self):
        req = request
        def do_save():
            open('/tmp/dump.txt', 'w').write(req.params.get('stuff'))
        key = webundo.launch_cancelable_job(do_save, 5)
        return 'Saving, click to <a href="%s">cancel</a>' % h.url_for(controller='th', action='cancel', id=key)

    def cancel(self, id):
        if webundo.cancel_job(id):
            return "Thread cancelled successfully"
        else:
            return "Too late, thread finished already."

We added some pieces of webundo, the save() action returns a confirmation message, and a link to cancel the operation. We also added a def do_save() wrapper, a call to the launch_cancelable_job function and the passing on of the key. Notice also the req = request, used to make sure the request object gets closed in the do_save() function. The fun part here, is that the operation will not be carried out until the 5 seconds (second parameter to launch_cancelable_job) are elapsed. The last thing is obviously, the cancel action, which will deal with the cancelation.

Using this feature, even if you close your browser window after calling the save action, the do_save() function will be executed normally, only delayed by 5 seconds.

For the Pylons addicts who read that code and say “hey, that request object can’t traverse threads, it’s a StackedObjectProxy”! See the details and answer in my other blog post.

Of course, there are cases where you want a certain operation to be carried out directly (when calling save() for example) but you want some special code to be executed if someone click an undo button for example. The WebUndo lib provides you with another pair of functions to do just that: launch_undoable_job and undo_job.

Take a look at the documentation for full details. Happy undoing!

UPDATED March 20th: typos following feedback

Respect de la vie privée, Google, et tout ce qu'on peut en dire

written by abourget, on Feb 12, 2010 8:14:00 AM.

En réponse au Journal du Geek, qui affirme:

C’est clair qu’à ce rythme et connaissant le respect de la vie privée de Google, on va bien finir par avoir un Google Street View à domicile (surement du genre témoin de Jéhovah avec des caméras 360° sur la tête).

dans son article Google Street View à la montagne, dans les magasins et bientôt chez vous !, je réponds:

Pourquoi est-ce qu’on essaie toujours de pousser l’argument de la vie privée alors qu’il n’a rien à voir ?

Je sais que l’insinuation était presqu’inaudible, passagère dans l’article, mais 20% des commentaires ont repris sur ce thème.

L’information et la vue des montagnes est une information publique, et même une information de grande valeur. Il n’y a simplement pas d’atteinte à la vie privée. Si Google fait quelque chose d’admirable – du genre, rendre disponible des choses hors de notre portée jusqu’alors – alors pourquoi ne pas simplement être admiratif.

Et je sais pas si vous savez, mais Google, ils la respectent la vie privée. Ils se posent la question sur plein de sujets chaque jour, pour s’assurer de la vie privée. Ils la méprisent pas, et peut-être qu’ils la comprennent beaucoup mieux que nous qui s’inquiétons quand nos montagnes se font prendre en photo.

Vous avez peut-être vu qu’ils brouillent les visages sur Street View la plupart du temps, sinon sur demande. Ils brouillent les adresses pour pas permettre des associations trop directes. Dans Google Goggles, ils ont volontairement désactivé la reconnaissance faciale, chose possible technologiquement, pour éviter des croisés trop directs.

Est-ce qu’on se plaint de nos commis de banque qui ont accès à toutes les informations sur nos comptes ? Et pourtant, ils ont l’information directe, associée devant ma personne, de ce que je gagne. Ils nous rendent un service, on leur laisse l’information nécessaire.. et ils font sans *aucun* doute des statistiques sur ce qu’ils ont. Pourquoi pas de constipation là ?

On s’alarme de profilage. Depuis la nuit des temps, le marketing fait du profilage, dans les magasins, dans les centres commerciaux. Pourtant, quand on entre chez [insérez votre magasin], on a déjà été profilé, par les article de décorations mis de l’avant, par les yeux de tel ou tel commis qui va nous diriger (en nous *regardant*, en voyant notre style, notre langage) vers ce qu’il croit être le mieux ou le plus approprié pour nous .. et *oui*, pour nous *vendre* ! Incroyable ce commis qui viole comme ça ma vie privée! Il me regarde, et *apprends* des choses sur moi, et même il les utilise pour me vendre des choses, quel arrogant.

Sur Internet, on ne se voit pas. L’information est utilisée pour faire du profilage, ça n’est pas différent, et même beaucoup moins direct.

Cessons de faire les paranoïaques.

Google Chrome as the next Web Developer browser

written by abourget, on Feb 12, 2010 7:54:47 AM.

Here’s a very good article on why Google Chrome might be the next Web Developer browser:

Why Web Developers Should Switch to Google Chrome - Nettuts