JavaScript as a First Class Language

December 8th, 2011

A couple of weeks ago I presented at the internal ThoughtWorks conference called XConf about how we have been treating JavaScript as a First Class Language recently on our current project. What it means to us is:

  • Modularise JS code (JAWR helps)
  • Unit test it. (we use Jasmine and JSTestDriver)
  • Static analysis, “checkstyle for JS”. (we use JSHint)
  • JS Dependency Injection to facilitate testing

Here are the slides with more info and some code samples.

Technical ,

My Echidna photo was selected

November 8th, 2011

I was quite happy that my photo was selected by schmap.com to represent Melbourne Zoo.

I’ve been working a lot on my photography skills… Who knows… One day I could be famous Smile

melbourne-zoo-fabio-pereira-photo

Personal

ThoughtWorks Brazil in João Pessoa

October 25th, 2011

I am extremely excited about the fact that ThoughtWorks is organising a Boot Camp Recruitment Event in João Pessoa this month. I was born in João Pessoa and it is also where I lived while I was at university UFPB Federal University of Paraiba.

I have been working for ThoughtWorks for the last 4 years and would totally recommend it to all my friends. So, if you are a passionate IT person in João Pessoa go check it out.

tw-brazil-joaopessoa

And, if one day, potentially, hypothetically, eventually ThoughtWorks decides to open an office in João Pessoa… And if you work for ThoughtWorks in any other offices all over the world… and you decided to transfer there, here’s what you would find… I love this city… I’m just saying… :)

joao pessoa

Photos from

www.pbase.com/alexuchoa/joao_pessoa

http://about.me/arthurlucena

Technical

TW SSC - Deep Sea Fishing

October 19th, 2011

Last Sunday (16/Oct) we went on a deep sea fishing trip as part of the SSC – Sydney Social Club, an ThoughtWorks initiative to help people have fun together…

TW_SSC_Deep_Sea_Fishing-162-Edit-Edit

Camila caught the first fish on the boat… A tiny little one, but really cute, like her Smile

TW_SSC_Deep_Sea_Fishing-59

Right after that I started feeling seasick and I threw up 6 times… It was a horrible experience. I had taken a ginger seasickness tablet, apparently, it doesn’t work. When we came back to the harbour I felt much better.

TW_SSC_Deep_Sea_Fishing-84

And that was when we had a lot of fun cooking some bbq and also the fish that we caught.

TW_SSC_Deep_Sea_Fishing-153

And we had delicious food…

TW_SSC_Deep_Sea_Fishing-171

Technical

Sunset–Nielsen Park–Sydney

September 17th, 2011

My aunt Necy used to tell me that the sunset is one of the most beautiful events in the world, it happens everyday for free and most of us take it for granted.

Today I enjoyed and remembered her at Nielsen Park in Sydney.

sunset hdr 1

More photos here

Uncategorized

Gource–The history of a codebase

September 4th, 2011

Codebase history generated using Gource.

Technical ,

Bone or Wood? Which one is harder?

August 28th, 2011

Yesterday (Sunday) I accidentally/on-purpose tripped/kicked/ran-into my bed… well, it’s complicated, not even I understand properly how it happened… But, long story short: I broke my toe.

It’s the fourth time I break a bone in my life. It’s always the same thing. It gets very numb and everyone around me says:
“You didn’t break anything, otherwise you’d be crying… Blah Blah Blah…”

A couple of hours later:

broken toe foot pe quebrado-1

broken toe foot pe quebrado-7

I went to St Vincent’s Hospital close to my apartment and was very well treated:

  • X-Ray to confirm it was broken
  • Tons of painkillers
  • Crutches
  • Ice
  • Keep foot elevated, above heart level

I broke the proximal phalanx on the right toe, also called hallux.

Left foot below is a normal one from the internet. The right one is mine.

xray-foot

Now I have to learn how to use crutches and work from home.

broken toe foot pe quebrado-14

Uncategorized

Testing Ajax with WebDriver – Make your tests deterministic

August 24th, 2011

We had some non-deterministic tests on our project so we decided to implement a generic way to test ajax calls using webdriver. I was quite impressed with how quickly we achieved this, mainly due to the fact that javascript is dynamic and functional. And also thanks to my js learning sessions with Romain, who is also responsible for a great majority of the js code below :)

Here’s the code, split into well defined components as we’ve been treating javascript as a first class language. It has also been unit tested, but I’ll save that for another post.

Http

A wrapper around jquery ajax

var Async = Async || {};
Async.Http = function() {

    function get(url, data, successHandler, errorHandler) {
        $.ajax({
            url: url,
            data: data,
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            async: false,
            success: successHandler,
            error: errorHandler
        });
    }

    function post(url, data, successHandler, errorHandler) {
        $.ajax({
            type: 'POST',
            url: url,
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: successHandler,
            error: errorHandler
        });
    }

    return {
        get: get,
        post: post
    };

};

Notifier

A stateful js component that keeps track of all the ajax calls and adds a div to the dom with that information.

var Async = Async || {};
Async.Notifier = function() {

    var $notifierElement = $('<div id="asyncNotifier" class="done">');
    $('body').append($notifierElement);    

    var inProgress = 0;

    function start() {
        ++inProgress;
        $notifierElement.removeClass('done');
    }

    function finished() {
        --inProgress;
        if (inProgress === 0) {
            $notifierElement.addClass('done');
        }
    }

    return {
        start: start,
        finished: finished
    };

};

HttpAsyncDecorated

A decorated version of Async.Http that uses Notifier.

var Async = Async || {};
Async.HttpAsyncDecorated = function(http, asyncNotifier) {

    function decorateWithFinish(handler) {
        return function(data, textStatus, jqXHR) {
            handler(data, textStatus, jqXHR);
            asyncNotifier.finished();
        };
    }

    function get(url, data, successHandler, errorHandler) {
        asyncNotifier.start();
        http.get(url, data, decorateWithFinish(successHandler), decorateWithFinish(errorHandler));
    }

    function post(url, data, successHandler, errorHandler) {
        asyncNotifier.start();
        http.post(url, data, decorateWithFinish(successHandler), decorateWithFinish(errorHandler));
    }

    return {
        get: get,
        post: post
    };

};

JS App Context (Wiring things together)

Here’s the js code that glues everything together… Like a “javascript app context”.

var MyAppMain = MyAppMain || {};
MyAppMain.Context = function() {
    function startup() {
        var http = Async.HttpAsyncDecorated(Async.Http(), Async.Notifier());
	MyApp.SomethingThatUsesAjaxHttp(http);
    }

    return {
        startup: startup
    };
};

WebDriver

And finally we need to use webdriver to wait for the div with the class asyncNotifier. We used WebDriverWait for that.

public static void waitForAsyncCallsToFinish(WebDriver driver)
{
	waitForCssClass(driver, By.id("asyncNotifier"), "done");
}

Technical ,

ThoughtWorks Poker Night

August 19th, 2011

As part of the Sydney Social Club we had a Poker Night in the ThoughtWorks Sydney Office.

We had so much fun… There was not really much money involved, everyone chipped only $5 just to make things a bit more exciting.

poker_night_thoughtworks_social_club-68

poker_night_thoughtworks_social_club-41

Enif, Leo’s partner, was the winner of the night.

poker_night_thoughtworks_social_club-14

poker_night_thoughtworks_social_club-97

We had hilarious all in’s, like this one with almost nothing

poker_night_thoughtworks_social_club-95

poker_night_thoughtworks_social_club-79

Technical

Ignite Sydney 7

July 28th, 2011

I got really excited about Ignite after I saw my friend Jason Yip presenting. The format is quite challenging: 5 minutes and 20 slides. Enough of procrastination…  I finally decided to submit a proposal for the upcoming Ignite Sydney 7 (Oct 11th 2011)

One section of the proposal says: “Convince us, why the Ignite Sydney audience will want to hear from you”. So I decided to write this post… Smile

Let’s start with a bit of a summary of who I am… here

Also, I’m extremely passionate about the topic: Human Behaviour and Happiness

Links for some of my recent presentations:

 

With the ignite value of keeping it short and simple, that’s it.

Congratulations to the organisers for this amazing event and… Fingers crossed Winking smile

ignite-sydney7-fingers-crossed

Uncategorized