Codility - BinaryGap

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps.

Automatic starting and stopping of AWS EC2 instances with Lambda and CloudWatch

I needed to figure out a way to start/stop instances automatically during certain periods. The obvious way is Lambda, but how to do it. We wanted some instances to run from Monday to Friday, and to start at 7am and stop at 5pm.

Luckily there is a library that abstracts everything you need for starting and stopping your instances. And coupled with Lambda and CloudWatch we can easily accomplish what we want.

Compressing multiple files or directories with XZ and TAR

XZ is one of the best compression tools I’ve seen, it’s compressed files so big to a fraction of their size. I’ve had an 16 GB SQL dump, and it managed to compress it down to 263 MB.

I’ve needed to compress several files using XZ. And as XZ compresses single files we are gonna have to use TAR to do it

Tracking versions in Go

Some of my services were written in Go, and we wanted a way to track which version was used, so we can track and solve issues. Or even see when the application was deployed or from which source was built. The code is on git, so adding a git commit hash to the mix will make our problem easier. Luckily go provides us with a simple way of doing this.

Dropping all databases in a MongoDB

I needed to drop all the databases or based on a filter in MongoDB.

Dropping all collections in a MongoDB database

I needed to drop all the collections in a database without dropping the database.