There’s no place like ::1

Twitter AMQP WebSocket Example (No Polling)

| Comments

HTML5 is here! Urray!

I was tired of hearing about one of the new innovation in HTML5: the WebSocket API.

After reading the excelent blog post about WebSockets and Ruby by Ilya Grigorik I got inspired by this experiment which is a simple example of a twitter-to-browser usage of websockets.

Since the excelent em-websocket was available on github, I decided to write my own “from twitter to the browser” real time updates, with no polling.

You can check the final result on my github repo.

General overview

Twitter Stream API → Filter → RabbitMQ → AMQP → Eventmachine → WebSocket → HTML5 Brwser

Too much buzzwords? Lets look at some code.


The filter is responsible for eating the Twitter Stream API and puting the tweets on a queue (RabbitMQ in my case) using AMQP:

Pretty easy right? Notice I am using a fanout exchange, which will allow me to broadcast the same message to all queues (clients) latter on.


Now we just need to build a server that accepts websocket connections, and for each client deliver each message that arrives on the fanout exchange. The code will make this clear:

So simple, yet so awesome!


The client just have to connect the websocket, and for each JSON piece that arrives on the socket, present them on the screen:

It seems we’ve ended writing almost more JS than Ruby :P Note that I’ve only tested this on Webkit nightly and latest Google Chrome beta for Mac.

Overall it was a great and easy experience building this simple system, but it allowed me to realize how simple we can build scalable push systems with the WebSocket API!

update: seems like Ilya Grigorik liked it :)

Cheap Calls to Any Portuguese Mobile Network

| Comments

Are you tired of calling your friends and family at prices from the last century? Do you feel frustrated every time you have to top-up the credit of your mobile phone, just because you are obliged to? Do you hate the obvious portuguese cartel around mobile operators?

Well, fell no more! Enter the VoIP world!

Betamax created lots of providers specialized in VoIP. Although almost all of them offer free calls to Portuguese landline numbers, I never realized how competitive they were on the mobile side.

So I dig a little, and found some pretty competitive Betamax VoIP providers:

  • – 4.5 cent/min
  • – 5.0 cent/min
  • – 6.0 cent/min

The best thing about these providers is

  • No required monthly payment
  • You can use your own phone number as Caller ID (so people still answer your calls).
  • They all support the SIP protocol (great for non-windows users like me)
  • Same price for all the mobile operators (so you can jump the wall garden)

I hope that this information helps you lowering your phone bill. Spread the word, and maybe your mobile operator starts lowering the prices too!

Optimus Webphone SIP Settings

| Comments

I am a client of the optimus tag service (for English users, it’s a phone plan that includes free calls for any other phone using the same network plan).

Recently, I discovered they have a softphone like system called Webphone (Windows only), that allows you to place and receive calls, SMS, MMS, and other stuff, right from your computer.

My first thought was “this must use some kind of SIP service”. Since the SIP settings are not posted anywhere on the internet, and I don’t want to use Windows to use their client, I decided to dig deeper and try to find the SIP configurations so it can work on any regular softphone.

Although it was easier than I thought (Wireshark, I love you), there is one serious limitation that I couldn’t solve without hacking some open source code. Anyway here’s the main settings:

Optimus Tag SIP settings (to use with a SIP softphone)

  • server address:
  • username: 351 your
  • password: your webphone password
  • SIP proxy:
  • User Agent: Optimus-SoftPhone/

Now, the last item is the worst part. If you don’t specify a User-Agent that starts with Optimus-SoftPhone, you’ll receive a “403 Forbidden User Agent” message. I tried to find a SIP softphone that allowed me to change the UserAgent but didn’t found one (I didn’t try hard).

So I decided to take the Twinkle open source SIP client, changed the hard coded User Agent, and got surprised when it worked flawlessly from the first time! I tried placing and receiving calls and it worked perfectly :)

If you’re interested on the trivial patch (I used Twinkle version 1.4.2) you can find it here.

If you know a SIP client for OS X or Linux that allows me to change the User Agent, don’t hesitate to comment bellow!

Two More Contributions to the Open Source World

| Comments

quick post to let you know my latest two mini-projects on github:

Ruby library to service API is a wonderful service to shorten URLs. They have a public API, and I wrote this library that allows you to use the service in the middle of any Ruby script.

The project is available here. It is compatible with Ruby 1.9 and JRuby, and contains a full RSpec test suite.

newzbin XMPP search agent

After spending some time learning XMPP, I decided to try it and build something useful. So I hacked a simple search agent for the newzbin website to be used by me and my friends. It is poorly written, but it works.

Maybe you can learn something from the simple example. In case you’re interested, the code is available again on github. It uses the XMPP4R gem and CouchDB (overkill, I know).

Feel free to comment on any of the code and send me suggestions on how to improve it.

24, Blowfish, Bruce Schneier, and LOL

| Comments

Quick note about the latest 24 episode (7×14). When FBI needed to decrypt an email that was sent using the Blowfish cipher, a “level 6 analyst” walks into a computer and says:

“The designer of this algorithm built a backdoor into the code. Decryption is a piece of cake if you know the override codes.”

Five seconds later, the file is decrypted :)

I guess Bruce Scheier, the author of the original cipher, should not be happy to hear this on a TV show :P