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

Running Flask on macOS with mod_wsgi/wsgi-express

Flask is a (micro) web development Framework for Python. It is fairly simple to get started. All you need to do is to pip install Flask into your virtualenv, give the FLASK_APP environment variable your file and run flask run (described in detail in installation and quick start). This will launch the development server and you can instantly start hacking around. When you want to use your Apache webserver, however, you need to install and configure a WSGI module. When I first wanted to do this I tried to install mod_wsgi via brew (brew install mod_wsgi from the homebrew/apache tap), but quickly ran into some (apparently common) issues with the XCode toolchain. Then I discovered that there is a much easier way of installing mod_wsgi as a Python package. ...

August 5, 2017 · David Hamann

SQL: Get the count of related records

Micro tutorial: Sometimes you need to show results from table A but also include the count of related records from table B. For example: how many items are in each purchase order, how many comments in each post, how many galaxies in each universe (wait, what?), … The following query shows one way of selecting the title and id from a table Posts, the count of the related records in a table Comments and then sorts descending by that count. fk_post is the foreign key of the post in the Comments table. ...

July 11, 2017 · David Hamann

Pandas: Select rows that match a string

Micro tutorial: Select rows of a Pandas DataFrame that match a (partial) string. import pandas as pd #create sample data data = {'model': ['Lisa', 'Lisa 2', 'Macintosh 128K', 'Macintosh 512K'], 'launched': [1983,1984,1984,1984], 'discontinued': [1986, 1985, 1984, 1986]} df = pd.DataFrame(data, columns = ['model', 'launched', 'discontinued']) df model launched discontinued 0 Lisa 1983 1986 1 Lisa 2 1984 1985 2 Macintosh 128K 1984 1984 3 Macintosh 512K 1984 1986 We want to select all rows where the column ‘model’ starts with the string ‘Mac’. df[df['model'].str.match('Mac')] model launched discontinued 2 Macintosh 128K 1984 1984 3 Macintosh 512K 1984 1986 We can also search less strict for all rows where the column ‘model’ contains the string ‘ac’ (note the difference: contains vs. match). ...

June 26, 2017 · David Hamann

LaTeX mathematics cheat sheet

LaTeX is the de facto standard typesetting system for scientific writing. A lot of the nice looking equations you see in books and all around the web are written using LaTeX commands. Knowing a few of the mathematics commands is not only helpful if you want to write a book or an article (or do some extreme stuff), but can come in handy in a lot of places, as many systems support LaTeX. You can use LaTeX in MathJax to display expressions on the web (like here), you can make yourself good looking mathematics flashcards in Anki, you can even nerd out and send formulas built with LaTeX commands to your friends via an iMessage app. Also, Apple’s latest Pages release now supports LaTeX equations. ...

June 12, 2017 · David Hamann