It is never enough

I am writing this in the middle of the Phoenix Park — one of Europe’s most stunning urban parks. And I can say with total certainty that I’ve never experienced something so sublime as I am experiencing it right now. I never thought I would.

Every one of us have dreams, and I am certain that I am living mine right now. If someone told me that I would be, one day, sitting on a bench with my laptop in the middle of the afternoon, watching people pass me by writing about my life in Europe, I would have told them to cut it out, because that would never happen.

Turns out that I would have been wrong.

Since I was a little kid, my one and only true dream is to live in an English-speaking country. For me, that was unreachable. Farfetched. Borderline impossible. Now, I am living in Ireland, surrounded by people I didn’t know could be so kind, in a city so full of culture and colour. I get to speak english every single day. I get to ride a bike. I get to enjoy the little things in life I didn’t knew I enjoyed because I felt imprisoned in my own country, living in constant fear and uncertainty.

6 months into this, I still cannot grasp the reality that I am in Europe. “Europe?” —I would say— “that’s just another world”.

Growing up, my goals broadened. When I started in the web development industry, I would constantly get inspiration and knowledge from all over the internet, but there was this place were you could find it all. Where the culture of progress, learning. community and success was the number one thing. Not even in my wildest dreams I could have imagined that I would become part of this wonderful family. When speaking to my friends and family about this, many times the conversation would boil down to me saying: “Me, there? Unthinkable”.

I wanted it so bad. It is now a reality.

I feel like I am blessed, yet unfulfilled. I would have never imagined that I would be doing almost all that I love at the same time. And now that I am here, I don’t know where to go. I don’t know what’s next.

I don’t know if it’s exciting. I don’t know if it’s frightening. But I do know one thing: it is not enough.

I always feel like I am not working hard enough, but life constantly proves me wrong. But this is not enough. And if this happens to you… if the special turns to normal, the farfetched becomes the norm, and when the impossible turns into reality, you may feel there’s nothing else.

But there is, because it is never enough.

Add a class to the comment form and submit button in WordPress

I am diving into WordPress. In reality, I am diving into a lot of things code-related now but WordPress caught my eye in a special manner (and it was about time, to be honest). It’s very easy to work with, and the results are quite impressive.

During my training, I noted something in the function definition of the comment form that struck me with surprise: you’re not able to define a class for the generated form, nor for the submit button. Yes, you can add ID’s, but when you’re using something like Twitter Bootstrap, you will find this useful.

After searching for a bit, I encountered this StackOverflow answer (go figure!) that I found quite clever. For some reason, it took me around 40 minutes to find this answer, so I am leaving it here, and also expanding about on it.

And yes, I refused to “only use jQuery”.

In a nutshell, since the comment_form() outputs the form immediately to the browser, you use Output Buffering to modify its contents. Brilliant!

This is the original snippet:

<?php
  ob_start();
  comment_form();
  echo str_replace('class="comment-form"', 'class="comment-form your-custom-class"', ob_get_clean());
?>

Although simple, it does the work. However, we can improve it a bit.

First, we can wrap the function with another function in our theme’s functions.php file, so we can call it like we call comment_form():

<?php
function custom_comment_form($args = array(), $post_id = null) {
  if (isset($args['form_class'])) {
    ob_start();
    comment_form($args, $post_id);
    $string = str_replace('class="comment-form"', 'class="' . $args['form_class'] . '"', ob_get_contents());
    $string = str_replace('<input name="submit"', '<input class="btn btn-primary" name="submit" ', $string);
    ob_end_clean();

    // submit
    echo $string;
  } else {
    comment_form($args, $post_id);
  }
}
?>

We’re adding a new key to the $args parameter: form_class. This allows to use the $args array just as you would with comment_form(), but the function would use output buffering to edit the form correctly — what is happening is that what should be outputted straight to the browser is buffered and you’re able to modify it using str_replace (or any string manipulation function you want).

This overwrites the class definition with the class you want and you are able to add several classes if you want to by separating them with whitespace.

To modify correctly the input button with a class of your choice, we use the same buffered string and modify the input:

<?php
 $string = str_replace(
  '<input name="submit"',
  '<input class="btn btn-primary" name="submit" ',
  $string
 );

ob_end_clean();
?>

If you want to dynamically change the class, you can add another key to the array and concatenate the result.

That way, you will be able to customise the form in whichever way you want!

Geographical Coordinates: from the E6 notation to Decimal Degrees

I have been fiddling around with the CityBikes API recently for a fun christmas project I have in mind using Laravel 4, AngularJS and the excellent Google Maps API. Whilst developing, I have encountered a particular thing to keep in mind.

Apparently, the CityBikes API has a profound hatred against decimals. They serve their latitude and longitude coordinates in something called the “E6 notation”. I was quite astonished that neither the OpenStreetMaps API or the Google Maps API provided natural ways to convert this notation to proper geographical points in the map, so as Leonardo DiCaprio in Inception, I needed to go deeper.

Looking through the internet and searching for answers, I found out that this is not a “proper” (big, fat quotes in here) geographical notation, but something called “Microdegrees”.

According to the Conversion Center:

Microdegree (μdeg) is a unit of angle measurement equal to 10^–6 deg, or 3.6 milliarcseconds.

You’re able to measure longitude and latitud through degrees, minutes and seconds and decimal degrees, so I was into something.

As it turns out, the Microdegrees notation or E6 notation is only the decimal degree notation multiplied by 10-^6 (or 1E6). This means that a coordinate in the E6 notation as given by the CityBikes API can be calculated in a shockingly simple way:

// "lat": 53339434, "lng:-6246548" — as given by the CitiBikes API in JSON format
// this will result in 53.339434 and -6.246548
// which are correct coordinates in degree notation + a proper LatLng object
latLng = new google.maps.LatLng((53339434 / 1000000), (-6246548 / 1000000));

It’s that simple! Just divide (because it’s 10^–6) the amount of zeroes (6!) and you will go from the E6 notation to the standard, Google Maps compatible degree notation.

You may be able to substitute 1000000 with 1E6, but I don’t know. I am not a daredevil.

More information:

What coffee has taught me

Ever had one of those moments when you realise something by experiencing something mundane and completely unrelated?

For me, it was all about coffee. It’s related to the professional work we, as developers and designers, do every day. Let me elaborate.

See, it’s kind of silly. The whole thing started a few days ago when I was trying to open my bank account. Coming from a country when you can easily encounter people in customer service who can say things from “What do I care?” to literally insult you because they cannot do their jobs properly (and they cannot get fired for it, but that’s something for another time), I found that’s quite nice that after you make an appointment, customer service representatives will approach to you and offer you a coupon for a nearby coffee shop.

It was nice, and I hadn’t slept a lot so I could use the kick. I walked for a couple of minutes to Cafe Sol, a small, lovely place in Baggot St Lower. where I had to wait in a small queue to get my coffee. The place seemed really popular for a place that wasn’t so busy in its surroundings.

I finally got my coffee. Tall Mocha with Cream, I remember; nothing special. I waited there for a few minutes, and I still had time to get to my appointment, so it was OK. I left the place, back to the bank. I attempted to take a shy first sip, hesitant, almost scared of what could happen, using one of those small plastic cups specially designed for coffee. I later found out those are called Takeaway Cups.

I drank.

It was delicious. It blew my mind.

I had never tasted something like that before (I am not a avid coffee drinker, so I can be easily surprised) . Of course, that hot, heavenly drink got stuck into my mind for days.

Until today, when I said to myself:

“I am gonna make a cup of Coffee just like the one I had. It’s going to be delicious”

Not being a connoisseur of Coffee, I thought that would be a great idea. I mean, it’s coffee. Anyone could do it, right?

“What could go wrong?”, I kept repeating to myself. “I’ve seen a thousand people do this in under a minute and it ends up being a heavenly experience”.

I sneak up to the kitchen, and I find some instant coffee, milk, and hot water (first mistake of a series of mistakes: no sugar) and began my adventure.

Spoonful of coffee, hot water (second mistake of a series of mistakes: water’s not boiling) and stir it up.

My mouth was ready. I add up some milk (third mistake of a series of mistakes: freezing cold milk) to the drink and I feel like I am brewing perfection.

The drink was ready.

My heart starts to race, remembering the feeling that went through my body when I had that first shy sip. I do the same: I take a slow, hesitant sip of that big, tall mug of coffee.

I wish I never had.

I wish I was in one of those weird time-travel episodes of Family Guy, so a disgusted, full of regret me of the future grabs me by my jacket and yells to me “Don’t do it! NO! Save yourself, this is madness, MADNESS I TELL YOU!”

But, what did I do wrong? It’s just coffee, milk, sugar and hot water. Anyone could do it.

See what I am trying to say here?

These days, anyone can open up a text file, put “Hello World” in it then save it as .html. If they’re feeling adventurous, they will even do it in PHP. Heard of Photoshop? Easy.

Anyone can do that”, they say. Then things like this happen.

It only took a minute, so it’s easy. It’s not.

In the sage words of The Oatmeal, talking about clients that want to design their own sites instead of letting the professional do it:

“If you were an engineer designing the turbine of a commercial airplane, would they interfere, I wonder?”

It’s not something that you can find in your room or in your kitchen? Oh yeah, it must be difficult. It’s not like it’s graphic design, amirite?

Behind that cup of wonderful, marvellous, succinct and delicious coffee there’s hours of training and practise, experience, careful technique, trial and error, concentration and a well thought recipe that has been researched for years. As you may imagine, our job isn’t any different.

So the next time you’re making a cup of coffee, don’t forget that it’s not only coffee, sugar, hot water and milk.

P.S: I didn’t actually learnt this from coffee, but I wanted to make sure I got the metaphor across. I’ve know this for years. You known, being a developer and all.

P.P.S: Thanks to @webjac for the tip and for making me post this to Medium. Perhaps more rambling to come.