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.
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.
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.
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.
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.
- Allow templates to access the “get_url” function
- Create an endpoint to serve your own static pages yourself
I had posted about a recursive maze solver earlier. This is an iterative solution to that problem.
This was… not straightforward. There’s a couple of Python modules out there for this. I ended up using
sqlalchemy. I needed to edit some files in
/usr/local/etc, and then symlink them to