Fixing Cloudflare 523 errors
(when using Cloudflare Tunnels)
For some context: Recently I’ve been sharpening my Kubernetes skills by setting up a small 6 node k3s cluster at home. The place I currently live doesn’t have a public IP address, so I chose to set up a Cloudflare Tunnel to expose services to the internet.
I chose to have the cloudflared daemon running on the host machines and the overall setup quick and pain-free. The whole thing seemed to work well, but I noticed that over time (within hours) the tunneled
services would start responding more slowly and eventually Cloudflare would display 523 errors.
Owning your music (collection)...
...without losing your mind, part 1
Recently, after learning how bad spotify is for its artists I made a deliberate effort to move my family to Tidal - 8/10 decision, would recommend.
But to take step further I decided to slowly move towards “owning my music” - maintaining my own digital collection of music and making sure I have a convenient way of listening to it.
There were a number of reasons for it
- a push against the you’ll own nothing and be happy about it shift in consumer culture
- moving back to listening to music in a more deliberate way, without phone distractions
- the joy of using a dedicated device - you can listen to music for hours without worrying about draining your phone’s battery, the UX can be better, and you can use good wired headphones
- I’m turning into the “old guy yells at cloud” guy and I’m recently gravitating towards maintaining my own “infrastructure”
Let me share what setup/workflow I ended up with. In this post I’ll talk about where I get my music from and what I play it on (plus the reasons behind the decisions). In the next one I’ll share how I store and manage the collection in a pain-free and player-agnostic way.
Elixir string operations seem slow
...and why it's a good thing
I personally hate it when people post clickbait titles and take their sweet time getting to the point, so let’s do this first:
TL;DR: Some Elixir string operations, most notably String.at/2 work in linear time,
as opposed to constant time, like the intuition might suggest. This is because the String module is UTF-8 aware.
UTF-8 encodes characters outside of ASCII with more than one byte, so in order to find the n-th character in a string you need to process it from the beginning, you can’t just use an offset in memory.
In this blogpost I go a bit more in depth about how UTF-8 works and compare some approaches to getting performant results, so even if you knew the tl;dr you might find something interesting here regardless.
Context
I as doing an algorithmic exercise containing string manipulation in Elixir and saw that even though my approach was correct and seemed pretty optimal, it was timing out on larger inputs - and timing out by a lot. After looking into it a bit I realised