Sebastian Wiesner (“lunaryorn”)

I write software for satellite mission planning with Scala and Akka, and play with Rust in my free time.

Contact

Projects

Latest posts

Rust, Windows, Travis CI…

Travis recently announced early stage Windows support, and it already supports Rust. I couldn’t wait to try it—I don’t really enjoy AppVeyor—so I set it up for mdcat and it worked really well.

The change was really simple, and I just took me a few iterations to get almost everything—in particular deployments to Github releases—working just like on Linux and macOS. I could eventually remove AppVeyor entirely which makes me really happy. This post describes the change and also outlines what little’s still missing for me.

Read More…


sudo fish

Over the last week I setup a Linux VM alongside my current work—I needed decent docker support and also I got somewhat fed up with Windows as a development system.

Setting up a new system means I got to use sudo a lot, but often I typed a command line and only then realized I had to use sudo. So I added a new editor binding to my ~/.config/fish/functions/fish_user_key_bindings.fish:

function fish_user_key_bindings
    fish_default_key_bindings

    # Prepend sudo to the command line with M-s
    bind \es sudo-commandline
end

~/.config/fish/functions/sudo-commandline.fish looks like this:

function sudo-commandline -d "Insert sudo at the beginning of the command line"
    set -l cmdline (commandline)
    commandline -r -- "sudo $cmdline"
end

Now I can just type Alt-S in Fish shell and I get sudo prepended to my current input. A small thing, but it already saved me a lot of frustration!

Permalink


Git Gone

A few days ago Eugene Yokota published a git-gone script which deletes local branches left over from pull requests. I liked the idea; at work we use pull requests a lot and I already have many stale branches around.

We use Windows at work, tho. I know, folks frown about Windows as developer system, and I sure do miss my Mac at times, but it is what it is, and the job’s worth using Windows. And with a few tweaks, Powershell 6, ConEmu and VS Code it’s a decent system to my surprise. Anyhow, the one thing Windows can’t really do is run Bash scripts, and unfortunately Eugene’s tool is a bash script.

So I wrote git-gone in Rust with the git2 crate and published it to crates.io. Enjoy.

Permalink


Recursive Exceptions

A couple of weeks ago a former coworker send me this piece of code I had writtten:

@tailrec
private def getRootCause(throwable: Throwable): Throwable = {
  Option(throwable.getCause) match {
    case None => throwable
    case Some(cause) => getRootCause(throwable)
  }
}

D’oh! A nice endless loop. It caused quite nice spikes in garbage collection metrics and peak response times, and it took them a few days to find the root cause.

Ironically I had explicitly added @tailrec to make this piece of code behave nicely. If I had omitted it, StackOverflowExceptions would have triggered alerts almost immediately after deployment.

I am sorry.

Permalink


UTC is the Worst

Me as a web developer: UTC is awesome! All use UTC!!

Me today: FUUUUUUCK LEAP SECONDS. Can we pleeeease all use TAI?

UTC is the worst; and it’s going to get way worse:

Some time in the 22nd century, two leap seconds will be required every year. The current use of only the leap second opportunities in June and December will be insufficient, and the March and September options will have to be used. In the 25th century, four leap seconds will be required every year, so the current quarterly options will be insufficient. Thereafter there will need to be the possibility of leap seconds at the end of any month. In about two thousand years, even that will be insufficient, and there will have to be leap seconds that are not at the end of a month. In a few tens of thousands of years (the timing is uncertain), LOD will exceed 86,401 s, causing UTC to require more than one leap second per day.

In 40.000 years People will hate us for three things: Global warming, Nuclear waste, and UTC LEAP SECONDS!

Permalink


Towards Hugo

I moved my blog from Jekyll to Hugo, the not-so-new and cool thing for static pages. I didn’t pick Jekyll consciuously—it’s just that before Netlify I had my blog hosted on GitHub Pages which runs on Jekyll.

Read More…


Algebraic Data Types In Scala

Object-Oriented Meets Functional

Scala claims to unite object-oriented and functional programming, and offers a rich set features from both worlds. Developers coming from object-oriented languages—Java in particular—quickly adopt the object-oriented features of Scala but often struggle to find their way around functional programming. Some aspects of functional programming found their way into object-oriented languages: Higher order functions or combinators like map and filter appear in today’s C# or Java code, and even a preference for immutable data structures spreads out into conventional object-oriented languages.

But algebraic data types (ADTs) still do not appear in object-oriented programming although these enable the true power of functional programming: Types well-founded on theory let us model the problem domain in types and thus help us write correct-by-construction code which provides a higher level of compile-time confidence than possible with the type systems of most object-oriented languages. This article aims to help developers from object-oriented languages understand what it means, and become familiar with the basic set of algebraic data types commonly used in functional programming and its appearance in Scala.

Read More…


Decode irregular JSON from Jenkins with Circe and Shapeless

The popular Continuous Integration (CI) server Jenkins provides a JSON API to access information about builds. At my former employer we heavily relied on Jenkins and its API to automate the integration and delivery pipeline of our Scala services; our internal tools often used the API of our Jenkins server to get information such as the latest successful build number for versioning. The Jenkins API speaks JSON, but the JSON it returns has a rather strange shape. I needed to extract the Git revision built by a job, but Jenkins hides this information in a specific object in a “catch-all” actions array which contains JSON objects of different shapes, many of which may or may not be present. With Circe—a lovely JSON library for Scala—and some Shapeless magic I managed to decode this irregular JSON in a type-safe and fail-safe way (ignoring unknown JSON objects).

Read More…


Decode “flat” ADTs with Circe

I had to talk to a web-service that returned JSON without meaningful HTTP status codes (don’t ask). All I had was the JSON itself to figure out whether the service returned a success or failure: Essentially I had to decode an ADT except that all alternatives were flattened into the same level in the JSON. A Circe decoder for these responses needed to inspect the JSON while decoding to pick the right branch.

Read More…


Maven Central Releases with SBT

Coming from Haskell and Python I found releasing a Scala library a cumbersome process. The standard Maven Central archive—JCenter claims to be a more popular alternative, but all big projects appear to prefer the former—lacks a convenient web interface like that of Python’s package index or Haskell’s Hackage, and comprehensive documentation about publishing. Getting an artifact to Maven Central for the first time involves a surprising number of manual steps and a rather elaborate SBT configuration.

In this article I hope to connect all the loose ends and offer a comprehensive step-by-step guide from nothing to a Maven Central release. I will start with some prerequisites which lie outside the scope of this article, guide you through the necessary bureaucracy and cover the setup. At the end I’ll introduce sbt-release, a powerful plugin to automate the entire release.

Read More…