Raw Syntax

The stuff programs are made of

Elixir From a Ruby Point of View

Permalink

There has been plenty already written about Elixir, but I'm not yet convinced it is a silver bullet. However, I do think it is a useful tool when used in conjuction with existing ruby applications. In particular it can be used when speed or scaling ability is of critical importance.

What follows are a few examples of where Elixir could be used in a pre-existing ruby codebase.

API

Given an existing application such as an API written in Ruby, an Elixir backend can be proxied in and used for certain routes where speed or scaling is critical. An easy way to get started would be to replace a simple read only Ruby endpoint with Elixir.

Over time the entire Ruby based API could be replaced entirely with Elixir.

Background Workers

It is arguable that Rails' strength lies in its easy use of gems and wrangling the web tier with relative ease. Background workers aren't necessarily a reason to pick Rails over another framework. In some codebases background workers are separated entirely from the web tier application code.

One way to try out Elixir is having background jobs that get queued in Ruby, but then get executed by Elixir based workers. In fact, Elixir has a sidekiq compatible worker library, which would allow each worker to be ported over to Elixir one by one, while existing Ruby workers peacefully coexist along side Elixir workers.

Slides

These two use cases allow for a trial of Elixir without having to build an entire application in it. I recently gave a talk on using Elixir from a Ruby point of view. The slides are below.

Elixir with Ruby

App Store Adventures

Permalink

Recently (in March) I took on a side project. My wife is nearing the end of her Family Medicine residency, however in talking with her I learned about a need for an app. The ACGME has requirements that residents in Family Medicine must have a certain number and type of patient visits completed to finish residency. For example one such requirement is performing 40 deliveries.

Where the app comes in is that it provides a simple way to log patient encounters and keep track of these metrics. After doing a quick search on the App Store and finding that such an app didn't already exist, I figured I could write one pretty easily. Though I don't have native app dev skills (Obj-C, Java) there are quite a few frameworks that allow developers to write JavaScript instead: Appcelerator, Ionic Framework, Phonegap etc.

Compatible .ruby-version With Rbenv Aliases

Permalink

In the past I've worked on projects where the .ruby-version checked into git specifies a ruby version not recognized by rbenv. Typically this can happen when the ruby version is specified with patch version while rbenv omits it.

Consider a .ruby-version file containing 2.1.3p242. This version is listed as 2.1.3 by rbenv (while RVM and others may list it differently), and it isn't recognized due to the patch version (though the version in rbenv is actually 2.1.3p242). There's a plugin called rbenv-aliases that addresses this problem.

You can install the plugin with the following commands:

mkdir -p ~/.rbenv/plugins
git clone git://github.com/tpope/rbenv-aliases.git \
~/.rbenv/plugins/rbenv-aliases

Then, running the command:

rbenv alias 2.1.3p242 2.1.3

will cause rbenv to recognize 2.1.3p242 and set the ruby version to 2.1.3.

However, this plugin must be used with caution. You could say rbenv alias 2.1.3 1.8.7, which is a lie! The plugin comes with a command for removing any incorrect aliases rbenv unalias 2.1.3.

Comparing Plist Files on OSX

Permalink

I recently had a problem with some of my keyboard shortcuts not working on OS X. I ended up moving the original plist (Property List) file, rebooting, and configuring the settings manually. This fixed the problem but left me wondering why the keyboard shortcut broke in the first place. Computers don't just break. There has to be a reason.

I tried to diff the two plist files and I got an unhelpful message similar to binary files differ. Having been on OS X a while, I know that plists can be saved as text or binary. In this case I simply used the open command to load the files into XCode, exported them as Property List XML, and then was able to diff them as normal text files.

Why Binary?

As an Emacs user, I was still confused as to why plists would ever be saved as binary. This just means I can't edit them with Emacs (out of the box anyway). Referring to the man page for plist it turns out the reason is performance:

The property list programming interface allows you to convert hierarchically structured combinations of these basic types to and from two formats: standard XML and an optimized, opaque binary format.

You can also use plutil to convert between binary and text. For example:

plutil -convert xml1 com.apple.symbolichotkeys.plist

Which converts the file to another format in place.

RSpec Suite Runs Twice?

Permalink

I worked on a rails project recently that had a peculiar problem. When running the specs via rake spec or rspec the whole suite would appear to run twice. I began digging around in spec/spec_helper.rb to try to figure out how RSpec could be configured to run twice instead of once. I also went to google and stack overflow and didn't find much.

Eventually I saw that there was both a .rspec file with configuration options and a few of the same configuration options repeated in the spec_helper. Once I removed the duplication (in particular the format documentation option was specified in both places), the RSpec suite output only appeared once. I did a little more digging and found that the test suite was not running twice, but rather the output was getting printed twice.

The easiest way to avoid this kind of problem is to decide on a project level to keep RSpec options in spec/spec_helper.rb or .rspec, but not both.