Compiling OpenVPN on the Raspberry Pi 3

- 1 min read

Recently I needed to upgrade the version of OpenVPN on my Raspberry Pi 3 Model B. Below are the steps needed to do this, here we upgrade to OpenVPN version 2.4.8.

$ cd /tmp
$ wget https://swupdate.openvpn.org/community/releases/openvpn-2.4.8.tar.gz
$ tar xf openvpn-2.4.8.tar.gz
$ cd openvpn-2.4.8/
$ sudo apt-get install libssl-dev
$ sudo apt-get install liblzo2-dev
$ sudo apt-get install libpam0g-dev
$ ./configure --prefix=/usr
$ sudo make
$ sudo make install

Verify that the new version installed:

Styling Markers on Mapbox Static Maps

- 1 min read

Recently I was using the python map-box api to generate static maps. I needed to style the markers which pin pointed locations on the map. I found it difficult to find the necessary documentation on how to do this. In the end it simply involved adding the following fields:

  • maker-colour (hex value).
  • marker-symbol (Maki icon name. an integer, or a lowercase letter).
  • marker-size (small, large).

To the JSON like so:

Ignoring Directories When Backing up with Borg

- 1 min read

Borg backup has a --exclude-if-present flag, which allows you to ignore a directory from being backed up, If it contains a certain ’tag’ file.

So given the following directory structure, which we want to back up:

+ MyFiles
	+ dirA
		- file_one.pdf
		- file_two.pdf
	+ dirB
		- spreadsheet.xsl
		- image.png

If we want to ignore dirB from being backed up by borg, we have to create a tag file in that directory:

Tar Archiving Using Relative Paths

- 1 min read

If you want to archive a directory (using the tar command), but not include the absolute path to the directory. You can use the -C option to the tar command, which essentially cd’s into the directory and then archives it. Here is an example:

$ tar czf /tmp/my_backup.tar.gz -C ~/home/coorp/my_files

When un-archived, the directory structure will be:

  • /some_path/my_files

And not:

  • /some_path/home/coorp/my_files.

Fin.

Make 'echo %PATH' More Readable

- 1 min read

When you want to check the contents of your $PATH variable. To see which directories are in your session, you run the command:

$ echo $PATH

Output:

/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/local/sbin:/opt:/usr/local/go/bin:/usr/local/texlive/2015basic/bin/x86_64-darwin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/sbin:/opt:/usr/local/go/bin:/usr/local/texlive/2015basic/bin/x86_64-darwin

This is all well and good, but the output of the command can be hard to read if you have many directories in your path. What you want is a command that outputs the $PATH variable in an easier to read format. Luckily, this can accomplished with a little bit of bash code:

Piping Commands into Go Binaries

- 2 mins read

In this post we will see how we can pipe commands into our Go applications. We will write a basic command line program which demonstrates the functionality. Before we get started, it’s worth going over the basics of piping commands.

The modular nature of the UNIX operating system. Allows the user to use basic commands to build up new commands. By allowing the output of one command to be used as the input for the next command. The general form of the pipe command is:

The Go sync.Pool type stores temporary objects, and provides get and put methods. Allowing you to cache allocated but unused items for later reuse. And relieving pressure on the garbage collector.

The purpose of the sync.Pool type is to reuse memory between garbage collections. Which is why sync.Pool is drained during garbage collection (GC).

Here is an example of how to use the sync pool:

package main

import (
	"bytes"
	"fmt"
	"sync"
)

var bufPool = sync.Pool{
	New: func() interface{} {
		return new(bytes.Buffer)
	},
}

func main() {
	b := bufPool.Get().(*bytes.Buffer)
	b.WriteString("What is past is prologue.")
	bufPool.Put(b)
	b = bufPool.Get().(*bytes.Buffer)
	fmt.Println(b.String())
}

Output:

Access Raspberry Pi Externally using ngrok

- 3 mins read

In this blog post we will set up our Raspberry Pi so it will accessed using SSH from outside our home network. Below is a diagram of the architecture:

[ Home Network : Raspberry Pi ] <– [ ngrok ] –> [ External Network ]

From our home network we will create a secure tunnel, through ngrok. Which we will then connect to from our external network. This will allow us to SSH into our Raspberry Pi, and manage it.

Raspberry Pi Slow SSH Fix

- 1 min read

If you SSH into your Raspberry Pi and have noticed a lag when typing characters into the terminal. Then the following fix may get rid of the lag (it worked for me!).

Log into your Raspberry Pi and type:

$ sudo nano /etc/ssh/sshd_config

At the bottom of the config file add:

UseDns no

Save the file, then restart sshd:

$ service ssh restart

Or better, reboot your Raspberry Pi:

$ sudo reboot

SSH’ing into your Raspberry Pi should no longer be slow after these steps. 🤞

Runtime and User Level Panics in Go

- 2 mins read

How can our application code detect the difference between a runtime panic and a user level panic? Before answering this question. Let’s take a look at the difference between a runtime panic, and user level panic.

A runtime panic is one thrown by the Go runtime, there are many things that can trigger a runtime panic. An example of the the most common runtime panic would be attempting to index an array out of bounds. The Go runtime would detect the illegal access and call the built-in panic function.