Today I Learned

TIL, 2018-02-19, Programming Phoenix


  • Gin, Martini: Go frameworks.
  • Plug: Rack for Elixir.
  • Hexdocs are the documentation for Phoenix.
  • mix archive.install to install Phoenix or upgrade to latest version. Reference
  • Ctrl-C during IEx to break out of it.
  • cowboy: Phoenix web server.
  • Controller and View are explicitly separate. They are also separated from the template being shown.
  • Templates: Embedded Elixir (.eex file).
  • Change starting port: dev.exs, HabitsOne.Endpoint, then there is a port section there.
  • Or you can do: PORT=4002 mix phx.server
  • $ gem cleanup to remove stuff. Solves Unresolved specs during Gem::Specification.reset (which usually means there are old gems in the system which may be interfering with your command). Reference
  • Pluralsight Ruby Beyond the Basics:
    • Currying in Ruby.
    • You can do functional things when applying multiple discounts for the report.
    • “What this class does is what this class is.”
    • Functional programming: Composition, referential transparency, and small, specific solutions.

Color Filter

class ColorFilter
  def initialize(color)
    @color = color

  def apply(products) { |p| p.color == @color }

Programming Phoenix

  • mix local.hex to install Hex, the package manager.
  • mix -v to check Phoenix version.
  • mix hello: Creating the app.
  • mix ecto.create: rake db:create?
  • mix phx.server: rails server?
  • config/dev.exs: Edit this thing for the database.
  • iex -S mix phx.server to run the app inside IEx.
  • prod.secret.exs.
  • MIX_ENV environmental variable to switch between prod/dev.
  • This looks really nice:
|> put_flash(:info, "Whoa cool.")
|> put_flash(:error, "Error.")
|> render("world.html", name: 'SWAGG')
  • This is like the part of the Rails boot process/Action Pack:
defmodule Hello.Endpoint do
  user Phoenix.Endpint, otp_app: :hello

  plug Plug.Static,
  plug Plug.RequestId,
  plug PLug.Logger

  plug Plug.Parsers,
  plug Plug.MethodOverride,
  plug Plug.Head

  plug Plug.Session,
  plug Hello.Router
  • This is essentially:
|> router
|> HelloController

How I Rented a Nice Place


  • Umbrella: A way of organizing a project into different standalone modules that depend on each other.
  • $ mix --umbrella rent_bot.
  • HTML parsing library: Floki.
  • HTML requester: HTTPoison.

This project is maintained by daryllxd