Use Backbone JS without REST

Backbone.persistence is a simple adapter to use Backbone.js without using the REST persistence layer.

Backbone is great, but not only for applications that use a remote persistence mechanism, for example, the demo TODO app uses the HTML5 localStorage instead of the usual REST layer.

Sometimes you don’t even need to use localStorage, for example, when you don’t need to save data between two different sessions for the same user. If you want to run your unit tests using Rhino using Jenkins, you can’t use things like localStorage.

That’s where Backbone.persistance comes in, it overrides Backbone.Sync to persist all the data in memory instead of using a persistence mechanism.

You can download Backbone.persistance at my github repository.

What I learned from Whitfield Diffie and Martin Hellman

A few years ago, while attending a “Computer Systems and Networks Security” class, I was talking with a friend of mine. We said to each other: “There’s no way in hell that two principals can exchange a key without a pre-shared key of some sort“.

A few minutes later, our professor introduced us to the Diffie-Hellman method for key exchange.

As you may know, the Diffie-Hellman method allows just that, two parties can share a secret key without any prior knowledge of each other. That secret key can then be used to encrypt data or whatever anyone wants to do with a secret key.

This made me think. There we were thinking a problem was plain impossible and a few minutes later we saw a solution that seemed way too simple for such a hard problem. But it works.

Whitfield Diffie and Martin Hellman found an “impossible” problem and transformed it in a problem with a solution. They didn’t say “That’s just impossible, let’s just solve other problem”.

From that day on, when I find an “impossible” problem I remember the day I heard about the D-H method and I think that maybe, just maybe, there’s a solution hidden somewhere. It motivates me to dig deeper, try harder and never dismiss a problem as “impossible”.

AppEngineLogTz – A User Script to convert timestamps in the Google App Engine logs to the browser’s current timezone

I noticed the time stamps used by the Google App Engine to show the application logs were all in  the Pacific Standard time Timezone. That’s just not useful for everyone not living in the pacific coast.

So I wrote an user script you can use to show the time stamps in your browser’s timezone.

I tested my script on Firefox with greasemonkey and google chrome and it seems to work.

You can get it here: http://github.com/simao/mycode/raw/master/UserScripts/appenginelogtz.user.js

You can also fork this script at github and change it. If you do, please push your changes back to the repository. :)

LXBus – Obtaining Lisbon bus waiting time information

A few months ago I started using a new service provided by carris to check how much time I have to wait for the bus.

Problem is, people at Carris never heard about webservices and rest apis, so I had to send an e-mail and wait for an automated reply with information about waiting times for the stop I was in.

So I wrote an Google App Engine App to wrap this operation and manage this process for me. All I have to do is provide the stop code and wait for the results.

You can check out the app here: http://lxbusinfo.appspot.com

The app is NOT beautiful  when seen on mobile devices, but it’s at least usable. I’ll get around to that as soon as I have some free time, but that is somewhat related with the second part of this post:

Since I developed a REST API to do this, you can also build your own app to check bus waiting times. Quite easily, in fact.

The process of obtaining bus information is of course asynchronous, since my app has to wait for an e-mail from carris.

All your App has to do is send a POST request with the stopcode parameter to http://lxbusinfo.appspot.com/api/newBusRequest You’ll receive a reply like this one:

newBusRequest Form data: stopcode:10503

[
    {
        "requestid": "d71175fc592e4557b76d04f836dae30ef7afcb1d",
        "statuscode": 1
    }
]

This way, you’ll receive a requestid you can use to poll the server at http://lxbusinfo.appspot.com/api/updateBusRequest using a GET request. This API call receives a requestid as parameter. Please wait at least 5 seconds between update requests. Here’s an example of a GET request on updateBusRequest:

updateBusRequest?requestid=d71175fc592e4557b76d04f836dae30ef7afcb1d

[
    {
        "message": "",
        "payload": [
            {
                "dest": "PORTAS BENFICA",
                "eta_minutes": 4,
                "pt_timestamp": "21:09",
                "last_modified": "2010-10-01T20:04:41.481256",
                "busnr": 758
            },
            {
                "dest": "PR. REAL",
                "eta_minutes": 12,
                "pt_timestamp": "21:17",
                "last_modified": "2010-10-01T20:04:41.556630",
                "busnr": 790
            }
        ],
        "statuscode": 0
    }
]

As you can see, all replys are json encoded so you can parse them easily with JavaScript.

There are other replies and error codes, leave a comment if you want to implement something and I’ll send you a nicer specification.

I’ll open the source and setup a github repository as soon as I can get around to shape things up a bit.

I want to make this open source not only because I want to share the source but also because probably carris will do something to block my app, but if the source is open anyone can install the app elsewhere and setup a new bus information server. Problem is I don’t want to share the source with Carris. :) Any thoughts on this? Lets hear it in the comments.

Browser fingerprinting

Tomei conhecimento do estudo da Electronic Frontier Foundation intitulado “Web Browsers Leave ‘Fingerprints’ Behind as You Surf the Net”, através do Miguel Almeida, mas já vi várias opiniões em vários sítios diferentes.

Apesar de achar que os resultados do estudo são de facto preocupantes, acho que se está a exagerar bastante.

Ao correr o teste disponível aqui, obtive os seguintes resultados:

Your browser fingerprint appears to be unique among the 1,763 tested so far. Currently, we estimate that your browser has a fingerprint that conveys at least 10.78 bits of identifying information.
Browser Characteristic bits of identifying information one in x browsers have this value value
User Agent -0.84 0.56 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
HTTP_ACCEPT Headers -6.98 0.01 text/html, */* ISO-8859-1,utf-8;q=0.7,*;q=0.7 gzip,deflate en-us,en;q=0.5
Browser Plugin Details 10.78+ 1763 A bunch of them
Time Zone -7.13 0.01 -60
Screen Size and Color Depth -5.38 0.02 1280x800x24
System Fonts 6.26 76.65 A bunch of them
Are Cookies Enabled? -8.89 0 Yes
Limited supercookie test -8.03 0 DOM localStorage: Yes, DOM sessionStorage: Yes, IE userData: No

Analisando os resultados linha a linha, podemos ver que o único parâmetro que é verdadeiramente único é o “Browser Plugin Details” e em segundo lugar o “System fonts”, sendo que 1 em cada 76 browsers testados têm as mesmas fontes que eu. Ou seja, o meu browser é unico entre os 1963 browsers testados, mas apenas pela minha lista de plugins. Ora em 1763 browsers testados, não acho que o problema seja tão grave como se faz parecer, ainda para mais quando é vulnerável ao uso de plausible deniability.

Como se pode ver, há um certo exagero nas opiniões que tenho visto sobre o estudo. Na prática, apesar de se provar que de facto o nosso browser está longe de ser comum, e consequentemente garantir qualquer tipo de anonimato, também não é tão particular como se faz parecer.

Just my 2 cents.

PrinScreen RSS File – Long live Prt.sc… sort of

Recently, one of my favorite blog aggregators died, but left us with a nice OPML file containing all rss feeds from the authors of the aggregator.

Yahoo! My pipes couldn’t parse the opml file, so I built a python script to do it and hosted it in my server.

The RSS File is updated every hour and contains all RSS entries from all Prt.Sc authors not older than seven days.

You can get the RSS file at http://simaom.com/prtsc.xml.

So prt.sc lives… well… sort of… I won’t update the opml feed with any authors, we only get access to rss entries from the authors included in the last version of Prt.sc.

Let me know what you think.

opml2rss.py – An opml to rss converter

I just uploaded another script to my github repository.

It’s a python script to parse an opml file and generate a rss file with entries from all rss feeds in the rss file not older than a certain number of days.

You can get the script here: http://github.com/…/opml2rss.py

The script has a few configuration parameters that are pretty self explanatory, should be easy. You also need to install a few python modules: Feedparser, OPML and PYRSS2Gen.

New github repository

I just set up a github repository to hold my code.

Here’s the link http://github.com/simao/mycode

Currently, the repository contains only the code of my latest Python script, rssTorrents.py.

Automatically download torrent files from a RSS feed

I was looking for a way to parse a RSS feed I built using yahoo pipes and add new torrents to Transmission to download them automatically. I couldn’t find anything useful, so I just wrote a python script to do just that. If you want to use it, you’ll need to configure the first lines of this file to suit your needs. The script is pretty self explanatory.

You can always find the latest version of the script at my github repo

Disclaimer: I use this script to download legal torrents ;)

Emacs easy window switching

I just found out about a another cool emacs plugin: WindMove

This packages allows you to switch windows withouth using C-x o.

WindMove is included with emacs, just include the following code in your .emacs:

(when (fboundp 'windmove-default-keybindings) (windmove-default-keybindings))

More info @ http://www.emacswiki.org/emacs/WindMove