Eric Gourlaouen

Read this first

Demystifying the Golang Context objects

Golang is a language that was built with concurrency in mind. It makes creating threads trivial and crystal clear, and enables easy inter-thread communication using the channels abstraction:

func main() {
  message := make(chan string)

  go func() {
    fmt.Println("Hello from thread 1! Waiting on a message...")

    receivedMessage := <-message
    fmt.Println("Thread 1 received the following message:", receivedMessage)

  go func() {
    fmt.Println("Hello from thread 2!")

    fmt.Println("Thread 2 sending message to thread 1...")
    message<-"hello from thread 2"

With Go 1.7, Context objects were added to the language’s standard libraries. These objects push the abstraction even further to manage an application’s thread arborescence.

 Managing a thread tree without Contexts

Say we have a simple application, made of a main thread and of three subthreads. The

Continue reading →

Quick AES encryption and decryption

For situations when Keybase is not an option. Should work on Ubuntu.

 Generate a AES key

Choose a unique passphrase, <passphrase>.

openssl enc -aes-128-cbc -k <passphrase> -P -md sha1

Keep the iv and key values in the $IV and $KEY environment variables.

 File encryption

Your file is located as file.txt, and will be encrypted as file.txt.enc.

openssl enc -aes-128-cbc -in file.txt -out file.txt.enc -K "$KEY" -iv "$IV"

 File decryption

Your encrypted file is located as file.txt.enc, and will be decrypted as file.txt.dec.

openssl enc -d -aes-128-cbc -in file.txt.enc -out file.txt.dec -K "$KEY" -iv "$IV"

Continue reading →

Create a user with sudo rights - a cheat sheet

Works on Ubuntu, should work on other Debian-based systems.

  • Create the user:

    sudo adduser <name>
  • Add sudo rights without password prompts:

    sudo echo "<name> ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/<name>

    Alternatively, with password prompts:

    sudo echo "<name> ALL=(ALL) ALL:ALL" > /etc/sudoers.d/<name>
  • Create .ssh folder:

    mkdir -p /home/<name>/.ssh
  • Create authorized_keys:

    sudo echo "<public key>" > /home/<name>/.ssh/authorized_keys
  • Set the appropriate permissions:

    chown -R '<name>:<name>' /home/<name>/.ssh
    chmod -R 700 /home/<name>/.ssh
    chmod 644 /home/<name>/.ssh/authorized_keys

Continue reading →

Understanding Cgo a little better

Go is a language that has become popular for a lot of different purposes. It’s being used by back-end developers, who use it to build websites and services ; it’s being used by system engineers, who use it to interact with low-level APIs ; it’s, in general, getting a lot of love for its simplicity and straightforwardness.

One of the features that made Go popular with lower-level developers is Cgo. With Cgo, developers can link their binaries to C libraries - which spares them the expense of having to rewrite specific low-level libraries written in C.
At The Things Network, we use Cgo to interface our own Go-based packet forwarder with the loragw C library written by Semtech, used to exchange packets with a LoRa concentrator. This article is for you if you’re looking for reasons why your Cgo-interfaced program might not work as you expect it to, or if you want to know more on the insides

Continue reading →

Using Govendor to manage your Go dependencies

I started recently using Go for work purposes. It’s a great language! While it doesn’t have the agility of Python or Node scripting, it’s fantastic as a compiled language. It’s easy to pick up and to use, maintainable, and has an active open-source community. By the time I’m writing this post, version 1.8 was just released, introducing deep performance improvements.

This is a small piece for people who’ve started developing with Go. To manage your dependencies, you must’ve quickly noticed that you can either import packages with their name - if it’s a native Go package, such as net, fmt or io - or with their full import path.

 Why would you use Govendor?

Let’s say you’d like to install Cobra, a command management tool, as a dependency to your Go application. You’d get the package in your $GOPATH with go get -u, and then call it in your app:

package main


Continue reading →

Introducing Hapi Web Service

I spent a certain amount of time during the last 14 months working on web services, whether it is RPC-like web services or RESTful WSes. I’ve recently started to work, for the purpose of a services computing class (CS459) here at KAIST, on another web service architecture - written in JavaScript, as part of my experimentations with Node. Hapi had nice features and extensions for building lightweight servers, so I went with this tech to start building it.

However, I realised that although Hapi was built in the objective of serving APIs (even though it can also render templates), several features were lacking to accelerate web services development. Notably, there is no web services description automation, generic error handling, common communication language, access protection…

That’s why I started building Hapi Web Service, that aims at providing an efficient framework for completing

Continue reading →

Useful tips for traveling/first steps in Korea

 General tips

  • No need to withdraw much Korean currency (Won, 전/₩): most of the stores accept debit and credit cards, whatever the amount. It can be useful to plan a bit of currency, for street food stands or taxis, but be careful where you withdraw money: some ATMs don’t work with foreign cards, you’ll have to hunt for “Global ATM”-marked ATMs.

  • If you’re from continental Europe, you won’t need any AC converter. Korean power sockets are a standard CEE outlet.

  • In many temples and indoor places, you might be asked to leave your shoes at the entrance. If you see shoes at the entrance of a public place, ask yourself the question.

  • There’s free Wi-Fi everywhere in Seoul - but if you need a reliable connection, you can get egg Wi-Fi hotspot devices at the airport.

  • If you want to visit the DMZ: don’t miss the JSA, the military camp managed by the UN forces and your only chance of setting a foot

Continue reading →

Maker’s Schedule

The manager’s schedule is for bosses. […] When you use time that way, it’s merely a practical problem to meet with someone. Find an open slot in your schedule, book them, and you’re done. […] [Programmers] generally prefer to use time in units of half a day at least. […]

A meeting commonly blows at least half a day, by breaking up a morning or afternoon. If I know the afternoon is going to be broken up, I’m slightly less likely to start something ambitious in the morning. […]

Maker’s Schedule, Manager’s Schedule, Paul Graham

Continue reading →

Install SoaMLDesigner on a macOS Modelio project

I’ve been trying to install SoaMLDesigner for Modelio on macOS for a few hours now, but I couldn’t find a way to install it on my project. I tried to follow this tutorial to install it, but I didn’t work on macOS: either some menus were missing, or were grayed out… I finally did it by toying around with the configuration files, so here’s how I did it.

  • First, open the ~/.modelio/[version number]/modules/ folder. In this folder, every folder contains a Modelio module - you have to find the one that contains a SoaMLDesigner folder. You can help yourself with the command tree -L 2 if you have tree installed on your computer.

  • Go inside that SoaMLDesigner folder. In the module.xml file, the root DOM element of Module type has an attribute called version (3.5.02 in my case). Copy the value of the attribute. Now, copy also the full address of the file in the folder that has a .jmdac extension

Continue reading →

Thoughts about Docker Compose environments

  • Docker Compose is a useful tool to decouple images and split them into components, to make them easier to read and to maintain.

  • However, Docker Compose environments are best used when the images coupled together don’t need to interact together at a system layer, but only at a network layer.

I’ve had the recent experience of a Node.js project that needed to interact with a Redis database, adding large amounts of data as a single action (between 300 000 and a million inserts). My instinctive thought was to decompose this project into a Node.js project image, and a Redis image, linked together through Compose. Redis has a mass insert protocol, but it is only available as a command-line tool (cat data.txt | redis-cli --pipe) - there’s no network protocol to use it. I’ve thought of a few options, but nothing ideal:

  • Make my own Redis image with an interface (poorly efficient, especially

Continue reading →