A Dream Within a Dream

Take this kiss upon the brow!
And, in parting from you now,
Thus much let me avow —
You are not wrong, who deem
That my days have been a dream;
Yet if hope has flown away
In a night, or in a day,
In a vision, or in none,
Is it therefore the less gone?
All that we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore,
And I hold within my hand
Grains of the golden sand —
How few! yet how they creep
Through my fingers to the deep,
While I weep — while I weep!
O God! Can I not grasp
Them with a tighter clasp?
O God! can I not save
One from the pitiless wave?
Is all that we see or seem
But a dream within a dream?

Each day is the last of its kind

Each day is the last of its kind, once it is past it will not happen again. Take pleasure on small things and try to be conscious of your decisions. 

Make your own flow instead of going with the flock. Or go with the flock if that is really what you wish. 

The biggest challenge in life is being truly awaken. How many of your decisions are truly yours? And how many are just made by your surroundings? Are you truly proud of yourself?

Do not look 10 years forward, instead keep asking yourself: If i die tomorrow, what would I miss the most? If i die tomorrow, what would it be my biggest regret?

The Art of Wishful Thinking

Wishful Thinking is the art of trying to solve problems in the best way, the way you wish you could, and then working to make that possible. It is a recursive approach so the solution of a wish can lead to other wishes and so on…

Wishful Thinking is an abstract concept that can be used to break up big problems into smaller nice parts. You can probably apply that to everything your life… but let’s do it in javascript!

Our problem will be the infamous FizzBuzz. We will solve that with javascript, tests and a lot of Wishful Thinking. So let’s introduce the problem:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Hum… 1 to 100 is too hard to test. I wish I could choose the Min and the Max, if we can solve from Min to Max we can solve from 1 to 100. Let’s generalize the problem:

Write a program that prints the numbers from MIN to MAX. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

That is better so let’s do a simple test on the code that I wish I had:

    console.assert(fizzbuzz(1,1) === [1]);

We got an error “ReferenceError: fizzbuzz is not defined”. Coz we don’t have that method so lets fix that by implementing that function.

    function fizzbuzz(min, max) {
        return [1];

What!? The test fails again? Yes, for javascript [1] is not [1]. :/

Fortunately we can we can use JSON.stringify and compare the strings, lets change the tests.

    console.assert(JSON.stringify(fizzbuzz(1,1)) === JSON.stringify([1]));

That works but the test code looks very bad, I don’t want to duplicate that crap several times, I wish it was better… I want a better assertion but javascript just gives that console.assert so lets make our wishes come true.

    // That assertion would be nice but javascript don’t gives us that.
    assertFizzbuzz(1, 1, [1]); 
    // Lets implement our custom assertion that will fulfil our wish
    function assertFizzbuzz(min, max, result) {
        var expected = JSON.stringify(fizzbuzz(1,1));
        result = JSON.stringify(result);
        console.assert(expected === result);

Cool, now we have a very nice assertion for fizzbuzz, and we can start to triangulate, so lets add a the tests containing our wishes:

    assertFizzbuzz(1, 1, [1]);
    assertFizzbuzz(1, 3, [1,2,”fizz”]);
    assertFizzbuzz(4, 6, [4, “buzz", “fizz”]);
    assertFizzbuzz(10, 15, [“buzz”, 11, “fizz”, 13, 14,  “fizzbuzz"]);
    assertFizzbuzz(99, 101, [“fizz”, “fizzbuzz”, 101]);
    // you could add more tests if you want but I think those are enough.

And implemente the code that will make it pass:

    function fizzbuzz(min, max) {
        var list = [], i;
        for(i = min; i <= max; i++) {
            if(i % 15 === 0){
            } else if (i % 5 === 0) {
            } else if (i % 3 === 0) {
            } else {
        return list;

And now the problem is solved, if for some reason you wished a different api you can just create a wrapper method or refactor the the code in that case you should to change the assertFizzbuzz function first to reflect your new wishes, and refactor the code to make that dream come true and all your tests will pass.

Fix for (ArgumentError: invalid byte sequence in US-ASCII)

I was getting the following error whenever I tried to deploy with Capistrano:

** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: (ArgumentError: invalid byte sequence in US-ASCII) connection failed for: (ArgumentError: invalid byte sequence in US-ASCII)

But after researching I found out that the problem was on some gem’s file and the fix is pretty simple, all you need to do is:

$ export LANG=en_US.UTF-8
$ export LC_ALL="en_US.UTF-8"
$ bundle

The lines above will force the file system to use UTF-8 and bundle will use UTF-8 for all the gems.

Update: Is better to add the export properties above to your ~/.bash_profile (or ~/.zshrc) otherwise you will have to do the above steps whenever you want to bundle.