Generating an Erlang sys.config from an Elixir config.exs

This post describes Erlang’s sys.config and the equivalent config.exs in Elixir and how you can convert from config.exs to sys.config (the link is to a script that does this). I also talk a little about how you could use this to deploy Elixir projects using Chef. Erlang’s sys.config Erlang releases use a file called sys.config for configuration values. This is the place to put your OTP applications’ configuration in addition to configuration for system applications like the logger and sasl. »

Integration Testing a JSON API in Phoenix

TL;DR To do integration testing in Phoenix, first enable the app’s content serving in its config, then use an HTTP client library (I use HTTPoison below) to make requests. The source code corresponding to this post is on my github at Introduction (plus a little discourse on testing) I like integration-level testing, especially for web apps and doubly so for APIs. A good integration test suite can help you work out usability issues with your API, give you confidence that your deployment is stable, and provide a springboard for troubleshooting issues down the road. »

Storing state in Elixir with processes

I’ve been getting into Elixir lately. I’m still learning, and one thing that helps me learn new languages is to take a problem I’ve solved in another language and solve it in the new language. A few months ago I wrote about storing state in erlang with processes and I thought it would be an interesting exercise to convert that discussion to Elixir. I’ll start out with a solution that’s too simple to be useful. »

Dan Swain

Storing state in Erlang with processes

State is how we make programs do non-trivial things. If we’re writing a video game, one of its states might be a count of the number of bad guys that have been defeated. In most programming languages, we would accomplish this by assigning the count to a variable and then updating the value each time a new bad guy is defeated. Erlang, however, doesn’t allow us to change the value of a variable once it has been set (single assignment). »

Dan Swain

New Blog Design

I think a lot of developers have this intention of creating and maintaining a blog. I started this one over a year ago and have published a whopping two posts. I’d call it a success! After those two posts, I felt it was obviously time for a redesign. The main purpose of this post is to give credit to some people that contributed in one way or another to this redesign. »

Erlang: First element in a list that matches some condition

The short answer: first(L, Condition, Default) -> case lists:dropwhile(fun(E) -> not Condition(E) end, L) of [] -> Default; [F | _] -> F end. 3 = first([0, 1, 2, 3, 4, 5], fun(E) -> E > 2 end, 0). 0 = first([0, 1, 2, 3, 4, 5], fun(E) -> E < 0 end, 0). Thanks to Odobenus Rosmarus, who provided this solution to my Stack Overflow question. The long answer: I recently needed an Erlang function that looks through a list and returns the first element matching some condition, without looking through the rest of the list. »

Dan Swain

Opening a new instance of Aquamacs from the command line

The short answer: #!/bin/bash open -na Aquamacs $* The long answer: If you’ve used the OS X command line for any length of time, you’ve probably (hopefully) come across the open command. Its job is (shockingly enough) opening files and applications using Finder. It works for files: $ open index.html opens index.html in your browser. It also works for applications: $ open -a Mail opens It also works for opening files with an application: »