Orestes Carracedo

Scrum Master, PHP Ninja, cat owner
21 July 2013

It was 2010 when we got some projects at Focus On Emotions from Ikea. Among the challenging stuff we did for them there was a project for automating the process of the users registering for a credit card. The final product was a digital user stall/kiosk with an interactive touch screen a physical keyboard and mouse. This project needed a couple of tricky features: ID verification and bank authorization.

This was not our first rodeo and we had another public kiosk/stall project for the city hall, Ajuntament de Barcelona which allow citizens to do paperwork. They were challenging because we had to integrate lots of different providers, but we didn't manage any banking data so this was new to us. These projects had been running smoothly for years and we've got some recognition from them.

A couple of weeks after the project's launch we had gotten many reports of users being disoriented when following the process. One of the steps required the users to physically place their ID form on a small flatbed scanner for validation. Even though the physical space was an obvious empty box the users didn't realise that was where they were supposed to place their ID.

The client asked us to modify the kiosk structure, add a LED stripe around the empty box and have it blink when the users got to the ID validation step. We had to give it a little thought before coming up with a solution because we had a tricky problem: hardware access was impossible. The whole application was written in Java, HTML and JavaScript,and it ran as a served web app inside a secured environment using SiteKiosk. This was great for pushing software changes to the multiple kiosks installed for the project as well as for interacting with the bank's backoffice services in a secured environment (server-side). The manufacturer for the ID scanner had provided the dev team with an API that used ActiveX and JavaScript to control their hardware, so we followed that idea: we had to develop our own ActiveX control to activate the LED stripe whenever we needed to.

We bought a simple relay board with an USB interface and started working on it. This relay board was great because it had two different relays that you could control independently. Each relay had a tiny onboard LED indicating its state. You can find it on RobotShop, here.

I got a hold of the controller's specification [mirror] and wrote a simple program to control it over USB by sending the byte-encoded messages for each action (open/close relay 1/2). It consisted of a minimal Windows Forms interface with a few buttons to open/close the USB port and switching on/off the relays. When I was sure I could make it work, I wrote a small function library and compiled it as an ActiveX:
csc /t:library USBLEDControllerLib.cs
To make it available for Internet Explorer, the DLL had to be registered:
regasm /tlb /codebase USBLEDControllerLib.dll
Both regasm and csc are provided by .NET Framework 2. in my case, It was already installed on %WINDIR%\Microsoft.NET\Framework

To invoke the ActiveX control we use the full classname, including namespace.

var controller = new ActiveXObject("FOE.USBLEDControllerLib");
var version = controller.getFirmwareVersion();
console.log('Running FOE USB LED Controller version ' + version);

The simple ActiveX control would trigger a security warning on IE. We suppressed this warning by implementing a few visible COM methods flagged as [Serializable, ComVisible(true)] which come from the IObjectSafety interface. This told IE it could trust our library.

The controller for the board had a limited set of functions so we had to extend them for our project. I added a couple of threaded functions to start/stop blinking the LEDs synchronously, stopping/starting only one of them and have the other synchronize on start, etc... Even though we had very little time and a lot of pressure I think it was a fun project. You can see the PoC in the video below. You click a button on a webpage and a LED lights up. Neat! I love the clicking sound from the relays, so mechanical :D


Categories: programming project videos
Comments: --
09 June 2013

Besides my writing skills, my problem with blogging was the software I was using, Wordpress. I found it slow, heavy and often insecure. I didn’t want my server exploding whenever I got a traffic spike, I didn’t want upgrading my WP modules and being worried about security issues. It was kind of hard to get it to look the way I wanted it. I wrote a custom theme but I wasn’t really satisfied with it, so I bought a one which looked cool, but I still wasn’t happy with my blog because it wasn’t “mine”.

I wanted a static blog website that I could code and style the way I wanted, without restrictions. I wouldn’t have to worry about security since it would be static and would have no user input, search or comment features. I didn’t want to give up comments so I checked Disqus, whichs a really good commenting platform that you can embed anywhere without having to worry about security or performance issues. Disqus is a seamless iframe whith a lot of clever programming inside. Ben Vinegar, gave a great talk about it in 2012: Seamless iframes: The future, today!.

Regarding the traffic spikes and server resources, I decided I’d move the blog out of my lab hosting (which is a tiny virtual machine) into somewhere that could serve static sites and I only had to worry about bandwith costs,

I started researching about scaffolding tools and generators for static websites. I had used stuff like yeoman that worked reat for getting something started quickly, but it was more aimed at apps than static websites and I’d still have to do a lot of the work.

Then I found about GitHub Pages and Jekyll, and they turned out to be the perfect solution for me. Jekyll is a blog-aware static website generator written in Ruby by Tom Preston-Werner. It’s easy to get started with and powerful enough to let you add your own plugins and teach it new tricks. GitHub Pages allows you to serve static content from your GitHub repositories without any setup

The pros Jekyll on GitHub Pages

  • It’s already blog-aware, so it has a notion of posts, categories, tags and a timeline.
  • I can version my posts and contents using a CVS I love (git)
  • I can easily share the source code for my blog
  • I don’t have to worry about hosting
  • I can still use any domain name I own
  • It provides higher geek factor than having a WP blog

The cons

  • GitHub crashes every once in a while and maybe GH Pages comes down with it
Working with GitHub Pages

GitHub Pages are divided into user pages and project pages. The only thing you have to do is create a gh-pages branch on your repository. Whatever you push to the branch will be served on your project page at http://username.github.com/repository-name. If you push a Jekyll site, GitHub Pages will actually build the site for you and serve that instead of the Jekyll source.

Working with Jekyll

You create a new site running jekyll new PATH which creates a bare minimum site config and layouts.

To create the extra tag and category index, as well as the archived month pages, I had to extend the same classes: Jekyll::Page and Jekyll:Generator. The method is pretty straightforward:

  1. Create a class that inherits from Jekyll:Page
  2. In the page class, implement the initialise method
  3. In the initialise method, call self.process(@name) and self.read_yaml to get the contents of the layout
  4. Add to the site.data Hash any data you want to expose to the page
  5. Create a class that inherits from Jekyll:Generator
  6. Implement the generate(site) method which adds instances of the custom page to the site.pages Array

I generated the monthly archive by iterating over the site.posts Array and analysing the dates. To generate the sidebar menu that displays the year/month list I needed to have an index to iterate over, so I coded my plugin archive_helper. What I did was:

  1. Inherit from Jekyll::Site,
  2. Made an alias of the original site_payload
  3. In my site_payload method, called the original site_payload and get the returned data.
  4. Added to site.data Hash the indexes created from the posts’ dates.

The plugins to generate the tag and a category pages were already provided in the Jekyll plugin docs so I didn’t need to do any extra work.

You can get the source code for my plugins and all of this blog here

Deploying the site

The problem I had with my plugins is that GitHub pages builds the Jekyll sites using the --safe switch, which disables them. The alternative is to push your source code to the master branch and your generated site files to the gh-pages branch. I didn’t want to do it manually every time I updated the source, so I wrote a little post-commit hook that generates the site, wipes the gh-pages branch and pushes the freshly generated site to the gh-pages branch.

Using a custom domain name

Everything gets served from http://username.github.com/repository-name. Having a good grasp of the HTTP protocol is crucial for a web developer, and I think we should also know at least a little about the DNS protocol. I wanted to host my blog under blog.orestes.io, so I got to my DNS panel on my domain registrar and added a new CNAME DNS entry for orestes.io with the name was blog and the value orestes.github.com. A CNAME is a Canonical Name entry, which tells DNS clients asking where blog.orestes.io is, to ask instead for orestes.github.io.

Let’s check what’s going on with my domain name using nslookup.

$ nslookup blog.orestes.io

Non-authoritative answer:
blog.orestes.io	canonical name = orestes.github.io.
orestes.github.io	canonical name = github.map.fastly.net.
Name:	github.map.fastly.net

On the output above you can see how everything is being redirected to github.map.fastly.net

When you finally get to the HTTP server behind github.map.fastly.net, it checks the HTTP 1.1 “Host” header, which is sent by the browser and will contain the value blog.orestes.io. Then the GH Pages takes a look under the user’s projects and their /CNAME files to check if any of this projects is assigned to this domain. If there is, you get the static site, if there isn’t, a 404 error.


Categories: technologies code
Comments: --
10 April 2013
Categories: talks
Comments: --
10 December 2012

This was posted about a month after the launch of Ingress, an Augmented Reality game by Google. In the beginning you could only be invited by someone working on the game, so we had to post ingress stories, artwork, articles, whatever we could to get attention from them and receive an invitation to play. Today is much easier to get invited, you can just go to ingress.com and request an invitation. It's really fun!

Ok, I have to tell you about this. I was looking for information about "Ingress" which is some kind of game a few people are playing but nobody seems to know how to get access to. I was browsing around and found out about something called "Niantic Project". Apparently there's something big going on and only a handful of people and aware of it, the ones playing Ingress.

I found a few cool pictures while googling around and I wanted to save some for later, but I accidentally saved this one as a .html file and that's when things got weird.

Try and do it yourself. Save this image to your local disk, and rename it to from .jpg to .html. When you open it in your browser, it will look almost the same, but you'll notice that your browser's background is now black, and the image has a weird green border around it, something it didn't have before. If you move your mouse over the image, you're going to find a mysterious text that leads to a strange website. I don't know who exactly created that webpage, but there's a ton of info on there.

Why whould somedy hide something inside an image?
What are they hiding from us?
What is "Niantic Project"?


Categories: games videos
Comments: --
06 December 2012

Update july 2013: Jez's talk has been deleted :(

The playlist rom the recent GOTO Aarhus 2012 has been published on YouTube.

Jez Humble's "Implementing Continuous Delivery" where he talks about the organisational problems, mistakes and misconceptions that come up when trying to implement Continuous Delivery has been one of my favourites.

Link: GOTO Aarhus 2012 playlist on YouTube (79 videos, 53 hours)

Comments: --
21 November 2012

Ben Vinegar's talk Seamless iFrames: The Future, Today! was very interesting.

This was a WordPress blog until I switched to Jekyll and started using Disqus for the comments and I must say I love it.

Link: HTML5DevConf 2012 playlist on YouTube (60 videos, 30 hours).
Via: HTML5 Weekly

Comments: --
17 November 2012

Programmer Swizec Teller and author of the (now) famous blog post "Why programmers work at night" has started a project on Leanpub to publish a book about programmers.

[...] In December 2011 I wrote down a bunch of assumptions about Why programmers work at night (link) in a blogpost. I wrote it because I got tired of being called a lazy slob for waking up at 11am every day. After 4000 tweets, 10000 likes and many emails I didn't feel alone anymore. The most surprising feedback were emails along the lines of "Oh man! I finally understand my husband, thanks so much for writing this!". And it is because of those that I have finally decided to write a short ebook. In the book I'm going to:
  • Show fellow night-time programmers (and others!) that they are not alone
  • Give practical tips on living with your friendly neighborhood programmer
  • Support my original hypotheses by interviewing cool programmers
  • Explore the modern trend of super early wakeruppers who approach the night time from the other end

So if you're a programmer that feels missunderstood on your late nights of happy coding, maybe this book will be an ideal gift for your roomies, girlfriend, boyfriend, parents or even for your boss.

Link: Why programmers work at night: the book
Categories: books
Comments: --
16 November 2012

I first learned about Petr Mitrichev the past year when he won 2011's Facebook Hacker Cup. He's a Google developer leading the current competitive programming challenges. He also keeps an interesting blog at petr-mitrichev.blogspot.com where he talks about algorithms and sometimes challenges his readers with some problems.

MIT's Technology Review has a nice introductory article about him.

I also found some interesting reading material if you're into competitive programming. Codeforces has a great post about Sao Paulo Training Camp 2010 containing his solutions to problems and some video explanations.

Update March 2013: He came up on top at 2013's Facebook Hacker Cup as well. This is guy is amazing :)


Categories: people
Comments: --
14 November 2012

Barcelona Smart City Expo World Congress 2012 NFC Bootcamp

The NFC Bootcamp Barcelona 2012 was held as part of the Smart City Expo World Congress 2012 at the Fira Gran Via Convention Center in Barcelona. We had some problems when trying to get our accreditations at the entrance but with a little help from the organisation we managed to finally get inside.

We met Robert Sabella from OTA Training and we chatted for a bit while we waited for others to arrive. Rob started the day by introducing NFC and the work the NFC Bootcamp has being doing for the past year.

Bastien Latge from INSIDE Secure followed up with a more in depth talk about the key players in an NFC Ecosystem and underlined some of the most common problems and situations companies deploying NFC solutions encounter the most. He talked about the NFC parts, specially the Secure Element and the different implementations and security measures implemented in them. He also talked briefly about the hardware which provides NFC capabilities for mobile phones without built-in NFC tech.

The accreditation Just before lunch, we met Stéphane Doutriaux from Poken. He made a brief introduction about Poken with a video. Afterwards we all got our own pokens and did a little tour of the reception area and the schedule wall poster, poking along the way and getting comfortable with the devices.

After lunch, Gloria Lozano from BCN Touch gave her talk, focusing on use cases and their projects from the last past years.

Then Stéphane came back to talk a bit more about the marketing and user experience side of NFC and how he thinks we should put the most of our efforts in providing some value rather than some technology, and use NFC as a means and not as a goal.

At the beginning of day 2, we got a USB NFC reader and different cards with different NFC chips in them and Bastien finished his talk about the players in the NFC environment.

Then we met Fernando Cejas, a mobile developer based in Barcelona, working for Flomio. He's also de organiser of the Google Developers Group Barcelona. His talk was going to be more focused on de technical/developer side of NFC but due to the majority of the assistants being not so technical that part was skipped. Bummer.

Before lunch, we went for a walk around the Smart City Expo and Fernando was captured by an evil robot. After we rescued him, Fernando gave a more technical explanation of the NFC components, the different NDEF well known formats and the read/writing permissions. He also talked about the idea of "cloud tags", flomio, the FloJack to provide NFC for iphone/ipad devices and other solution prototypes they had researched using other tech such as the Raspberry Pi and the GuruPlug

Then Stéphane came back and we participated in a workshop with Poken and their partner tools. We created a campaign and linked a Poken Tag using the NFC Reader/Writer. We also learned a bit more about the technology used in Poken. The Poken tags use the same technology as the regular Pokens. Poken Tag They use a Swatch licensed chip with added NFC capabilities and a full USB stack,powered by a 9 volt battery that lasts about two years. Everything is encased in silicon so its fairly resistant, and of course, it's sticky. Poken Tags have to be activated using an NFC writer and power themselves off when they are stacked or they detect too much inference to not drain the battery.

We all got an NFC Bootcamp completion certificate on behalf of OTA Training and the AENFC and we took some pictures. It was a great experience and I'm sure both speakers and attendees will keep in touch with each other.


Comments: --
01 July 2012

PHP + Symfony developer Matthias Noback has written a really nice article about the use of Silex on outdated PHP projects. If you've been looking forward to migrate/redo some of your old projects using Symfony components, this may be worth reading.

Link: Let Silex Wrap Your Legacy PHP Application (and add Twig for templating)

Categories: php reblogs
Comments: --