week 34, 2021

Develop a Go app with Docker Compose

Writing Go applications in an isolated environment with Docker comes with some great advantages. You get the bare essentials for developing, and you can easily change which Go version you’re developing against.

In this tutorial, we’re going to show you how to structure a Go application with Docker Compose as your development environment.

In the end you'll have:

  1. A docker compose setup to develop in
  2. An HTTP server written in Go that is connected to Postgres
  3. An auto-reloading server that compiles when you change a file

Source: Develop a Go app with Docker Compose, an article by Robert Ross.

CSS masonry

On the surface it seems fairly easy to create a masonry layout with flexbox; all you need to do is set flex-flow to column wrap and voilà, you have a masonry layout. Sort of. The problem with this approach is that it produces a grid with a seemingly shuffled and obscure order. Items will be (unbeknownst to the user) rendered from top to bottom and someone parsing the grid from left to right will read the boxes in a somewhat arbitrary order, for example 1, 3, 6, 2, 4, 7, 8, 5, and so on so forth.

Source: CSS masonry with flexbox, :nth-child(), and order, an article by Tobias Ahlin.

Light Chaser

Amahle is a Light Chaser – one of a number of explorers, who travel the universe alone (except for their onboard AI), trading trinkets for life stories.

But when she listens to the stories sent down through the ages she hears the same voice talking directly to her from different times and on different worlds. She comes to understand that something terrible is happening, and only she is in a position to do anything about it.

And it will cost everything to put it right.

In the evening I started in Light Chaser by Peter F. Hamilton and Gareth L. Powell.

jsc: My New Best Friend

A friend of mine recently pointed me at a well hidden command line tool. In the JavaScript framework used by Safari and other parts of Apple’s products, there is a tool called jsc. It’s a command line interface for JavaScript that uses the same code as the rest of the system.

Source: jsc: My New Best Friend, an article by Craig Hockenberry.

Plugins in Go

Several years ago I started writing a series of posts on plugins: how they are designed and implemented in various systems and programming languages. In this, I'll extend the series by providing some examples of plugins in Go.

As a reminder, the original post in this series identifies four fundamental plugin concepts, and claims that nearly all plugin systems can be characterized and understood by mapping their design to these concepts:

  • Discovery
  • Registration
  • Application hooks to which plugins attach (aka. "mount points")
  • Exposing application capabilities back to plugins (aka. extension API)

Source: Plugins in Go, an article by Eli Bendersky.

Away from exceptions: errors as values

Programming with exceptions is difficult and inelegant. Learn how to handle errors better by representing them as values.

In Smelly Exceptions, I laid out 3 practices to avoid when programming with exceptions. My goal there was to help you write more maintainable code. We saw that misuse of exceptions make programs brittle, tightly coupled, and difficult to reason about. The common factor in all three anti-patterns we discussed was exceptions. They are hard to use correctly. Even when used correctly, they don't compose, so the program flow is unnatural. In short, they are exceptions.

Source: Away from exceptions: errors as values, an article by Barisere Jonathan.

How to enable Python type checking in VSCode

Since version 3.5, Python now has support for type hints. This typing is a cool new feature allowing type checking across your code for more quality and also help when you are using some packages or call some functions your colleague did in a large codebase. In this article, we will see how to enable type IntelliSense and type checking analysis in Visual Studio Code editor.

Source: How to enable Python type checking in VSCode, an article by Emmanuel Gautier.

Cropping model images using PIL

We love to use model images at Wehkamp. This year we've switched from overviews with product images to overviews with model images. A lot of photography is shot by our own photo studio. I love this, because it gives us control over the process and the tone. But as our assortment grows, it is not feasible to shoot all the products on our website. That is why we use images from our suppliers. Unfortunately, we have no control over the conditions of the photo.

Source: Cropping model images using PIL, an article by Kees C. Bakker.

Pin, Unpin, and why Rust needs them

Using async Rust libraries is usually easy. It's just like using normal Rust code, with a little async or .await here and there. But writing your own async libraries can be hard. The first time I tried this, I got really confused by arcane, esoteric syntax like T: ?Unpin and Pin<&mut Self>. I had never seen these types before, and I didn't understand what they were doing. Now that I understand them, I've written the explainer I wish I could have read back then. In this post, we're gonna learn

  • What Futures are
  • What self-referential types are
  • Why they were unsafe
  • How Pin/Unpin made them safe
  • Using Pin/Unpin to write tricky nested futures

Source: Pin, Unpin, and why Rust needs them, an article by Adam Chalmers.

Why I use attrs instead of pydantic

This post is an account of why I prefer using the attrs library over Pydantic. I'm writing it since I am often asked this question and I want to have something concrete to link to. This is not meant to be an objective comparison of attrs and Pydantic; I'm not interested in comparing bullet points of features, nor can I be unbiased since I'm a major contributor to attrs (at time of writing, second by commit count, after Hynek) and the author of one of its unofficial companion libraries, cattrs.

Source: Why I use attrs instead of pydantic.

Creating PDF Invoices in Python with borb

In this guide, we'll be using borb - a Python library dedicated to reading, manipulating and generating PDF documents. It offers both a low-level model (allowing you access to the exact coordinates and layout if you choose to use those) and a high-level model (where you can delegate the precise calculations of margins, positions, etc to a layout manager).

We'll take a look at how to create a PDF invoice in Python using borb.

Source: Creating PDF Invoices in Python with borb, an article by Joris Schellekens.

Using Emacs in an IDE world

I remember the sad day that I finally gave up on using Emacs for Java development at work. I had spent hours trying to configure it to properly index all of the files so that I could go to definition easily. My mentor, the old Lisp guy with the insane init.el file who I would pester with questions, told me: “Just use IntelliJ”.

Source: Using Emacs in an IDE world, an article by Andrew Judson.

Daily Rust: Iterators

Iterators are part of Rust’s secret sauce. They power things from the humble for-loop to the elegant iterator chain, but have you ever stopped to think how they work?

Let’s find out more about Rust’s iterators by implementing our own versions of common iterators and reading the standard library’s source code.

Source: Daily Rust: Iterators, an article by Michael F. Bryan.