Skip to content

Instantly share code, notes, and snippets.

===> Failed to fetch and copy dep: {git,"git://github.com/DeadZen/goldrush.git",
{tag,"879c69874a"}}
@jeregrine
jeregrine / phoenix-0.15-upgrade.md
Last active August 29, 2015 14:25 — forked from chrismccord/phoenix-0.15-upgrade.md
Phoenix upgrade instructions 0.14.x to 0.15.0

Sockets and Channels

A new socket behaviour has been introduced to handle socket authentication in a single place, wire up default channel assigns, and disconnect a user's multiplex connection as needed.

First things first, create a UserSocket module in web/channels/user_socket.ex and move all your channel routes from web/route.ex to the user socket: (replace MyApp with your application module)

0.14.x - web/router.ex:

defmodule MyApp.Router do
   ...
@jeregrine
jeregrine / config.exs
Created June 5, 2015 15:32
Hackney Config
config :hackney,
mod_metrics: MyApp.Util.HackneyLibratoMetrics
@jeregrine
jeregrine / hackney_librarto.ex
Created June 5, 2015 14:58
Hackney Librato Metrics
defmodule MyApp.Util.HackneyLibratoMetrics do
require Logger
def new(_, _) do
:ok
end
def delete(_name) do
:ok
end
@jeregrine
jeregrine / repo.ex
Created June 5, 2015 14:37
ecto repo logging
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
def log(entry) do
Logger.info(fn ->
[log_time("measure#database.query", entry.query_time, true), log_time("measure#database.queue", entry.queue_time, false)]
end)
super(entry)
end
@jeregrine
jeregrine / task_timeout.ex
Created May 15, 2015 14:44
task timeout catch
results = try do
Task.await(search_task, @timeout)
catch
:exit, {:timeout, {Task, :await, [_, @timeout]}} -> []
end
@jeregrine
jeregrine / Howto.md
Created May 12, 2015 19:37
Setting up Redo and Poolboy for redis connections in Elixir

Then add

worker(Redis, []),

to your supervision tree

defmodule MyApp.CommentView do
use MyApp.Web, :view
@attributes ~W(id name inserted_at)
def render("show.json", %{data: comments}) when is_list(comments) do
for comment <- comments do
render("show.json", data: comment)
end
end
defmodule MyApp.MyModelController do
use MyApp.Web, :controller
plug :action
def show(conn, params) do
render conn, "show.json", data: Repo.get!(MyModel, params[:id])
end
end
@jeregrine
jeregrine / encode.ex
Last active August 29, 2015 14:17
Example
def render("show.json", %{data: data}) do
%{
id: data.id,
name: data.name,
title: String.capitalize!(data.name)
}
end