You might need to install a fair bit of stuff,
sudo apt-get install unixodbc unixodbc-dev tdsodbc freetds-dev freetds-bin -y
There’s a neat trick you can do to automatically configure FreeTDS on you Ubuntu machine (discussion here: https://gist.github.com/rduplain/1293636)
sudo dpkg-reconfigure tdsodbc
This will write data to
/etc/odbcinst.ini for you. This file configures which drivers FreeTDS will use. You could write this by hand, but this operation reduces the risk for error.
I was trying to access a remote server using
pyodbc and I was providing a connection string like,
conn = pyodbc.connection('DSN=<dsn>;UID=john.doe;PWD=<password>')
For some reason, I wasn’t able to connect at all. It turns out that I needed to put a space after
UID… it’s weird, but it worked. Maybe this is because there was a dot in my UID? I’m not sure. You can also set the UID and PWD in
/etc/obcd.ini, but that’s probably not ideal.
If you’re stuck, you can list the connections on a given host with this,
tsql -H <host> -L
You’ll probably need to install tsql, which I think is located in the
freetds-bin package listed above.
Today I worked out an example of using InfluxDB from Django in Docker. Using Docker containers to run databases greatly reduces the amount of database configuration you need to worry about when you’re trying to work out a proof of concept.
InfluxDB is a great tool for storing timestamped data. Storing a timestamp and a set of measurements, one timestamp per row, in a Postgres database is possible, but inefficient. InfluxDB offers you a way to store a set of values, and a set of indexed meta-data tags per row.
For example, if you’re collecting hourly production data from multiple wells, you can store the rates as data values, and wells as indexed tags. Then looking up the production from a set of wells over some time period becomes very efficient due to indexing. Looking up wells by production rates, however, would be very inefficient, unless you stored rate data as a tag, and well names as values. Learn more here from the InfluxDB documentation.
Continue reading Using InfluxDB with Django and Docker
In a previous post I deployed a Flask app with Docker. This time around I wanted to see if it was any different to host a Django app. It turns out that it wasn’t that much different.
Continue reading Deploy a Django App with Docker
I thought I’d show some examples of solving some common statistical word problems using Python. Today I’ll look at exponential random variables; this is a continuous random variable used to model the waiting time between independent events. Sometimes this is posed as the waiting time for the first event in a Poisson process.
Continue reading Exponential Random Variable Examples
I think that using
make in Python development is a fantastic idea. Reproducing someone’s work is difficult, and using Makefiles minimizes that guesswork. I created a simple Makefile for a Docker project from a previous post
Continue reading Create a Makefile for Docker
I wanted to understand how to host a simple Flask app inside a Docker container, so I went through the following exercise. In the future, I would use something more like the tiangolo/uwsgi-nginx-flask docker image.
Continue reading Deploy a Flask App with Docker
A co-worker was interested in segmenting a list of data points, and I went down a rabbit hole on one dimensional segmentation. I found an article on the Jenk’s natural breaks optimization on Wikipedia. I found another article that had some examples. This is used to bin data points so that clusters are always binned together. There is an iterative method that takes unordered data, but this implementation just sorts the data before binning.
Continue reading Jenk’s Natural Breaks Optimization
For a while I’ve wanted to work on a typed spreadsheet application. This weekend I started working on an interpreter for it using David Beazley’s PLY. So far, this is able to store data and type information in cells in a data store, and perform operations using numbers or references to cells. It also supports limited type checking.
Continue reading Writing an Interpreter in Python with PLY
This technique is known by several names: ports and adapters, hexagonal architecture, layered architecture, onion model, or (most boringly) dependency injection. The main idea is that you separate your business logic from your storage and from your presentation etc. so that you can easily swap out any single piece without refactoring all of your code. I originally read about this on Robert Martin’s site.
Here, I present a simple notes app using dependency injection for the storage and output. Right now I’m using TinyDB for storage, and presenting output to the terminal as a formatted string, or as JSON.
The first two abstract classes
Output_Adapter define the general form what a database or output mechanism should have or provide. Next, we subclass these adapters into concrete classes that can pull data from an actual database, or present output in different ways. At the end of it all, when we instantiate the Notebook class, we pass if the database and output adapters that it will use in order to do its job. At this point, all of its dependencies have been provided (or injected) and it is free to focus on business logic, like managing permissions, spam filtering, or whatever.
Continue reading Ports and Adapters Pattern Example in Python
- Allow templates to access the “get_url” function
- Create an endpoint to serve your own static pages yourself
Continue reading Getting Started with Bottle