Have you been asked a ‘FizzBuzz’ question in a technical interview?

This question popped up in my daily email digest from Quora:

Are there really programmers with computer science degrees who cannot pass the FizzBuzz test?

Ok. I’ve been a professional software developer for 22 years (not including hobbyist coding before graduating and starting work) and I have a Computer Science degree. What is this FizzBuzz test? Now I’m curious. I admit it’s been a while since I’ve been for a job interview, but I’m aware of the current trend to ask interview questions to determine a candidate’s ability to solve problems. ‘FizzBuzz’ refers to a school game where you as a group you take turns in counting, but replace ‘Fizz’ if the current number is divisible by 3, ‘Buzz’ if divisible by ‘5’, or ‘FizzBuzz’ if divisible by both (or something similar, along those lines).

So the interview question is: write code that counts from 1 to 100, and outputs the number, or Fizz, Buzz, or FizzBuzz according to these rules.

The point of the question is not to write the most elegant, or brilliantly clever solution to the problem, the point of the question is to establish whether the interview candidate can write code demonstrating elementary software development concepts such as iteration and boolean logic conditions. If you’ve ever conducted technical interviews before then you won’t be surprised that you will come across candidates who say they have x years of experience in coding in language XYZ, but it’s pretty obvious that they can’t code anything at all. Jeff Atwood commented on this in a post here.

My first attempt at writing this straight up with little thinking, I wrote this:

Once I’d written this, it concerned me that I had the mod 5 test twice, so I tried to optimize the logic to not repeat this test, and my second attempt resulted in code that didn’t write out the correct expected results. I think this is the second part of the point of this question – it’s a puzzle where it appears there should be an elegant solution, but there really isn’t. Gayle McDowell’s answer to this question on Quroa calls this the ‘Smart Person’s Mirage’ – it seems like there should be a smart answer to the question, but there really isn’t.

Other than being lured in to try and answer this question myself since I’d never heard of this before, I guess the lesson here is that it’s not really the answer that counts, it’s how you approach the problem, and the process you take to solve the problem.

mdm crashing after upgrade from Mint 17.3 to Mint 18 (and solution)

I recently upgraded my Mint 17.3 to Mint 18 using mintupgrade and following the instructions here, and unluckily had a powercut while in the middle of the upgrade. When I rebooted, some things had changed, like the logon screen had new background images, and the grub menu now said ‘Mint 18’, but as soon as I logged on, mdm crashed and there was a dialog saying that XWindows had crashed within seconds of starting. The popup dialog said to check ~/.xsession-errors, which contained this error:

initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
syndaemon: no process found

A quick Google found this question with the same error message, and following the suggestion to run ‘sudo apt-get install cinnamon’ fixed my issues. I restarted mdm with ‘sudo service mdm restart’, logged on and eveything was good.

I’m not entirely sure how much of the upgrade completed, so re-running ‘mintupgrade upgrade’ again still prompted for a number of packages to be deleted or upgraded. Completed the upgrade, rebooted, and now everything looks good.

This could have been a lot worse, but luckily was able to recover with no noticeable issues so far. And Mint 18 looks great! (I like the new window animations!)

Docker Swarm node set up with Docker 1.12 RC on Raspberry Pi

I’ve been following through the steps in this article to set up a Docker swarm cluster on a pair of Raspberry Pis. Most of the steps work as-is from Mac OS, but for a few steps there’s a couple of variations.

This is most likely going to be part 1 of a few posts as I work through and get this working.

For example, to copy your ssh key to the Pis, instead of:

ssh-copy-id pirate@pi3.local

… you can do (from tip here):

cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

To switch between remote hosts:

eval $(docker-machine env pi1)

where pi1 is the name of the remote host.

To switch back to the localhost (not entirely obvious but found the answer here):

eval "$(docker-machine env -u)"

After ‘swarm init’ and adding the other nodes to the cluster, ‘docker swarm ls’ lists the nodes in the cluster:

More to come in part 2:-)

Installing kernel headers for Oracle Linux 6 on VirtualBox

The usual reason for Guest Additions failing to install on a Linux guest on Virtual Box is that the kernel headers are missing. How you install these or where they come from varies from distro to distro, although they’re usually available via the package manager on that distro.

I had an Oracle Linux 6 guest installed, Guest Additions (for video drivers, shared folder, clipboard sharing) was all working, and then at some point I started it up again and it was no longer working and wouldn’t re-install either. Seems like I’d picked up an update, and I needed to update the kernel headers too.

This post covers the steps needed. On OE6 before installing the Guest Additions, just run ‘yum install kernel-uek-devel’ and you should be good to go (assuming you’re booting with the ‘unbreakable kernel’ and not the RHEL compatible kernel)

Configuring a static IP on HypriotOS for the Raspberry Pi

How you configure a static IP on the Pi changed between Wheezy and Jessie, and it seems on Hypriot’s prebuilt images for running Docker on the Pi, it’s a slight variation.

Edit /etc/network/interfaces.d/eth0, comment out the DHCP line:

iface eth0 inet dhcp

and add:

iface eth0 inet static
address your-static-ip
gateway your-gateway-ip
#google dns servers


Docker 1.12 RC on the Raspberry Pi

If you’re excited about playing with the swarm mode in the new 1.12 version of Docker, you can download the release candidates for Linux, Windows, Mac, but it’s not obvious where you can get an ARM compatible version to run on the Raspberry Pi.

The awesome guys over at Hypriot talk about running the 1.12 RC on the Pi, but their prebuilt OS images for the Pi don’t yet include the 1.12 RC version. I found this blog post however, which mentions a download location where you can pick up a .deb file and install it on the Pi with dpkg.

Downloaded, installed on my “to be” Pi cluster of 2 Pis, and up and running! Now to deploy something with swarm 🙂

Mac Docker 1.12.0-rc3-beta18 native client and insecure registry

A while back I set up a local Docker Registry to share images between different machines, and configured it as an ‘insecure registry’ since it’s just for testing. With the latest native Docker engine for Mac OS, I was having difficulty pushing to the Registry, it was just fail with a cryptic message:

$ docker push

The push refers to a repository []

Get http: server gave HTTP response to HTTPS client

I noticed in the Docker menu from the menu bar that there’s a Insecure Registries section under Preferences, Advanced Options. Adding the IP and port of my Registry there fixed my problem, now I can push:

$ docker push

The push refers to a repository []

3d4f4a09f67b: Pushed 

fc91d495516f: Pushed 

5f70bf18a086: Pushed 

532820a7256b: Pushed 

ed62ae893def: Pushed 

994d5442545b: Pushed 

f097d343f850: Pushed 

latest: digest: sha256:c71c6743924243d6117050a1b5b95adf4effee7c9059315c0bfe500f67e0d16b size: 260

Windows History: DOS vs NT sourcecode heritage

As a software developer, I’m fascinated by computer and IT history. I grew up with 8 bit home computers like the Sinclair ZX Spectrum, and developed my first applications in Sinclair BASIC which most likely kickstarted my interest in software development.

I find it interesting when developers have very little interest or knowledge in even recent history of the tools and platforms that they work with every day. For example, statements like “I’m glad Windows 10 no longer has any dependence on MS-DOS like Windows 8 did”, or “Microsoft completely developed Windows 10 from scratch, you know”, – neither statements which could be further from the truth.

Up until Windows XP, Windows was developed as two parallel code lines, the MS-DOS based code line, Windows 1.x through 3.x, 95, 98, and ME, (95, 98 and ME aimed at home consumers) and the Windows NT code line for enterprise users. After Windows ME, Windows XP was developed based on the NT kernel from Windows 2000, with some features taken from ME and it’s MS-DOS code line.

There’s a great history of the parallel code lines in this article on the History of Microsoft Windows on Wikipedia, and clearly illustrated in this diagram:

(From https://en.wikipedia.org/wiki/Timeline_of_Microsoft_Windows, shared under Creative Commons Attribution-Share Alike 3.0 Unported license).

Windows ME was the last release of the MS-DOS based Windows code line, and Windows 10 is the next release in the Windows NT code line, which as you can see from the timeline above, shares it’s heritage with 8, 7 and Vista before it.

Running gpsd on a Raspberry Pi 3 over UART

Adafruit have a great tutorial for connecting and setting up their GPS Shield on the Pi. To connect it direct to the tx/tx GPIO pins on the Pi (instead of USB), there’s some additional steps covered here. Since the Pi 3 uses it’s hardware serial with the onboard Bluetooth, there’s additional steps covered that are Pi 3 specific.

After following those steps however, runnning cgps would run for a second and quit, with ‘No Fix’. What’s odd was that doing a ‘cat /dev/ttyS0′ would show the GPS NMEA messages being received, so I could tell the GPS board was up and receiving, but something else was not right.

Instead of starting gpsd as a daemon, running it form the commandline with additional debugging options gave some additional clues:

pi@raspberrypi:~ $ sudo gpsd /dev/ttyS0 -n -N -D3 -F /var/run/gpsd.sock

gpsd:INFO: launching (Version 3.11)

gpsd:ERROR: can’t bind to IPv4 port gpsd, Address already in use

gpsd:ERROR: maybe gpsd is already running!

gpsd:ERROR: can’t bind to IPv6 port gpsd, Address already in use

gpsd:ERROR: maybe gpsd is already running!

gpsd:INFO: command sockets creation failed, netlib errors -1, -1

This thread has others with the same issue. There are some suggestions towards the end of the thread to edit /lib/systemd/system/gpsd.socket and change some values, but the one recommendation that worked for me was to use this to start the service:

sudo service gpsd start

and then running cgps connected to the gpsd daemon, and everything is good!