The basics of Logarithms – with examples

Logarithms are widely used in computer science (e.g. for algorithm analyses, floating point number limitations, scaling data, feature transformations). Not coming from a mathematics background (I don’t!) logarithms can seem confusing at first. Let’s look at the very basics of logarithms to get an understanding of how they can be broken apart, some of the properties that can be utilized, and why they work. What is a Logarithm? $$\log_{b}(x)$$The logarithm is defined as the inverse operation to exponentiation. To get the logarithm of a number, we need to find out, to what exponent another number, called the base, needs to be raised to produce that first number. ...

February 6, 2018 · David Hamann

Using vi commands in your bash shell

Entering a long shell command and then moving the cursor around to correct parts of it always felt a bit clunky to me. I remembered some of the <ctrl>/<alt> key bindings but would often just end up using arrow keys or alt-click to navigate to a certain position. Today I learned that you can easily get a vi-style command line interface in bash, giving you insert and normal mode and allowing you to use a basic subset of vi commands. ...

January 28, 2018 · David Hamann

Count elementwise matches for two NumPy arrays

Let’s say we have two integer NumPy arrays and want to count the number of elementwise matches. Here are our two arrays (NumPy imported as np): >>> a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> b = np.array([1, 2, 2, 2, 5, 6, 7, 9, 9]) To create a third (boolean) array that contains True for a match, and False otherwise, we can use the equality operator. >>> a == b array([ True, True, False, False, True, True, True, False, True]) Given that, counting the number of matches is as easy as: >>> np.count_nonzero(a==b) 6 (Another option would be to use the (slower) np.sum(a==b))

January 26, 2018 · David Hamann

Basic understanding of IPv4 addresses

In a recent project I needed to anonymize IP addresses in tracking data. While masking a few bits from an IP address is not so interesting, it’s a good excuse to review some of the basics of how (IPv4) IP addresses work. What’s an IP address and how does it look like? To be able to route traffic through a network (e.g. your local network or the internet), we need a way to uniquely identify devices on that network, i.e. we need addresses. ...

January 22, 2018 · David Hamann

VPN: Temporarily solve same subnet conflicts

I recently had the problem of needing to establish a connection to a server behind a VPN that was in the same subnet as the network I was connecting from. Every call I wanted to make to the server on the remote network wouldn’t go through as it was looking for the server on the local network. To eventually reach the server, I temporarily added a route to the routing tables, telling the client it should transmit traffic to the destination ip through the interface of the VPN connection. ...

September 27, 2017 · David Hamann