Forward connection to local development environment in LAN

I needed a quick way to test a few things on a webapp running locally (on my Linux box) from another machine running Mac OSX.

Quick and easy way (although insecure, make sure you only do this on a private LAN) was to use socat.

Install on Archlinux (server):

sudo pacman -S socat

Install on the MacOSX client via homebrew:

brew install socat

Proxy local connection to the LAN (on the server; assuming the webapp runs locally on port 5000):

socat tcp-listen:8000,fork tcp:localhost:5000

Proxy remote connection to localhost (so we can access it with the benefits ...

Getting average image color from Python

It's quite common to see web pages that show a solid color in place of images, while resources are being loaded. The color is usually averaged from the original image, as to give it a more "consistent" feeling while the page loads.

A simple way to do this from the command line is by using ImageMagick to resize the image to 1x1 size, then get the color of that one pixel:

% convert pic.jpg -resize '1x1!' txt:-
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (16818.3,27417.8,39342.8)  #416B99  srgb(65,107,153)

(The image ...

mypy: function accepting type, returning instance

I recently ended up with a function that looks a bit like this (most of the logic was removed for sake of example):

def build(record, **kwargs):
    # Pretend we're doing stuff with the **kwargs here..
    return record(**kwargs)

Where record could be one of several classes. All we care about is, the function accepts a type as first argument, and returns an instance of that type.

The problem

At first, the most logical way to describe this to mypy was to use a TypeVar like this:

from typing import Any, TypeVar, Type

T = TypeVar('T')

def build(record: Type ...

Caching docker image on CircleCI

At BKNO3 we use Docker and docker-compose for development, in order to make sure every developer can easily and reliably set up a development environment locally, even if they're not familiar with the project itself (we have several components, with different developers working on each one).

The same docker containers are used to run continuous integration (on CircleCI) as well, in order to reduce the differences between the dev/ci/prod environments.

A big pain in doing so, however, was the time spent rebuilding the whole docker image every time the test suite was run, even if nothing changed ...

PostGIS on Gitlab-CI

It took me a while to figure out how to setup postgis on a gitlab-ci build, and could not find anything on the docs, so here is a brief explanation of what I did:

First of all, I used mdillon/postgis as a base image for the service, to avoid having to install postgis on the postgres:9.4 base image over and over.

Using custom docker images as services is explained on the Using Docker Images page of the official guide.

But in short, all I had to do is make a few following changes to .gitlab-ci.yml:

services ...

Page 1 / 3 »