Skip to content

Instantly share code, notes, and snippets.

@chrismccord
chrismccord / upgrade.md
Last active January 28, 2016 03:20
Phoenix 1.1.1 to 1.1.2 upgrade instructions

Phoenix 1.1.1 to 1.1.2 upgrade instructions

Optional upgrade for new brunch features

Update your phoenix deps

def deps do
  [{:phoenix, "~> 1.1.2"},
  ...]
end
@chrismccord
chrismccord / gist:cf51346c6636b5052885
Last active January 17, 2016 12:11
Phoenix 0.9 to 0.10.0 upgrade instructions

form_tag, link, CSRF changes

Plug 0.10.0 moves CSRF tokens from cookies back to sessions. To avoid future bumps on the road, a get_csrf_token/0 function has been added to controllers and imported into views. Update all your csrf token reference code to use the new function. Additionally, form_tag and link helpers have been added that will inject the csrf token for you automatically. You should transition to these new functions where possible, ie:

  <%= form_tag("/hello", method: :post) %>
    ... your form stuff. csrf is inject for you
  </form>
@chrismccord
chrismccord / gist:8640170
Created January 26, 2014 22:15
Plug use
defmodule Router do
use Phoenix.Router, port: 4000
use Plug.Static, mount: "/public"
use Plug.EncryptedSession, secret: "203802482048204820"
get "pages/:page", PagesController, :show, as: :page
get "files/*path", FilesController, :show
get "profiles/user-:id", UsersController, :show
resources "users", UsersController
@chrismccord
chrismccord / gist:8446557
Last active January 3, 2016 09:59
Nested Macro
defmodule Example do
defmacro __using__(_options) do
quote do
Module.register_attribute __MODULE__, :attr, accumulate: true, persist: false
import unquote(__MODULE__)
end
end
defmacro append(attr) do
@chrismccord
chrismccord / gist:7806146
Created December 5, 2013 14:42
Elixir 0.11 record bug
# This worked on 0.10
defmodule Records do
defmacro __using__(_) do
quote do
defrecord A, name: "chris"
defrecord B, id: nil, nested: A.new
end
end
@chrismccord
chrismccord / gist:6349128
Last active December 21, 2015 18:39
Access protocol only for specific record
defrecord User, email: nil
defmodule Access.User do
def access(record, attr), do: apply(elem(record, 0), attr, [record])
end
user = User.new(email: "foo@bar.com")
iex> user[:email]
"foo@bar.com"
@chrismccord
chrismccord / gist:6000108
Created July 15, 2013 13:54
Wrap eredis connection
defmodule ERedis do
@name :eredis_connection
def start do
{:ok, pid} = :eredis.start_link
:global.register_name(@name, pid)
end
def connection do
@chrismccord
chrismccord / gist:5519310
Last active December 17, 2015 00:11
"I have a table that shows the 10 most recent entries and then via Sync new ones get added. Is there an easy way to remove existing entries to keep the total at 10?"
# Assuming your partial is named 'list_row' and your model is 'Todo'
class Sync.TodoListRow extends Sync.View
maxRows: 10
afterInsert: ->
$rows = @$el.siblings("tr")
$rows.first().remove() if $rows.length > @maxRows
# remove any bad refs
git remote prune origin
# pipe into bash and auto-delete any branches that have been merged into master!
git log master --pretty=format:'%d' | grep '^ (origin' | tr -d ' ()' | sed 's/origin\//git push origin :/'
@chrismccord
chrismccord / phoenix showdown rackspace onmetal io.md
Created November 17, 2015 14:58 — forked from omnibs/phoenix showdown rackspace onmetal io.md
Phoenix Showdown Comparative Benchmarks @ Rackspace

Comparative Benchmark Numbers @ Rackspace

I've taken the benchmarks from Matthew Rothenberg's phoenix-showdown, updated Phoenix to 0.13.1 and ran the tests on the most powerful machines available at Rackspace.

Results

Framework Throughput (req/s) Latency (ms) Consistency (σ ms)