UHFIF — A post mortem on a useless image format

Background A while ago (around six months) I started working on a very simple image format. My intention wasn’t to create anything really useful which is why I called it “useless high fidelity image format” – or UHFIF for short. The main goal with UHFIF was to teach me about file formats. While I knew a bit about formats I had never actually implemented a file format. And because I wanted to learn about image encoding an image file format it was. ...

January 24, 2025 · 4 min · Moritz Sokoll

Speeding Up Applications With Async

Context About a week ago, I decided to publish my newest album onto my music page which is built using the faircamp static site generator. faircamp has to generate a bunch of files at build-time for deliverables and streamable files. In total, this means that every track has to be built three times in my configuration: Opus 96kbps (streaming) MP3 (streaming for better support on older platforms) Opus 128kbps (deliverable) In total – for me – that was 92 tracks. All of these 92 tracks are produced sequentially using ffmpeg1 which for me takes ages – 10 minutes or 670 seconds to be exact. ...

September 5, 2024 · 5 min · Moritz Sokoll

Rust Type Magic

What are types? Types in programming languages are different across the board. Essentially the only common denominator is primitive types. These are types that are not implemented with the language and exist as a consequence of the languages features but rather they are a part of the language. Some common types include: integers characters strings booleans floats This list is going to be different for every language but it works in general. ...

June 13, 2024 · 5 min · Moritz Sokoll

Rust Error Handling

Error handling is hard rusts error handling is substantially different from other languages. For a quick comparison let’s look at a python example: try: # code that fails except: # what happens when code fails This approach, although intuitive, leaves some important flaws. Namely: Unhandled errors may occur Errors are propagated implicitly, not explicitly, which can lead to some unwanted behavior If your try-block ends up containing multiple parts of code that could fail you have to handle each of them separately How rust handles errors If you have used rust before you’ll already know what comes up. The two main types for error handling in rust are Result and Option. The latter technically doesn’t count as an error type as it just represents the case where an operation may return nothing (i.e. NULL in C, None in python, etc.). The real error type is Result. ...

May 5, 2024 · 7 min · Moritz Sokoll

skvconf - A configuration file parser

Introduction I have been programming in various languages for quite some time now but have found myself coming back to C and rust the most. One small problem I had with C however was adding configuration capabilities to my applications. In rust I always just used the toml crate but that didn’t work in C. So I ended up writing very simple parsers for these projects. This was of course not very scalable and also had ugly configuration syntax as a side effect. Eventually, I decided to write a dedicated library that I could embed into my applications when needed. This library would focus on having a good configuration language as the base and would handle parsing and the rest. ...

April 21, 2024 · 6 min · Moritz Sokoll

Writing a web server in C

Introduction A while ago I started work on a web server written in C. The project is available here. Before I had written a web server in rust (found here) so I was a bit familiar with HTTP and since this wasn’t my first ever C project I of course knew a bit about basic file handling and error handling. The main new things to learn where the following: Working with sockets Using a thread pool with: Worker threads An event queue for incoming requests Parsing a configuration file Technical details Sockets While I was somewhat familiar with sockets I hadn’t used them in C (I used them in a small python web server). This turned out not to be a big problem. The harder part was the protocol parsing but I restricted myself to HTTP/1.1 connections that close immediately after being processed. And I didn’t look into non-blocking sockets. This is one of the things I might explore later in a smaller form factor and then either try to work into this project or write a new one from scratch. ...

April 17, 2024 · 3 min · Moritz Sokoll