Geek as a platform

Tamron SP AF10-24mm

I am not a pro photographer and don't like to spend a fortune in gear for my camera, but I've always wanted to buy an ultrawide lense...

I had the opportunity to buy the Tamron SP AF10-24mm for a decent price, and so far I am liking it... See a couple of pics I took a few days ago:

'Shibuya crossing'

'Zenko-ji Nagano'

'Matsumoto Castle'

Maybe not the best uw lense out there, but good enough for the price

\\psgonza

We love you Bash

We love you Bash… but sometimes you are so damn slow

I'm sure this has happened to you before… I had to create an ldif file containing 70.000 entries like these ones:

dn: user=XXXXXXXXXX,rootdn=com
changetype: modify
replace: attr1
attr1: qwerty1
-
replace: attr2
attr2: {"reporting": [{"name":"Total","reportingLevel":"total","subscription":"A", "time":500,"reset":{"main":"30 ","time":"30 "}}}]}

(the real data was a little bit larger, this is just an example)

It was supposed to be something really quick and simple, one of those one-liners you write in 3 seconds… I said to myself: bash + loop + echo + redirection to file = WIN

Well, it proved me wrong :

The quick and dirty code to be executed in the shell:

for i in `seq 1 70000`;
do
echo -e "dn: user=XXXXXXXXXX,rootdn=com
changetype: modify
replace: attr1
attr1: qwerty1
-
replace: attr2
attr2: {\"reporting\": [{\"name\":\"Total\",\"reportingLevel\":\"total\",\"subscription\":\"A\", \"time\":500,\"reset\":{\"main\":\"30 \",\"time\":\"30 \"}}}]}
"  >> modify.ldif
done

So I issued that command, and went out for a bite… 30 minutes later, the fraking thing was still running!!! How was that even possible…

I realized I was opening the file every time I wrote a line, a nonsense… so I just stopped the script and tweaked it a little bit… Result: pretty much the same… Here's some figures with only 5000 iterations per loop with different redirections:

Initial redirection:

for i in `seq 1 5000`; do

> "  >> modify.ldif; done
real    4m17.606s
user    1m4.028s
sys     1m35.850s

Only one redirection outside of the loop:

for i in `seq 1 5000`; do

> " ; done >> modify.ldif
real    4m30.218s
user    1m8.496s
sys     1m41.390s

I also tried to use a file descriptor, just for the sake of it, but it has no impact:

exec 4>> modify.ldif
for i in `seq 1 5000`; do

> "  >&4; done
real    4m32.197s
user    1m10.248s
sys     1m39.294s

And using the FD outside of the loop:

for i in `seq 1 5000`; do

> "; done >&4
real    4m31.478s
user    1m11.740s
sys     1m38.678s

So all in all, as you can see, Bash IO redirection performance, basically sucks.

A 20 lines python script (with no optimization whatsoever) is able to generate the whole ldif file (creating 70.000 entries to modify) in less than 1 second:

#!/usr/bin/env python

data="""dn: user=XXXXXXXXXX,rootdn=com
changetype: modify
replace: attr1
attr1: qwerty1
-
replace: attr2
attr2: {\"reporting\": [{\"name\":\"Total\",\"reportingLevel\":\"total\",\"subscription\":\"A\", \"time\":500,\"reset\":{\"main\":\"30 \",\"time\":\"30 \"}}}]}
"""

with open("modify.ldif",'w') as outputF:
    for iter in xrange(70000):
        outputF.write(data.replace("XXXXXXXXXX ",str(iter)))

Executing it:

# time python gen_ldif.py
real    0m0.506s
user    0m0.108s
sys     0m0.052s

How about that? Sometimes it's just better to use the right tool for the right job...

So yeah, we love you Bash… Even though you are really slow sometimes.

\\psgonza

Moving to SSL/TLS

10 minutes... That's all it takes to configure HTTPS thanks to Let's Encrypt. So from now on, this blog will be using https by default..

There is a lot of information about how to configure it available in Internet (you can find a usefull piece of information here) so I won't even try to add anything new.

Let's Encrypt certs have a ninety-day lifetime, so make sure you renew your certifications each 3 months (some examples here).

As a final note, if you are running a static blog generator as myself, don't forget to modify your config file and replace "http://" by "https://".

\\psgonza

Docker and Kubernetes Workshop

Yesterday I attended a very interesting workshop in ShuttleCloud offices in Madrid about Docker and Kubernetes...

I'd say most of the people already knew a little bit about Docker (at least basic knowledge), but it was the first time with Kubernetes for most of us... It was a very good introduction to the technology, and we spent a few hours playing around with pods,services and replicationcontrollers in our own cluster (it is pretty simple to setup a small environment using Vagrant or Google Cloud Engine.

I'd love to attend to more whole-day events like this one (lunch was a plus, but it is not needed whatsoever), since it is a great way to learn/improve our technical skills and helps to build a "community" (I saw some familiar faces from Python meetups in the workshop)

This is a picture of all the participants:

'workshop' (taken from Shuttlecloud twitter account)

Thanks to Ivan and Alex for sharing their knowledge, and of course, to jobandtalent for providing the lunch!

\\psgonza

Free ranting about iPhone6

Here's a few things about Apple iPhone6 that have been bugging me lately:

1 - I was asked to delete all the photos from an iPhone6... I was hoping it was going to be a matter of connecting the phone to my laptop (MBP), click here, click there, select all, delete and you're done... Well, apparently, it is easier to put a rocket in Mars than deleting all the freaking photos from an iPhone6. Shame on you Apple... you made my life miserable for 1 hour (I had to delete all the photos from the phone itself.... 5467 photos!)

2 - Playing around with the same phone, I pressed the home button (btw, who can live with only one button?? for everything!! are you crazy?) for long enough to invoke Siri, with the phone locked... And she answered to me!!! Let me repeat it.. I long-pressed the home button, I asked Siri to "call mum" (not my mum obviously because it wasn't my phone) from another person locked phone... I would say it is a huge security flaw to allow anyone to make calls that way. Shame on you Apple, again.

\\psgonza

PS1: I am not an Android/Google fanboy... I own a MBP and I cannot complain, it just works.

PS2: Probably these two things I mentioned are not new if you are an iPhone user, which I am not...

PS3: Ranting is free :P