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.
Category Archives: Uncategorized
Compile a PDF from PNGs
I keep forgetting how to do this:
brew install imagemagick convert out/*.png out.pdf
Notes on Elixir
I’m reading Programming Elixir 1.3 by Dave Thomas. I’ve compiled some notes on Elixir here for personal reference. Elixir is basically a Ruby-ish wrapper around Erlang, a language developed at Ericsson in the 1980’s. Erlang is known for being extremely reliable, and concurrent.
Addition With Bit Operations
This adds integers using bit-wise operations. I tried to provide a lot of print statements so that you could see what’s going on with each step.
Jenk’s Natural Breaks Optimization
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.
Writing an Interpreter in Python with PLY
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.
Use Alias in Bash Script
A few weeks ago, I had trouble accessing aliases in bash scripts. It turns out that aliases are not expanded in scripts, only when the shell i interactive. However, we can get around this by using
expand_aliases at the top o our script.
#!/bin/bash shopt -s expand_aliases ...
Ports and Adapters Pattern Example in Python
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
Getting Started with Bottle
- Allow templates to access the “get_url” function
- Create an endpoint to serve your own static pages yourself
The Iterative Maze Problem
I had posted about a recursive maze solver earlier. This is an iterative solution to that problem.