Skip to content

Instantly share code, notes, and snippets.

@chrismccord
chrismccord / 1.js
Created April 7, 2016 02:50 — forked from net/1.js
Adding Bootstrap to Phoenix using NPM
// 1. Add Bootstrap as a dependency in package.json
{
...
"dependencies": {
...
"bootstrap": "~3.3.6"
}
}
@chrismccord
chrismccord / gist:be5c3cf8f89b252122ba
Last active January 2, 2018 01:26
Phoenix Gulpfile.coffee (Sass/CoffeeScript)
# Gulpfile.js
# // Note the new way of requesting CoffeeScript since 1.7.x
# require('coffee-script/register');
# // This bootstraps your Gulp's main file
# require('./Gulpfile.coffee');
# assets
# ├── Gulpfile.coffee
# ├── Gulpfile.js
# in your app supervisor
:phx_dyn_dispatch = :ets.new(:phx_dyn_dispatch, [:named_table, :bag, :public])
defmodule DynamicDispatch do
def register(group, plug, opts) do
true = :ets.insert(:phx_dyn_dispatch, {group, plug, opts})
end
def unregister(group, plug) do
@chrismccord
chrismccord / postgres-upgrade-recipe.sh
Created October 6, 2015 11:14 — forked from eoinkelly/postgres-upgrade-recipe.sh
Upgrade Postgres to 9.4 using Homebrew on Mac OSX
#!/bin/bash
# This script can be used in "run & hope" mode or you can use it as a recipe to
# do things manually - you probably want the latter if you really care about
# the data in your databases.
# Happy hacking
# /Eoin/
# Tell bash to stop if something goes wrong
set -e
@chrismccord
chrismccord / gist:6298006
Last active January 8, 2017 21:47
Rails callback/listener approach to shared service object behavior from controllers
class CommentsController < ApplicationController
def create
CommentCreator.new(current_user, params[:comment], self).create
end
private
def create_successful(comment)
@chrismccord
chrismccord / gist:c24b2b516066d987f4fe
Last active April 24, 2016 23:17
Phoenix 0.6.x to 0.7.0 Upgrade Instructions

How to upgrade to Phoenix from 0.6.x to 0.7.0.

  1. 0.7.0 depends on Plug HEAD, so you'll need to include plug in your mix deps until the next plug release:
{:plug, github: "elixir-lang/plug", ref: "7040c89cb4cf1f1c6afdee379e5982a07d77a6c3"}
```

  1. The `Pheonix.Controller` functions html/2, json/2, text/2, redirect/2 and render/3 no longer halt automatically. *Important*: You must now explicity call `halt/1` yourself if you want to stop invoking further plugs after calling these functions. This is improtant for auth filtering plugs, ie:

```elixir
@chrismccord
chrismccord / gist:b3975ba356dba902ec88
Last active February 12, 2016 09:52
Phoenix Upgrade Instructions 0.11.x 0.12.0

Build-embedded and start permanent

Elixir v1.0.4 ships with two new important options for new projects. For projects generated prior to Elixir 1.0.4, add these options to your project entries in mix.exs:

build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod

Asset Digests (optional)

A new phoenix.digest task is now inluded which digests and compress static files and can be used during deploy. It also integrates with the static_path helper to render the proper asset paths from the manifest.

@chrismccord
chrismccord / gist:3603fd2735019f86c74b
Last active February 12, 2016 09:52
Phoenix 0.10 to 0.11.0 upgrade instructions

mix.exs

Add these functions to the bottom of mix.exs:

  # Specifies which paths to compile per environment
  defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
  defp elixirc_paths(_),     do: ["lib", "web"]
@chrismccord
chrismccord / gist:0a3bf5229801d61f219b
Last active February 12, 2016 09:52
Phoenix Upgrade Instructions 0.12.x 0.13.0

Deps

First, clean your deps to avoid phoenix_html conflicts:

$ mix deps.clean phoenix --all

Next, bump phoenix:

{:phoenix, "~> 0.13"},

@chrismccord
chrismccord / gist:57805158f463d3369103
Last active February 12, 2016 09:52
Phoenix Upgrade Instructions 0.13.x 0.14.0

First, bump your phoenix in mix.exs:

def deps do
  [{:phoenix, "~> 0.14"}, ...
end

phoenix_html

Update your phoenix_html version to 1.1.0 in mix.exs: