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 ...

Shooting timelapse videos on Linux

I've been doing some experiments with shooting timelapse videos, and I'd like to share information that could be useful for others (or future me looking for it again..).

Far from being a guide, I'm just pasting here the commands I used.

Just as a reference, I'm using a Nikon D3300 and Archlinux, but I assume tethering is supported for most modern DSLR cameras.

Shooting the actual photos

I'm currently using the dumbest way of doing this: ask gphoto to shoot one frame every 5 seconds and download to the local hard-drive:

gphoto2 --capture-image-and-download -I 5 ...

Page 1 / 7 »