Great dev quote

Found this one on Hacker News and really liked it :


                // At this point, I’d like to take a moment to speak to you about the Adobe PSD format.
                // PSD is not a good format. PSD is not even a bad format. Calling it such would be an
                // insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having
                // worked on this code for several weeks now, my hate for PSD has grown to a raging fire
                // that burns with the fierce passion of a million suns.
                // If there are two different ways of doing something, PSD will do both, in different
                // places. It will then make up three more ways no sane human would think of, and do those
                // too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide
                // that *these* particular chunks should be aligned to four bytes, and that this alignement
                // should *not* be included in the size? Other chunks in other places are either unaligned,
                // or aligned with the alignment included in the size. Here, though, it is not included.
                // Either one of these three behaviours would be fine. A sane format would pick one. PSD,
                // of course, uses all three, and more.
                // Trying to get data out of a PSD file is like trying to find something in the attic of
                // your eccentric old uncle who died in a freak freshwater shark attack on his 58th
                // birthday. That last detail may not be important for the purposes of the simile, but
                // at this point I am spending a lot of time imagining amusing fates for the people
                // responsible for this Rube Goldberg of a file format.
                // Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this,
                // I had to apply to them for permission to apply to them to have them consider sending
                // me this sacred tome. This would have involved faxing them a copy of some document or
                // other, probably signed in blood. I can only imagine that they make this process so
                // difficult because they are intensely ashamed of having created this abomination. I
                // was naturally not gullible enough to go through with this procedure, but if I had done
                // so, I would have printed out every single page of the spec, and set them all on fire.
                // Were it within my power, I would gather every single copy of those specs, and launch
                // them on a spaceship directly into the sun.
                // PSD is not my favourite file format.


Credit : https://code.google.com/p/xee/source/browse/XeePhotoshopLoader.m?r=f16763d221dfca6253983824b470adf553a19e06#108

Automation, Ninja Blocks

Thoughts on open source automation

Lots of things going on on the open hardware and open source front these days. Many more advanced users are looking to use those innovations in their home. The way I look at it is geeks built tools to help geeks out with annoyances. As an IT guy, my annoyances are not in my home so much as my work place. Some examples.

Ninja Blocks

I used the Ninja Blocks as a cheap backup system to counter-verify data from my main systems for temperature and movements. They are so easy to setup and move around I can also use it to monitor places that are not covered by the main system. I would not deploy it in production as the main system. Being wireless it’s not the best fit for enterprise needs, but the cheap supply chain powering the Ninja Blocks, makes it a very solid backup and test system.


openHAB is the most single amazing piece of software out right now for automation. It’s a programmable brain. You can connect openHAB to almost any connected object out there. If you can’t, you can easily write a plugin to support it. Once you have it configured, you can add rules based on states or events. It’s really powerful. I use it at work to drive almost every connected devices in the building.

The best thing is that once you have openHAB running, all your stuff is exposed trough a neat Web API. It’s the first effort to normalize the data and the communications between all connected devices.

Raspberry PI

No secret, it’s everywhere now. When people are talking about commodity hardware the PI is what I have in mind. Granted the GPO headers are a bit weird compared to the BeagleBoard or Arduino, but a full stack at 59 bucks (with case and Noob SD card) that’S a steal. We use it to monitor commodity hardware like distribution switches too cheap to support SNMP, PDUs, UPS and mode.

With a Shinken server, the RPis are used as the data source and the monitoring process for the hardware. Once you have the basic images, you can just copy them with a disk dump (dd) and voilà!

With the current price of home automation hardware, I think we’re still in enterprise price tags. But it’s getting really affordable. Before long we’ll have usable home solutions, but until then, keep on hacking in the workplace.

Ninja Blocks

What I had to do to get my Ninja Blocks running

I went and order the december batch of Ninja Blocks. Got it in the mail last week. I was psyched!

What you need to do is not quite easy to figure out. So in order to save yourself a bunch of time I won’t get back, I’ll document everything here.

Register your NB

Plug it in the wired ethernet port, go in the backend of the NB interface and add it using the serial number. Once that’s done you’ll get the IP of the device.

Setup the NB so it’ll actually work

SSH into the NB (which is a beagleboard). Password is temppwd

ssh ubuntu@ip_of_the_NB
sudo su -

Update the Wifi chip, otherwise your setup process will never complete.

curl http://assets.ninjablocks.com/beagle/bbbupdatewifi.sh | bash

Install the NB management interface so the online backend will work

curl http://assets.ninjablocks.com/beagle/install-block_admin.sh | bash

After that you can complete the setup on the administration page of the NB.



Sending SMS from Huawei LTE B593 Routeur (and possibly others)

We got a LTE routeur from Telus at work and I wanted to use it as a backup plan for sending SMS from our Nagios server.

Figured it would be REALLY easy using cURL. Turns out it is, once you’ve figured out all that is wrong with the system.

So here it is, the lines I used to send SMS using cURL on a Huawei LTE B593.

First thing first, you need a cookie file. Called mines cookies.txt.

# Netscape HTTP Cookie File

# http://curl.haxx.se/rfc/cookie_spec.html

# This file was generated by libcurl! Edit at your own risk.

huawei.smarthub    FALSE    /    FALSE    0    SessionID_R3    0

.huawei.smarthub    TRUE    /    FALSE    0    Language    en

.huawei.smarthub    TRUE    /    FALSE    0    FirstMenu    Admin_0

.huawei.smarthub    TRUE    /    FALSE    0    SecondMenu    Admin_0_0

.huawei.smarthub    TRUE    /    FALSE    0    ThirdMenu    Admin_0_0_0

Next part is a bit « Black box magic. » In order to actually correctly send a SMS you need to first login, then fetch a page THEN send the message. If you don’t fetch the page, it won’t work — Go figure.

Note that you need to Base64 encode your password.

Ok let’s login:

curl --cookie-jar cookies.txt --data "Username=admin&Password=Base64EncodedPassword" http://huawei.smarthub/index/login.cgi --cookie cookies.txt

Note that when you login the SessionID_R3 cookie must have a value of 0 otherwise it will fail. Since login in changes this value to give you a session ID, you need to reset it to 0 for every connection.

Now that you’re loged in we need, for some obscure reason, to fetch the message page, so let’s do that.

curl --cookie-jar cookies.txt http://huawei.smarthub/html/sms/message.asp --cookie cookies.txt

Now, we can  send an actual message

curl --data "Receivers=5555555555&SmsContent=Test SMS&EncodeType=7bit&LengthList=8,0,0,0&CurrentTime=5/14/2013 2:29:59 PM" http://huawei.smarthub/html/sms/sendSms.cgi?RequestFile=/html/sms/message.asp --cookie cookies.txt

This will send the message Test SMS to 555 555-5555. Not you can split the Recievers with ; to add (AFAIK) as many as you want.

Note you need to change the first number in the LengthList to the number of character in your message (the 8 in 8,0,0).

And that’s it!

One of my collegue packaged it all up in a nice, Nagios ready, sendsms.sh.

# ./sendsms.sh

Usage: ./sendsms.sh -t number [-H hostname] [-p password] [-m "message"] [-v]


-h : show this help

-H : hostname (or IP) for the SMS gateway

-p : password for admin

-t : destination (SMS number) (required)

-m : message (will be converted to 7-bit)

-v : verbose; show the curl output

Link seems to be broken so here’s the code

#! /bin/bash

# Send SMSes using a Huawei gateway, via cURL.
# kevin.lamontagne@libeo.com 2013-05-15

set -e
set -u

function usage(){
 /bin/cat <<EOF
Usage: $0 -t number [-H hostname] [-p password] [-m "message"] [-v]
-h : show this help
-H : hostname (or IP) for the SMS gateway
-p : password for admin
-t : destination (SMS number) (required)
-m : message (will be converted to 7-bit)
-v : verbose; show the curl output
 exit -1;

password="MTExMTEx" #111111 en b64
message="Test SMS"

# Parse args
#only "-t" requires a value
while getopts ":hH:p:t::m:v" opt
case $opt
 echo "Invalid option: $OPTARG"
 echo "-${OPTARG}: Argument required"
if [ "$OPTERR" != "0" -o -z "$destination" ]

# http://stackoverflow.com/questions/296536
rawurlencode() {
 local string="${1}"
 local strlen=${#string}
 local encoded=""

 for (( pos=0 ; pos<strlen ; pos++ )); do
 case "$c" in
 [-_.~a-zA-Z0-9] ) o="${c}" ;;
 * ) printf -v o '%%%02x' "'$c"
 echo "${encoded}"

#Convertir en ASCII 7-bit
message="$(echo "$message" | /usr/bin/iconv -c --to-code="ASCII")"
#Couper a 154 chars
message="$(echo "$message" | cut -c1-154)"
#Encoder pour le GET
message="$(rawurlencode "$message")"

#Create a temporary cookiejar
cat /etc/icinga/huawei_default_cookie.txt > "$cookiejar"

#Login with a default cookiejar
curl -s $verbose --cookie-jar "$cookiejar" --cookie "$cookiejar" --data "Username=admin&Password=${password}" "http://${myhost}/index/login.cgi" >/dev/null

#Need to retrieve this page before sending a SMS...
curl -s $verbose --cookie-jar "$cookiejar" --cookie "$cookiejar" "http://${myhost}/html/sms/message.asp" >/dev/null

data_send="Receivers=${destination}&SmsContent=${message}&EncodeType=7bit&LengthList=${mlen},0,0,0&CurrentTime=$(date '+%D %r' | sed 's/ $//')"
command_send='LC_TIME="en_US.UTF-8" curl -s --data "$data_send" "$url_send" --cookie "$cookiejar"'
if ! eval $command_send | grep "gVarSendStateOK" -c
 echo "Erreur dans l'envoi de sms"
 exit 2

rm -f "$cookiejar"

Nexus 7 screen flickering after drop

Just fixed my Nexus 7 after my girlfriend dropped it on the floor. Figured I’d share my experience so people can stumble on it if they ever search Google because my search wasn’t very helpful. So here we go

What happened

My Nexus was in my bag which was hanging from the side of a whiteboard. My girlfriend walked to close to it and the bag fell on the ground. Second time this happened to my in less then 6 months. First time I brought it back to where I got it. They replaced it no questions asked.

This time around though I wasn’t so lucky. They told me to call ASUS customer support. Now I got on the site and they needed my serial number.

So I went ahead and open my Nexus 7 to get the SN. Once opened I figured it might as well try to fix it.

The symptoms

After dropping the tablet, it would boot but the screen would be garbled, only pitch black and  colorful noise. If you’re experiencing this right now, just know I feel your pain. It sucks.

The fix

It looked to me like this was a classic case of unplugged screen. Seemed weird to me that dropping a table on the floor would disconnect the screen, but I had nothing to lose.

Image iFixit all rights reserved

I went over to iFixit and found the article about replacing the screen to try and figure out which wire could be unplugged. I found it, didn’t even have to remove the battery it right below the battery connector. I just pushed the wire to the right, closed the tablet back and voilà! Problem solved.

Hope it helps!


De l’apprentissage du web

S’il est une profession libérale, ce doit bien être celle de l’intégration web. Toutes les meilleures ressources, les meilleures pratiques et les meilleurs exemples concrets sont sur la toile, accessibles, bien documenté et facile à trouver.

Utilisant des standards ouverts, tout du web peut être copié, utilisé, décortiqué. Il n’y a aucune raison de ne pas être à la page et au meilleur de ses capacités quand on fait du web «frontend.»

Il est aisé de constaté les limites des développeurs ou les limites de leurs gestionnaires. Quand on tourne les coins rond en web, ça parait!

Dans le monde du logiciel libre, un adage qui circule est que pour faire du bon code il faut avoir vu du bon code. Le bon code est souvent révisé par de pairs, modifié par leurs suggestions, critiqué par la communauté d’utilisateurs et encore modifié avec le temps.

Le processus de création de code est un d’ouverture et d’humilité.

Faites du bon code, il n’y a pas d’excuse pour faire autrement.

(Premier article de blogue rédigé sur mon iPad. Je n’ai pas Antidote, soyez indulgent quand à la qualité du Français 😉 )

Code, WordPress, ZAP

AuthPuppy pour WordPress à la sauce ZAP

AuthPuppy est chez ZAP depuis presque 2 mois maintenant et je travaille, dans mes temps libres, à finir la migration. Une des raisons qui explique le délai est qu’il n’existe pas de plugin bien documenté et fonctionnel pour AuthPuppy et WordPress.

Celui qui existe est développé par Île sans fil, mais je n’ai pas compris son fonctionnement rapidement et quand j’ai compris, je l’ai trouvé trop compliqué. J’ai donc décidé de faire le mien, qui supporte très peu de scénarios d’utilisation, mais celui qu’il supporte est, selon moi, le plus facile à utiliser.

Mon scénario

Chez ZAP, l’authentification se fait maintenant par l’adresse MAC. Ce qui veut dire qu’il n’est pas nécessaire de supporter la connexion des usagés. De plus, dans l’objectif de réduire la complexité pour l’utilisateur, la page de connexion est standardisée pour tous.

Le plugin ExternalCMS permet une redirection vers n’importe quel lien externe. Naturellement, le meilleur CMS du monde est WordPress, il est donc naturel que ce soit celui qui ait été retenu chez ZAP.

L’utilisation est simple: L’usagé ce connecte sur un point ZAP, est redirigé vers la page de connexion consolidée (la même maudite pour tous) et, quand il a appuyé sur «Naviguer», on y voit la page de contenu du point ZAP.

Tout ce qu’il faut, c’est donc que l’usagé soit redirigé vers une page cohérente, selon son contexte (son point d’accès ZAP).

J’ai donc développé un petit plugin (encore en développement d’ailleurs) qui permet de déterminer et afficher un contexte pour l’usagé. Il s’appelle, tout simplement AuthPuppy ZAP (APZ). Ce qu’il fait est très simple, il s’insère dans blogoption(‘name’) et ajoute quelques fonctions pour les développeurs de thèmes ou de widgets.


APZ s’insère quand le développeur essaie d’aller chercher le nom du blogue, dans le thème. Si l’adresse du blogue est une node ID valide pour AuthPuppy, c’est le nom du node qui remplacera le titre du site.

Dans le thème de ZAP, l’acronyme «ZAP -» est aussi retiré, afin de faciliter l’affichage.

Nouvelles fonctionnalités

Pour le moment, APZ introduit une seule nouvelle fonction pour les thèmes: apz_connected_users. Cette fonction permet d’afficher le nombre d’usagé en ligne sur un point d’accès.

Cache et «failover»

APZ inclut l’utilisation obligatoire de Cache_Lite. Cette inclusion permet de diminuer le nombre de requêtes sur le serveur d’authentification, qui est le plus sollicitée dans l’exploitation d’un organisme qui fournit du WiFi. Il y a aussi un failover pour les requêtes HTTP. Si elles échouent, les informations de la node ne sont pas récupérées, sans toute fois affecter le bon fonctionnement du thème.