proof-of-work based blockchain explained with golang

Yet another “blockchain explained” article, I know, I really thought about if releasing it or not, but you know, you only understand what you can explain clearly, so I hope I’ll be able to explain proof of work and blockchain as clearly as it is clear in my mind.
The originality of this post is that I’ll try to make those concepts clear through pieces of code extensively explained so it doesn’t feel like a theoretical expose where you get the idea without the taste.

Replacing a (silently) failing disk in a ZFS pool

Maybe I can’t read, but I have the feeling that official documentations explain every single corner case for a given tool, except the one you will actually need. My today’s struggle: replacing a disk within a FreeBSD ZFS pool.

What? there’s a shitton of docs on this topic! Are you stupid?

I don’t know, maybe. Yet none covered the process in a simple, straight and complete manner. Here’s the story:

golang reflection tips

Because I’m the kind of person who likes genericity, I often find myself using features of languages that are flagged as “only use it if you know what you’re doing”. Golang reflection is one of those features, powerful yet a bit confusing.

Reflection, as explained in The Laws of Reflection is the ability of a program to examine its own structure, particularly through types; it’s a form of metaprogramming

In short, you can introspect variables at run-time, making your program exceptionally dynamic. How can this serve any purpose? well imagine for example creating function names dynamically by another function parameter. Pretty cool uh?

Cleaner micro Kubernetes on OSX

While my main workstation is a Linux Mint machine, I occasionally use my OSX ${WORK} laptop for traveling and composing. I’m not really fond of the OS, but at least it’s an UNIX-like, and pkgin runs well with it ;)
When I’m “on the go”, I like to try things and play along with technologies I’m currently obsessed with, among them Kubernetes.
On OSX, the natural choice is to go with minikube, it’s kind of integrated and does the job well, but if you tried it already and also happen to run docker for OSX you might have found yourself struggling with versions and consistency between the two. Added to this that I wanted to have a fully functional Linux virtual machine, preferably Debian GNU/Linux, there was way too much inconsistencies and wasted disk and CPU space to come. So I dug by myself and found a clean and fast solution by spawning my own virtual machine using OSX native hypervisor, which runs Canonical’s microk8s, a nicely done snap package to install a fully working and modular Kubernetes cluster on a Linux machine.

Understanding golang channel range

Here we go again with my golang self teaching, today with a topic I had hard time understanding correctly (and hope I actually did): range over channels along with goroutines.

First of all, let’s have a little reminder. We all know a goroutine live its own life and must be waited for at the main level, i.e. in this example:

package main

import "fmt"

func main() {
	go func() {
		fmt.Println("hello there")
	}()
}

run me on playground

Golang interfaces, a pragmatic explanation for the programmer

I’m still in the process of learning golang the right way. Yes I already wrote some projects with the Go language (here and here), but I like to understand the real meaning of techniques when using them.
One of what is said to be the most amazing features of Go is interfaces. Here’s what the official golang docs has to say about it:

Interfaces in Go provide a way to specify the behavior of an object: if something can do this, then it can be used here. We’ve seen a couple of simple examples already; custom printers can be implemented by a String method while Fprintf can generate output to anything with a Write method. Interfaces with only one or two methods are common in Go code, and are usually given a name derived from the method, such as io.Writer for something that implements Write.

An Elasticsearch from the past

Here’s a procedure I came up with in order to migrate an elasticsearch 1.1 database to version 6 (actually 6.4 but probably any 6.x version).

  1. Fire up a temporary elasticsearch version 1.1

Fetch the tar.gz version from https://www.elastic.co/downloads/past-releases/filebeat-1-1-2 and untar it.

Use the following basic configuration file

$ egrep -v '^[[:space:]]*(#|$)' ~/tmp/elasticsearch-1.1.2/config/elasticsearch.yml 
http.port: 9202
transport.tcp.port: 9302
path.conf: /home/imil/tmp/elasticsearch-1.1.2/config
path.data: /var/db/elasticsearch

Note that I changed the standard ports to $((standard_port + 2)).

From the untarred directory, lauch elasticsearch

OpenVPN routes dynamic NATting

Assume the following scenario: your {Open,Free}BSD pf-enabled (yes, I know what’s missing and it’s a pity, I am well aware of it) gateway connects to an OpenVPN server. This server pushes a couple of routes to your gateway that you’d like to be able to reach from within your own private network. As routers on the other end don’t have routes to your network(s), mandatory NAT is to be configured, but let’s also assume those routes are subject to change, and there’s more than a couple of them, some kind of dynamic rule adding should be considered.

From GitLab CI to Docker Hub

With all the noise around those topics I would have imagined this one had been covered thousands of time, yet I did not find a single complete resource on this subject which I found to be a basic building block: pushing docker images from GitLab CI to the Docker Hub registry.

There’s actually an opened issue on Docker GitHub’s that’s sitting there for 3 years, and it really feels more like a political / strategic / commercial issue than a technical one. Point being, there’s no straightforward integration between GitLab.com and Docker Hub.

Kubernetes under my desk

I’m diving into Kubernetes for a couple of months now. Discovering the possibilities and philosophy behind the hype definitely changed my mind. Yes, it is huge (in every sense ;) ) and it does change the way we, ex-sysops / ops / syasdmins do our work. Not tomorrow, not soon, now.

I’ve had my hands on various managed kubernetes clusters like GKE (Google Container Engine), EKS (AWS Elastic Container Service) or the more humble minikube but I’m not happy when I don’t understand what a technology is made of. So I googled and googled (yeah sorry Qwant and duckduckgo I needed actual answers), until I found >many >incredibly >useful resources.