Rent-a-founder

How to write a text editor

One of the most requested features for my terminal user interface library tview (now at 8.6K stars, which is still mind-boggling to me) was a multi-line text editor. Before starting to work on this UI component, I collected my users’ requirements for it. They basically boiled down to this:

Read more...

Mocking APIs in Go - An Alternative Approach

It’s fairly common that one has to write unit tests for applications that access external systems. We don’t want to forgo the advantages of unit tests for these applications. So we need to find a way to run them self-contained, without depending on external systems.

Imagine we have a function which saves a user’s password in the database:

Read more...

Word wrapping in Go

It may seem that “word-wrapping” or “line-breaking” — the process of breaking a section of text into lines such that it will fit in the available width of a display area — is a simple thing to do: Find the last space character in a line of text and break after it. If you’re dealing with simple English text, that is, all ASCII characters, this will work reasonably well. But as soon as other languages or special characters like emojis need to be supported, you are dealing with the full complexity of Unicode. Read more...

The Problem with Perceptual Hashes

Apple just announced that they will use “perceptual hashing” to detect illegal photos on iPhones. I have some experience to share on this technology.

At my company, we use “perceptual hashes” to find copies of an image where each copy has been slightly altered. This is in the context of stock photography, where each stock agency (e.g. Getty Images, Adobe Stock, Shutterstock) adds their own watermark, the image file ID, or sharpens the image or alters the the colours slightly, for example by adding contrast. For our customers, i.e. the photographers who upload their photos to these agencies and sell them through their platform, we need to find all of their photos’ copies on those agencies. We use perceptual hashes to find them.

Read more...

Convert an Image to Grayscale in 2 Lines of Golang

If you turn to Google on how to convert an image (e.g. a JPEG) to grayscale, almost all solutions you will find will cycle through all pixels individually to convert them to a luminance value:

Read more...

Autonomous Driving - Not Happening Any Time Soon

Watch this video which I recorded two years ago while travelling in Madagascar:

If it looks crazy, that’s because it is.

Read more...

Die Corona App: Der erste Versuch muss sitzen

Nichts darf, aber jede Menge kann schief gehen.

Read more...

IATA SSIM Flight Schedule Parser

This post likely doesn’t affect most readers of this blog. But since I also write to document my work, this announcement will go here.

I implemented a new commercial software tool which can read IATA SSIM Flight Schedule files (Chapter 7). SSIM files follow a sophisticated fixed-width format and are used to describe an airline’s flight schedule over a specific period of time (usually 365 days into the future). These files are used to exchange schedule information among a large number of airline systems, some of which include:

Read more...

How to Count the Characters in a String (Unicode)

You would think that maintaining a mildly popular package such as tview would consist mostly of adding cool new features, maybe with the odd bugfixing sprinkled in. You would be wrong. If I had to guess, I would say 70% of my work on it was dedicated to making Unicode characters work. It’s all very simple when you just have to support the English language. But with the first requests for Chinese, Thai, Arabic, or emoji support, I realized I was in for a lot of trouble. (And I dread the day when users will ask for Hebrew which is written from right to left.)

Read more...

Golang: Append Modifies Underlying Slices

Even after four years of programming in Go, there are still things I didn’t know about the language itself. The following example illustrates behaviour that surprised me. My (false) assumptions actually led to a bug which was very difficult to find as it happened only rarely and repeated reviews of the code didn’t turn up anything unusual. Here it is:

Read more...

My Go Package Reaches 1.4K Stars on GitHub

I was pleasantly surprised when I realized my recently published Go package tview had just passed 1400 stars on GitHub which is quite significant. It seems to have struck a nerve. As mentioned in my previous blog article, there are already a number of Go packages that allow you to create terminal-based user interfaces. But the focus on making it simple seems to have paid off. Naturally, with this popularity come new responsibilities: All of a sudden, I have to respond to feature requests, bug reports, and pull requests. Read more...

Terminal-Based User Interfaces in Go

Recently, a number of Go packages to create terminal-based user interfaces popped up. This is great because it allows you to run semigraphical applications on the server. It’s also more secure than implementing a dedicated admin area in your web app because it reduces the attack surface by hiding behind an ssh login. Here’s an example from Stock Performer where we can monitor the analytics precomputations that happen on the server: Read more...

My Gopher Academy Blog Post on Web Sessions and User Workflows

I’ve released two new Golang packages on GitHub: github.com/rivo/sessions and github.com/rivo/users. They will help you write web apps in Golang.

Read more...

Graceful Server Stop and Restart in Go

A blog post from 2014 explains quite nicely how one can achieve graceful server stops and restarts in Go, that is, how to implement a server process that allows running requests to finish before exiting the application. We will also want to deploy new binaries without interrupting running requests and without any noticeable server downtime. There are tools for this and in the past, I’ve used a combination of manners and goagain, along with some additional code on my end. Read more...

Textured Gradients in Pure CSS

We’re going to create a background like this in pure CSS:

Screenshot of result

Read more...

Generating Colour Palettes for Charts

I recently had to find a way to generate colours for charts. Specifically, the series in a chart — typically visualized using bars, lines, dots, or areas — are often distinguished using different colours which, for the most part, should be generated and assigned automatically. And while d3.js (on which the chart code was based) offers some pre-defined colour schemes which consequently happen to be used in most d3.js-based projects, they were quite limited for what I needed.

Read more...

Visualizing Data Using d3.js (With Examples)

The web browser has become our preferred user interface of choice. But even in 2015, I bump into fellow developers who view the web as nothing more than a bunch of companies’ online presences. Surely, a native Windows client or a Java SWT app must be more powerful than your average web browser. I would have agreed in the days of Internet Explorer 6 (which, by the way, already supported AJAX requests) but luckily, we are long past IE6 and there are now so many web technologies available to us it’s even hard to keep up.

Read more...

Find Similar Images with Duplo

I’ve released a Go library Github: Duplo. The library can be used to detect image duplicates or to find similars in a set of images. It is an implementation of Fast Multiresolution Image Querying by Jacobs et al. It works surprisingly well if you want to find duplicate images which may have been modified slightly (e.g. colour correction, different compression / file format, watermarks). Applications may include: Recognize copyright violations Save disk space by detecting and removing duplicate images Search for images by similarity The images themselves are not stored in the data structure. Read more...

My Talk at the Golang User Group Berlin Meetup

I gave a talk at Berlin’s Golang User Group (which is supposedly the biggest one in Europe at the moment). It was a quick overview of the duplicate image detection software I wrote in Go for Stock Performer. You can find the slides here. I will put the code on my Github profile very soon. There will also be a more extensive blog post about it.

Adventures in Clojure: The Font Manager

I’ve contributed to Github projects before but I’ve just now uploaded my first own Github repository: The Font Manager. It combines two things I’ve been wanting to do for a quite a while: Learn to program in Clojure Write a font manager / viewer that can look into ZIP archives There are lots of font viewers out there. But for some reason, I wasn’t able to find one that could search ZIP files. Read more...

Learning Swift

Started learning Swift. This seems to be a good moment to finally get into iOS programming. What I’ve seen so far looks ok, although I’ve recently started to really enjoy simpler languages (more on that later). The trend in the last few years seemed to be to add more and more “features” to a language based on whatever the trend is at the time. Generics, closures, features from functional languages. I don’t really think it’s needed — I’d like an OO language to remain OO, I don’t need it to become a functional language. Read more...