How to find out compiler version of a go binary

If you have a binary that was produced by a golang compiler, and you want to find out which version of the compiler was used, you can use use the C debugger gdb as follows:

$ gdb /path/to/binary
[...]
(gdb) p 'runtime.buildVersion'
$1 = 0x5e1d83 "go1.9"
Advertisements

Generate an SSH public key

If all you have is an SSH private key and you need to generate a public key out of it, you can run the following:

ssh-keygen -y -f yoursshkey

It will spit out the public key on the standard output.

Raspberry Pi: attach a serial console

For a Raspberry Pi with GPIO pins (B, B+, 2, 3):

  1. Connect as follows:
  2. Append this line at the end of /boot/config.txt:
    enable_uart=1
  3. Access the console from your workstation like this:
    sudo screen /dev/ttyUSB0 115200

Sources:

For Raspberry Pi without pins (Pi Zero, Pi Zero W):

  1. Add the following line at the end of /boot/config.txt:
    dtoverlay=dwc2
  2. Insert the following between ‘rootwait‘ and ‘quiet‘ in /boot/cmdline.txt:
    modules-load=dwc2,g_serial
  3. Mount the linux part of the Pi SD card and add the following lines at the end of /etc/rc.local, before ‘exit 0’:
    usbconsole="getty@ttyGS0.service"
    if [ ! $(systemctl is-enabled "${usbconsole}") ]
    then
    echo "Enabling and starting ttyGS0 console..."
    systemctl enable "${usbconsole}"
    systemctl start "${usbconsole}"
    fi
  4. Connect a micro usb cable into the socket market ‘USB‘ on the Pi, not the one marked ‘PWR’.
  5. On your workstation, console can be accessed as:
    sudo screen /dev/ttyACM0 115200

Sources:

git: list all files in a commit

To list all the files tracked a commit, run this:

git ls-tree --full-tree -r <hash>

If you’re only interested in the names:

git ls-tree --full-tree -r --name-only <hash>

Helpmate in 1

A helpmate is a problem where a mate is possible with the help of the color that is defending. Here a nice example of a helpmate in 1:

Solution is here:

Learning go

I have started to learn go, Google’s system language. I really like it. I appreciate these features in particular:

  1. It is truly cross-platform, in par with java
  2. It has a huge standard library, again like java’s but without the GUI stuff
  3. It compiles to standalone executables that include the runtime! Imagine a JAR file that would carry a little JVM with it. No need to “install go” on a deployment machine!

In terms of design, it takes a little bit of time to get used to. But on the whole it is fairly easy and straightforward. I have a good knowledge of C, java, lua and bash and I had no problem to adapt to go.

Highly recommended!

How to build Xerial’s sqlite JDBC driver on Alpine Linux

These are the steps I took to build the sqlite JDBC driver so that it works on a musl-based Linux distro, namely Alpine Linux.

  1. Install a couple of dependencies:
    # apk update && apk upgrade
    # apk add git gcc make openjdk8 maven
    # apk add perl curl unzip bash musl-dev
  2. Set up JAVA_HOME:
    # export JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
  3. Clone sqlite-jdbc repository:
    # git clone https://github.com/xerial/sqlite-jdbc.git
  4. Build the shared object library and the JNI bindings:
    # cd sqlite-jdbc
    # make jni-header native
  5. Build the JAR (some tests don’t pass, you have to skip them):
    # mvn -Dmaven.test.skip=true package
  6. The jar that is produced is in the target directory:
    # ls target/sqlite-jdbc*
    target/sqlite-jdbc-3.16.2-SNAPSHOT.jar
  7. To use it in a gradle build, mkdir a lib directory in your gradle project, copy into it the jar that was built as above and add the following compile line to build.gradle:
    compile fileTree(dir: 'lib', include: '**/*.jar')