Posts
Generating thumbnails 3.8x faster by using ffmpeg seeking instead of fps filtering
As part of tinkering with reelchest, one of the tasks I need to tackle is thumbnail generation.
A few ways to do that are described in the official ffmpeg documentation. Since I want to create more than one thumbnail per media file (hopefully, so that I can do some kind of cool crossfade effect that makes the entire application feel a bit more lively), I opted for the fps
video filter. Here’s the snippet in my code that creates a thumbnail every 10 seconds into the video. (The snippet here is Kotlin, but they’re the literal CLI flags passed to the ffmpeg
process, so this should be comprehensible.)
Pooling multiple drives on my Raspberry Pi with mergerfs
My homelab setup is a bit of a mix-and-match of whatever hardware I happen to have lying around. Likewise, since I mostly run strange little experiments in my home setup, my requirements change frequently. Here’s one such requirement:
An app I built needs more storage than I have on the external HDD that’s currently attached to my Raspberry Pi.
I did have another, smaller HDD that wasn’t seeing any use, so I looked into ways of somehow fusing the two drives together, essentially extending storage across two heterogeneous drives.
Guide: Cross-compiling Rust from macOS to Raspberry Pi (2024, Apple Silicon)
This guide builds on the guide from Amarit Rathie, which has been an indispensible resource in getting me started with cross-compilation at all. Mine has been updated for the latest versions of macOS at the time, and I’ve tried it on an M2 Mac – here, I’m the steps (and workarounds) required to get it to work for me – explanations are kept short, and I encourage you to reference the original blogpost to get a better understanding of what’s going on.
Coroutines quirks: withTimeout might not do what you think it does
TLDR: The
withTimeout
function doesn’t cancel the execution of the block you pass it. It throws aTimeoutCancellationException
, which, when left uncaught, cancels the invoking coroutine.The
withTimeoutOrNull
behaves as expected, canceling only the block, and returningnull
in case the timeout was exceeded!The kotlinx.coroutines team is aware of this issue.
In Kotlin coroutines, the
withTimeout
function can be used to constrain the execution of your code to a specific timeout. Its signature looks as follows:Idiomatic Kotlin: Solving Advent of Code Puzzles, Passport Validation
Today in “Idiomatic Kotlin”, we’re looking at day 4 of the Advent of Code 2020 challenges, in which we tackle a problem that feels as old as programming itself: input sanitization and validation.
Day 4. Passport processing
We need to build a passport scanner that, given a batch of input text, can count how many passports are valid. You can find the complete task description at https://adventofcode.com/2020/day/4.
Exploring Kotlin Lists
This blog post accompanies a video from our YouTube series which you can find on our Kotlin YouTube channel, or watch here directly!
Today, we’re talking all about lists! Lists are the most popular collection type in Kotlin for a good reason, and we’ll find out why together.
Lists
What’s a list?
If you’ve written Kotlin code before, you’ve definitely seen a list – they’re collections of ordered elements, where each element is accessible via an index. As such, they’re one of the basic building blocks for a lot of Kotlin code.
Advanced Kotlin Collection Functionality
This blog post accompanies a video from our YouTube series which you can find on our Kotlin YouTube channel, or watch here directly!
Today, we are learning about advanced functions that we can use to work with and manipulate all kinds of Kotlin collections!
Checking predicates:
any
,none
andall
Let’s warm up by having a look at a selection of functions that allow us to check conditions for our collection elements.
How I built an "Asteroids" game using Compose for Desktop (Part 1/2)
A while ago, I tweeted about a small game I had created on top of Compose for Desktop: A small clone of the classic arcade game Asteroids, in which you control a space ship with your mouse, and navigate the vastness of space, avoiding and breaking asteroids in the process.
Today, it’s time to take a look under the hood and understand how I built a basic version of this game, and how Compose for Desktop helped me achieve it in just one evening!
Tips & tricks for building a game using Compose for Desktop (Part 2/2)
In the first part of my blog post series about building a small clone of the classic arcade game Asteroids on top of Compose for Desktop, we saw how to implement the main game loop, as well as manage state and draw basic shapes. In this post, we will explore some more details of the game implementation. This includes:
- Rendering details – making sure game objects don’t escape our play area, and using a device-independent coordinate system for rendering
- Geometry and linear algebra – the secret sauce that makes the space ships fly
- Frame-independent movement – so that our game works consistently.
Let’s learn about these topics!
Diving into Kotlin collections
This blog post accompanies a video from our YouTube series which you can find on our Kotlin YouTube channel, or watch here directly!
Kotlin Collections! You’ve heard of them, you’ve used them – so it makes sense to learn even more about them! Kotlin’s standard library provides awesome tools to manage groups of items, and we’re going to take a closer look!
Kotlin Standard Library Safari: Strings
This blog post accompanies the first episode of our YouTube series “Kotlin Standard Library Safari”, which you can find on the official Kotlin YouTube channel, or watch here directly!
What’s Kotlin Standard Library Safari?
In the “Kotlin Standard Library Safari” series, we’re going through the useful functionality the standard library in Kotlin has to offer, one subject at a time. In the process, we’re hopefully going to unearth some hidden gems together, which will come in handy the next time you write Kotlin code. Because if you know how to wield it, the Kotlin standard library is a powerful tool which can help you be more productive solving your problems, and be more expressive in your code.
Migrating our Kotlin/JS app to the new IR compiler
Together with some colleagues, I maintain a small full-stack web application called CodeQuiz, which we built during a 48-hour hackathon at JetBrains, and use at events to gamify learning about Kotlin. I recently migrated its frontend which you can see below (and which is using the
kotlin-react
wrappers) to the new Kotlin/JS IR compiler backend.The new compiler made a bunch of issues in our code visible, so I wanted to share my experience of migrating a Kotlin/JS app, and provide some hints on where to look when your app behaves unexpectedly after moving to the IR compiler.
Tips and tricks for your Kotlin code explorations
This blog post accompanies a video from our YouTube series which you can find on our Kotlin YouTube channel, or watch here directly!
We’re going to take a look at some handy tips and tricks to help you explore Kotlin code, no matter whether it’s your own code or the code from the Kotlin standard library or any of your other dependencies. They will equip you to discover some of the goodies in the code you’re working with on your own.
Hosting Kotlin/JS on GitHub Pages via GitHub Actions
GitHub Pages is an easy way to host your Kotlin/JS application - and in combination with the continuous integration service GitHub Actions, you can easily set up a smooth development (and deployment!) experience for your projects. Read on to learn how you can build and test your application on GitHub’s CI, and get your Kotlin/JS web apps published for free.
In this post, we are going to configure GitHub Actions and Pages so that new code pushed to our repository or added via pull request is automatically validated (by having the project built and our tests run on GitHub’s servers), and code pushed to the main branch of our project is automatically made available to the public (by generating and publishing production artifacts of our app).
Deploying server-side Kotlin Ktor applications on Dokku
In my last article, I talked about “[Publishing server-side Kotlin applications built with Ktor on Heroku]({% post_url 2021-01-15-Kotlin-on-heroku %})”. I really like Heroku as a place to host my Kotlin apps because the time from setting up my application to having it available to the public is very short – I can confidently get my prototype applications running in the cloud in less than 10 minutes, and even if I need a database or integration with some other service, it can be spun up in mere minutes.
Kotlin, Ktor and Exposed on Heroku
Getting an application into the hands of the first users is the best feeling. Seeing them try out an app for the first time and collecting feedback from them for future improvement has always felt very rewarding to me. For server-side apps, this usually means getting the app deployed somewhere – published on the web.
Today I want to share one quick way to get Kotlin applications built with Ktor onto the web: Using Heroku.
Running Create-React-Kotlin-App on Heroku
(This post is a tutorialized version of the workarounds that I worked out together with Andrey Skladchikov in this YouTrack issue for CRKA.)
As the name might suggest,
create-react-kotlin-app
(CRKA) is the Kotlin equivalent of JavaScript’screate-react-app
: A wonderful little tool to automate all the webpack and configuration stuff for your React/Kotlin application, having you focus completely on the actual application logic.Getting create-react-kotlin-app to run on Heroku, however, is not without its pitfalls. After having struggled through it myself, I’ll run you through how you can deploy your CRKA application on Heroku, proper production builds and all.
Developing for Raspberry Pi using IntelliJ Deployment
So a few days ago I published the Thermal-Kotlin library which allows use of thermal printers in conjunction with a Raspberry Pi. That library and the way I developed it will get its own article soon, but I wanted to pick out one part that was particularily interesting for me: Automatic Deployment using IntelliJ.
When prototyping the library, I had to run it on the Raspberry Pi often, in order to figure out the exact workings of the protocol used by the printer and even try out timings that wouldn’t prevent the printer’s buffer from overflowing. At first I tried running IntelliJ on the Raspberry Pi to little success (unfortuantely the Pi isn’t nearly beefy enough to run a fully fledged IDE at a comfortable speed), but I didn’t want to miss out on all the great autocompletion and refactoring features that I have become so used to in IntelliJ.
Fixing PAGE_FAULT_IN_NONPAGED_AREA after Windows 10 Creators Update
After the last unsolicited update from Microsoft, the Creators Update for 2018, instead of a seamless upgrade, I was greeted by
PAGE_FAULT_IN_NONPAGED AREA. Cause of Error: SbieDrv.Sys
This was combined with Windows frantically trying to restart multiple times, trying to roll back the changes it had made, all to no avail. As I was sitting in front of the computer, beeping with every restart, I started researching on my phone in order to take matters into my own hands.
Hexagonal Grids
I was spending one of the recent days in the Loretta Bar here in Munich together with Alex, and we worked on a few tasks of the 2017 edition of Advent of Code. I was infatuated with the last task we worked on, the Day 11 challenge. You are supposed to find the distance of a position in a Hex Grid based on a path description. I had already read a few articles regarding hexagonal grids, because I feel it is one of the less intuitive data structures, but none of them really made me understand the topic extremely well. I decided to just grab a pen and doodle away at a napkin and (later on) a few pieces of paper, scribbling around and trying to figure things out. After I had managed to build an (albeit inefficient) solution for myself, I set out to understand more about the topic. When I managed to have somewhat of a personal breakthrough in understanding, and felt a lot better reasoning about the topic, I decided it would be time to improve upon the visualisations that I had seen on other blogs like Redblobgames. They’re still a great read any heavily recommended, but I thought I’d try my hand at one of these as well. So, amidst what seems like a heavy outage on the internet (with a very spotty connection), I managed to glue together a small demo. Because we all love interactivity, I’m going to throw the demo in first, and the rest of the text later.
Making my Fire HD 10 a YouTube machine
T’was the night of the 24th of december, I was sitting together with my family at my grandparent’s house and celebrated Christmas - and the Christkind blessed me with a Fire HD 10 Tablet, freshly made by Amazon (or whoever manufactures these things). It should serve as a replacement device for my Sony Xperia Tablet Z which unfortunately had an unplanned rendezvous with the floor.
So I set out to make this thing my classic YouTube watching machine that I was used to before. Which is when I encountered…
Setting up a CUPS / AirPrint Server on Raspberry Pi
Even though I’ve switched almost my whole office experience to paperless, my parents are still very much heavy users of the printer. However, with the recent diversification of even their technology, and the growing need to print from a Windows machine, a Macbook and an iPad, I knew it was necessary to find a unified way to print from all those devices. The answer proved to be a CUPS (formerly Common UNIX Printing System) server on a Raspberry Pi that I had lying around.
Muting Macbook after Restart
1. Install sleepwatcher & set up as service
brew install sleepwatcher
brew services start sleepwatcher
2. Configure mute on wake
echo "osascript -e 'set volume output muted true'" > ~/.wakeup && chmod +x ~/.wakeup
Heavily inspired by a post on kodiakskorner