Counting digit occurrences in a range

I was asked if I knew an easy way to count how many times digits occur within a range of numbers. For example in the range 10–15, how many times does each digit occur? The numbers 0, 2, 3, 4 & 5 each occur once, and 1 occurs 6 times, that is twice in the number 11, and one in every other number in the range, because the tens all start with a 1. It seemed like an odd request, but it’s for number tags on utility poles, like this one:

There might be several rows of yellow tag numbers on a given utility pole

By Onore Baka Sama – Own work, Public Domain, source

Electricians use these tags to identify the poles and, at least in Hungary, they’re made up of individual plates for each digit, that are screwed on to a larger plate on the pole. If you estimate too few when ordering the digits you’ll run out obviously, and if you order too many you’ll be stuck with a pile of unused digits.

It seemed like a problem that should have a simple mathematical solution to it. Unfortunately, the answers I found on Math Overflow Continue reading

Custom thumbnail generators for audio waveforms and GIMP XCF files

I recently packaged these 3D thumbnailers for Arch Linux and this act inspired me to dig into this topic a bit and make some of my own. First off, what’s a “thumbnailer”? It related to this Free Desktop specification and I’d summarise it as:

A thumbnailer is a program that can generate a small preview image (called “thumbnail”) of a specific file type. File browsers know about thumbnailers by reading configuration from .thumbnailer files which specify which program to call for a specific MIME type, and which arguments to use to get the desired output.

For more details and practical examples of what these files look like and what you can do with them, see this blog post by Radu Zaharia. For most of the 3D thumbnailers I packaged, the thumbnailer programs are small purpose-built scripts, written in Python or Bash, that understand the specified format and how to get a PNG image out of it. The thumbnailer config just specified which order it wants its file input and output arguments in. However, as Radu’s blog post points out these can also be more advanced one-liners using programs you already have installed, so I decided to try that out and this post I’ll cover 2 such examples: Audio & GIMP.

tl;dr: Copy-pastable version at the end of the post Continue reading