Kasper Grubbe

Read this first

Running and installing Ruby in parallel using Rbenv with flock and Buildkite

I am maintaining a few Docker-images that contains all supported versions of Ruby, and they also ship with Jemalloc.

Because I use Buildkite, it is very easy for me to test multiple versions at the same time, but they all run the same setup script:

echo "--- setup rbenv"
source ~/.bash_profile

echo "--- setup ruby"
rbenv local 2.7.7 || rbenv install 2.7.7 && rbenv local 2.7.7

echo "--- bundle setup"
gem query --silent --installed --exact bundler || gem install bundler

echo "--- tests"
ruby tools/test.rb 3.1

This fails for some reason when multiple agents of Buildkite run in parallel, I don’t know if Rbenv or Rubygems gives any guarantees for this sort of usage, but nevertheless it fails.

Instead of digging into the intricacies of Rbenv and Rubygems we could make sure that the code above are only being executed by one agent at a time, we can do this with flock:

exec
...

Continue reading →


Optimizing bicycling routes with OpenStreetMap and APIs

(There’s a video version of this article available here, where we also do a deep dive into the code behind it, remember to turn on subtitles):

I’ve started playing with data from OpenStreetMap (OSM). It started with me trying to fetch all the places where I could get free water when moving around Copenhagen, which turned out to be a daunting task, because OSM seems to have a lot of different ways to categorise available water. I’ve identified the following tags to look out for:

Tag Documentation amenity=drinking_water https://wiki.openstreetmap.org/wiki/Tag:amenity%3Ddrinking_water man_made=water_tap https://wiki.openstreetmap.org/wiki/Tag:man_made%3Dwater_tap amenity=water_point https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dwater_point drinking_water=* https://wiki.openstreetmap.org/wiki/Key:drinking_water

Contributing back to OpenStreetMap

I soon became...

Continue reading →


How to use Haproxy redis-check with a password

It seems like option redis-check in Haproxy does not support Redis-databases that requires authentication as of 1.9.6 (newest version).

That means that if you want to check the health of password protected redis-servers, you would have to use a tcp-check, so you will have to modify your check like this:

listen redisserver
  bind *:6380
  mode tcp
  server redis_backend someredisserver:11020

  option redis-check

to:

listen redisserver
  bind *:6380
  mode tcp
  server redis_backend someredisserver:11020

  option tcp-check
  tcp-check send AUTH\ aveeeeeryseeeecretpassword\r\n
  tcp-check expect string +OK
  tcp-check send PING\r\n
  tcp-check expect string +PONG

View →


Rick-rolling people looking for free WiFi using an inexpensive ESP8266-chip

(If you are here because you were tricked, you can throw some words my way on rickroll@kaspergrubbe.com or by sending a tweet to @kaspergrubbe)

I found a project on Github named mobile-rr, by a user called idolpx. His project includes a little wifi-chip that includes a piezo buzzer, and when people connect they are promised free wifi, but instead of getting access to the internet, they are shown a video of Rick Astley singing “Never gonna give you up”.

This is a so called Rickrolling prank, and if you have been living under a rock the past decade, the prank involves bait-and-switch where a link on a webpage promises to bring the user to some unrelated material, and bam! they are now listening to the tunes of Rick Astley and they can consider themselves rickrolled.

The original project only beeped when a person was tricked, and if you wanted to know the score, you had to connect to...

Continue reading →


Protecting services with client certificates using Haproxy

What we want to achieve

We want to be able to connect to services inside a private network using client certificates, in this example we will be connecting to Redis.

haproxy-client-certs-overview.png

Install or compile Haproxy

I am using Debian, so this is what I use to compile Haproxy for testing out this setup.

apt-get -y install make gcc g++ libssl-dev

wget http://www.haproxy.org/download/1.8/src/haproxy-1.8.4.tar.gz
tar xzf haproxy-1.8.4.tar.gz
cd haproxy-1.8.4
make TARGET=generic USE_OPENSSL=1
make install PREFIX=/usr/local

Install and configure firewall

I am testing with a Redis-server, but it can be anything. First firewall off everything except for port 22 (ssh) and port 88 (our external redis port):

apt-get -y install ufw

ufw default deny incoming
ufw default allow outgoing
ufw allow 22
ufw allow 88

Install Redis

apt-get -y install redis-server

Since Debian and Debian-related distros have the...

Continue reading →


How to backup your Betaflight configuration between upgrades

Sometimes you will need to upgrade the Betaflight firmware on your quadcopter, normally this process wipes all your settings, and you will have to fill all of them in again.

  • You can use diff in the Betaflight CLI to see which changes you have made that differs from the default settings.
  • diff all includes all 3 PID profiles.
  • You can then take the output and save it into a text-file
  • Upgrade the firmware.
  • Paste the settings from you textfile into the CLI again, type save.
  • Please read the changelog, maybe something have changed!
  • Go fly, have fun!

View →


How to invert motor rotation with Betaflight and Blheli

  • Take your propellers OFF!!!
  • In Blheli invert the motor rotation.
  • In Betaflight go to the console and type: set yaw_motor_direction = -1 followed by a save command.
  • Go back into the CLI and run get yaw_motor_direction to make sure your value is saved, you want to see -1.
  • Now verify your configuration by going to the motors tab, providing power, and spinning each motor up individually.
  • Remember to test it out slow when you take your quadcopter to the field.

View →


No Christmas presents for me, please!

I am quite content and grateful for what I have, and if I really want something it is either way too expensive to ask for, or I would buy it when I need it.

If you really want to give something, invite me for a home-cooked meal, buy me a beer, donate to something you feel is nice (and if you’re still lost, or need a recommendation, donate to the EFF or the homeless), or use the money on better presents for others.

View →


Connect to X-RACER F303 with Cleanflight/Betaflight on OSX

By default Cleanflight is not able to identify the flight controller when plugged in with USB.

But you can install the USBtoUARTBridge driver from SiLabs, and it will be able to connect just fine, you can find it here: https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspxmac

And you will then be able to find your model as /dev/cu.SLAB_USBtoUART in the menu:

screenie_1472160040_887212.png

View →


Easier installation of NixOS on Linode

The guide from the official wiki on how to install NixOS at Linode is very manual, and that can get a bit time consuming if you have to do it a lot of times.

I have therefore made a script that does the same, but is more automated.

nixos-hires.png

1. Create a new instance

Press the Add a Linode link in the interface.

2. Add a disk

Press Create a new Disk in the interface, give it a name, for an example nixdisk, type=ext4, size=maximum. Click the create button.

3. Boot Finnix

Click the tab named Rescue, and click the button saying Reboot into Rescue Mode.

4. Get remote access

Click the tab named Remote Access, and click Launch Lish Console, you will get a popup that looks like this:

screenie_1467214794_495297.png

5. Run install script

I have a script hosted on Github here: https://gist.github.com/kaspergrubbe/b42e5e1ccd276fea8d99e4865f0bcb21

I had to ignore certificates, because the version of Finnix Linode uses...

Continue reading →