Skip to content

Instantly share code, notes, and snippets.

defmodule Test do
  def test(a, opts \\ []) when is_list(opts) do
    with opts <- opts |> Enum.into(%{foo: :a}) do
      test(a, opts)
  def test(a, opts) do
defmodule Test do
  def test() do
    IO.inspect "unreachable" 
    _ex -> IO.inspect("exception caught")
defmodule VanillaTest do
  def foo(%{arg: arg}) do
    IO.inspect("foo/1 with map called: #{arg}")
  def foo(arg) do
    IO.inspect("implementation function foo/1 called: #{arg}")
defmodule MyGraph.Middlewares.ResolutionWithErrorReporting do
@moduledoc """
Middleware to handle application errors and exceptions
require Logger
@behaviour Absinthe.Middleware
@doc """
Call this on existing middleware to replace instances of

Context: batch queries constructed using data from the context

Currently, dataloader/3 helper accepts only statically defined args.

This means we cannot use the dataloader helper to use data from the Absinthe.Resolution to build the batch key.

We can do this directly:

field :is_favorited, non_null(:boolean),

This is a work in progress.

Domain and Persistence Separation

Our primary motivation for this architecture is separating Domain and Persistence concepts.

  1. When Domain and Persistence logic are mixed together in ActiveRecord Models, the resulting code is hard to reason about, difficult to test well, and resists change.
  • AR Callbacks are a hellish way to manage domain logic
  • Managing different validation contexts is not straightforward
  • There is no clear Domain API (everything is a Model#save side effect)


#!/usr/bin/env ruby
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)

Use a glob route at the bottom of your scopes to catch invalid routes

# config/routes.rb
Rails.application.routes.draw do
  # ... all your scopes and routes
  match "(*any)", to: "application#render_not_found", via: :all

Heroku DNS

For Heroku to receive traffic at the apex domain ( Your DNS provider must support ANAME / ALIAS resolution for a hostname ( to the apex domain.

GoDaddy does not support this, you can only set up an A record to a static IP address for the apex.

They provide domain forwarding, but this does not work for HTTPS, so requests to will timeout. Their domain forwarding service will only work for forwarding from

If you're using GoDaddy, it is recommended to transfer or switch name servers to a different service (e.g. Namecheap, DNSimple, etc).

eprothro / index.html.haml
Last active December 12, 2019 17:01
snippets from Materialize starter template from
%html{lang: "en"}
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%meta{content: "width=device-width, initial-scale=1, maximum-scale=1.0", name: "viewport"}/
%title Starter Template - Materialize
%link{href: "", rel: "stylesheet"}/
%link{href: "css/materialize.css", media: "screen,projection", rel: "stylesheet", type: "text/css"}/
%link{href: "css/style.css", media: "screen,projection", rel: "stylesheet", type: "text/css"}/