Image for post
Image for post

There’s been many times when I’ve just wanted to add a simple JSON endpoint to an app to, expose a service, or process webhook events, without the overhead of a full framework. Let’s see how easy it is to build a production ready endpoint with Plug, using Erlang’s Cowboy HTTP server.

Plug is:

1. A specification for composable modules between web applications

2. Connection adapters for different web servers in the Erlang VM

If you’re coming from Ruby/Rails, think Rack, from Node, think Express, et al. …

Introduce Null Object is a great refactoring tool when you find yourself checking for nil too often. nil checks are often signs of much larger problems, as it violates Tell, Don’t Ask, and results in defensive, bug prone programming. Let’s take a look at a simple example of refactoring nil checks:

This Movie class is incredibly defensive, it goes to great lengths to ensure its account actually exists. Why should that responsibility fall on Movie? It would be much better for Movie to just assume it has an account OR something resembling an account. Let’s Introduce Null Object:

We have gotten rid of all conditions defending against nil and introduced one that always returns an Account like…

Extract Method can be used when you have several expressions, a code fragment, that can be grouped together. Even if there is one expression that could be better explained with a well thought out method name, it’s still a good move.

Let’s use Extract method on the Invoice#print method:

The method before refactoring looks like:

def print
# print line items
line_items.each do |line_item|
puts "#{}: #{line_item.price}"
# print subtotal
puts "Subtotal: #{line_items.sum(&:price)}"

Often times, if you see comments explaining what a code fragment does, it’s a smell indicating there is a method to be extracted.

The method after refactoring looks…

Let’s look at another simple yet powerful refactoring method, Replace Temp with Query. You can use this when you have a temporary variable holding the result of an expression. I will reach for this when temporary variables add too much to a method’s size/complexity, or when the result of an expression needs to be used in other methods.

Let’s use Replace Temp with Query in the Movie#total_price method.

The method before refactoring looks like:

def total_price
# Temp variables holding expressions
tax = price * TAX_PERCENTAGE
discount = price * (discount_percentage / 100.0)
price + tax - discount

The method after refactoring looks…

Let’s take a look at a simple way to add clarity to your ruby methods. Extract Variable or Introduce Explaining Variable, it’s probably one of the least invasive refactoring methods. Don’t let the simplicity fool you though, any clarity or explicitness gained is well worth the change.

Use Extract Variable when you have complex expressions grouped together in a method. It’s better to describe your expressions as clearly, and IMO, as verbosely as needed.

Let’s use Extract Variable in the Movie#total_price method.

The bad version looks like:

def total_price
price + (price * TAX_PERCENTAGE) - (price * (discount_percentage / 100.0)) …

Image for post
Image for post

I recently launched a side project I’ve been working on, Syndicate App, a simple tool to automate email arrival to your inbox. It acts as an intermediary between your actual inbox and anything that sends email. You can think of it as a mask for you personal email with a bit of automation on top.

Creating Rules

Rules consist of a condition and a series of actions, whey your rule is run, all actions associated will be applied to the inbound email, then forwarded along to your real inbox.

Image for post
Image for post
A Rule in Syndicate App

Postponing Emails

I enjoy signing up for newsletters. The problem I had with this is, I’d always receive emails first thing in the morning, or at some point during my work day when I just didn’t have time to read them. Even though my mail client has a “snooze” feature, it has to be done after receiving the email, getting notified, and distracted. Now, I use my Syndicate App email address to sign up for everything, I postpone every newsletter until after my work day. …

Image for post
Image for post
Deploying Elixir Apps With Dokku

With many methodologies out there for deploying elixir apps, it’s hard to choose a simple way to get your app online quickly. Enter Dokku, an open source PaaS, a Docker based mini Heroku you can host yourself. Dokku allows you to easily deploy elixir (and many other types of apps) with the ease of Heroku at a fraction of the cost.

This guide assumes you are familiar with creating droplets, and configuring DNS on Digital Ocean. A familiarity with application containerization a la Docker will also be helpful, though not required.

We will walk through getting up and running in five…

Image for post
Image for post
Simple Mail Transfer Protocol

Let’s see just how simple SMTP is with elixir/erlang. I began experimenting with this mostly as a learning tool to get more familiar with elixir/erlang, I’m also trying to get better at documenting my learning. I will preface this post with that, I am no expert, so any suggestions or recommendations are welcome.

What Is SMPT?

Simply put, it’s a text based protocol in which mail is sent and received by issuing a few simple text commands. Typically this connection is made over TCP. You can think of an SMTP session as writing a letter, you need an envelope that defines who the message is for, who it’s from, and also to hold the message you wish to send. In addition, you can include extra meta information in the form of headers. …

The engineering team at ConvertKit has spent the last few months building, iterating, and refining Visual Automations to give content creators even more powerful tools to grow their business.

While many aspects of this feature greatly changed over time, sometimes near full re-writes took place, there is this core philosophy that allowed us to build upon a solid foundation. It’s called the Graph Theory.

The tl;dr of Graph Theory

A Visual Automation at it’s core is just a graph. A graph in CS (computer science) is made up of vertices, nodes, or points (we’ll call them nodes) connected by edges, arcs, or lines (we’ll call them edges). …


Jon Lunsford

Engineer @convertkit, programming enthusiast, father, and musician

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store