What I’m up to - Mostly Elixir things

Underjord is a tiny, wholesome team doing Elixir consulting and contract work. If you like the writing you should really try the code. See our services for more information.

While I'm writing something a bit more involved and substantial I figured I could give an update on what I've been doing. Mostly around Elixir. But I'll cover a few different things.

Ecto - A deep dive

Working on a project I'll cover more at a later date has led me to work more with Ecto. I rather like it. What I didn't like is that my use-case seems fairly unexplored and a little bit light on documentation. The project requires multi-tenancy for the database, that is, running multiple instances of the same Ecto repo. The support for this exists and is actual very reasonable overall. But it wasn't exactly a packaged deal and the number of people who have written about it is low. Expect me to publish a write-up on this with a bunch of examples. I'm just dealing with blog post scope creep.

Fun parts of this journey involved taking a few looks into how Ecto actually does things. I cannot recommend this enough, read the code. Look how it works under the hood. I have never worked in an ecosystem where I felt the code was easier to reason about than Elixir. I do not have to ingest the entire class and object hierarchy out of someones mind through the straw of their library code. Most things are easy to reason about. There are strong conventions around most of the slightly complex things like GenServers but often you're just dealing with pure functions and some IO.

The dive resulted in two issues and a PR. If I'm happy with my post I might contribute a streamlined version into the Ecto docs to cover some of what I'm doing. Creating repos at runtime, ensuring the database has been created, running migrations at runtime and that sort of stuff. It's all there in Ecto, but there aren't so many guides around it.

ExUnit - Testing and mocking

I've done some work now which benefited greatly from mocking some of the calls. As they required user interaction on a mobile device to trigger the response (yeah, auth through a second factor, nothing fancy). Getting it exactly right was a bit of a hassle from what I recall. But it was a little while back. I might do a write-up on it if there is interest. But there's plenty of stuff about Mox and all that already. If I write something it'll probably be mostly about the gotchas or how I used it.

So what was this 2-factor-stuff? Well, read on if you have niche interests!

BankID - Swedish national identity sign-on

I made a library for using the swedish national identity sign-in thing for Elixir. I fully intend to release it but it needs some polish and I still need to decide if I like having my own personal information as test data ;)

It is not a complex API to implement so most people could do it on their own. But at least this gives you a GenServer that handles some of the keep-alive mechanisms and stuff for you and wraps it all up quite nicely. I even ended up getting familiar with Erlangs :httpc module to minimize dependencies.

If this would be useful to you in a project and I haven't released it yet. Get in touch. You can have it :)

Nerves & Scenic - More people

Justin's talk at ElixirConf US 2019 seems to have sparked quite a bit of interest. I think the stream of people into #nerves and #scenic on the Slack has gone up. Still a very chill place and a lot of friendly people. It mostly caught my eye because there have been a lot of people getting started with Nerves and/or Scenic in there.

Which leads me to what I spent yesterday evening investigating and the morning swearing about.

A Scenic diversion

If you run Scenic on your development environment chances are you use your mouse to click things and your keyboard to type.

If you run the same project using Nerves and the Scenic Nerves display driver (the one meant for the official touchscreen) and then you connect a mouse, you will not have a good time. Or you won't click things, that's for sure. Because the Scenic driver doesn't know anything about mice. On your host it uses glfw which handles all this. On device it uses nanovg which doesn't. But you have a touch driver, which drives the touchscreen very well.

So I spent a bunch of time getting to know the Nerves library for InputEvent (very neat, had no idea, so much potential in there) and trying to hack the touch driver to be a mouse driver instead. I dare say I got fairly close. But then I had to actually work for a living. And that's where that foray ended. For now. IT got the ol' juices going though. If you've any interest in running with this, let me know and I'll point you in all the best directions. Probably ;)

The Vue from here is pretty good

Ye olde secret project demanded a frontend of significant complexity and high UX fidelity. So I figured I'd pick a framework. I've been wanting to do a Redux or Vuex thing for a bit. So now I have a Vue project on my hands. Because honestly React just seems like it offers less of a coherent whole. But I haven't gone deep into figuring out the differences. Generally I've had a better experience trying to get started with Vue & friends than trying to get started with React & friends.

It's been fine. I'm not a big fan of the dependencies, the infinite build tool configs or whatever. But the Vue project generator set most things up in a way I can largely follow. We had to fight some more when I wanted to add some specific testing things, maybe I elected to not include those. I don't recall at this point. What I will say is that I'm getting used to ES-whatever-the-version-is-now and a bunch of the modern notation is very useful, quite concise.

Feels good to be getting more practice in a current-generation JS code-base because I felt a bit old there for a bit. I don't hate it. I like Vue conceptually, I've enjoyed how it gets out of the way mostly when I want to figure out a component. I enjoy the single file component thing. I have my concerns about the way the JS ecosystem works. But it is currently on my good side and I will try to keep up to date enough that it stays there.

If you love JS and find it the best thing you've ever worked with. Please do take this for what it is, just another techie that prefers other things. Do your thing.


So that's a brief update on what I've been up to. The current secret project should lead to quite a few more posts over time. But I also have to build the damn thing. Stay strong out there and use the source.

Underjord is a 4 people team doing Elixir consulting and contract work. If you like the writing you should really try the code. See our services for more information.

Note: Or try the videos on the YouTube channel.