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 a TimeoutCancellationException, which, when left uncaught, cancels the invoking coroutine. The withTimeoutOrNull behaves as expected, canceling only the block, and returning null 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.

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 Like many challenges, we first inspect our input:

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.

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 and all 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.

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! Let’s see what types of collections the Kotlin standard library offers, and explore a common subset of operations that’s available for all of the collections you get in the standard library.

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.

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’s create-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.

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.

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.

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.

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