Skip to content

Instantly share code, notes, and snippets.

@cjbell
cjbell / Gemfile
Created October 21, 2013 21:45
Sir Trevor Image Uploader (Rails + Carrierwave)
# Upload gems
gem "carrierwave"
gem "mini_magick", "~> 3.3"
gem "fog", "~> 1.3.1"
defmodule Monitoring.Decorator do
@moduledoc """
`Decorator` functions for doing monitoring.
"""
use Decorator.Define, [measure: 0, measure: 1]
alias Monitoring.Statix
require Logger
@cjbell
cjbell / plugs.ex
Last active March 9, 2018 23:08
Authorization Plugs
# Usage in a controller
plug :load_and_authorize, [
params: "account_id",
loader: &Accounts.get_account/1,
policy: AccountPolicy,
assign: :account
] when action in [:index]
# The plugs themselves

Keybase proof

I hereby claim:

  • I am cjbell on github.
  • I am cjbell (https://keybase.io/cjbell) on keybase.
  • I have a public key ASByIAdUbSnPWd2v7tOLX7dqM8v6XCcQxGY3Hfb5wTcL7Ao

To claim this, I am signing this object:

defmodule MyApp.PostController do
use MyApp.Web, :controller
import MyApp.Controllers.Helpers # this will bring in all of the helper methods into this controller
end
defmodule MyApp.Web do
# ... Other lines removed for brevity
def controller do
quote do
use Phoenix.Controller
alias MyApp.Repo
import Ecto.Model
import Ecto.Query, only: [from: 2]
defmodule MyApp.Controllers.Helpers do
import Plug.Conn
import Phoenix.Controller
def render_blank(conn) do
conn
|> send_resp(204, "")
end
def render_error(conn, status, opts) do
defmodule Shop.Order do
use Shop.Web, :model
schema "orders" do
field :email, :string
has_one :address, Shop.Address
timestamps
end
@cjbell
cjbell / .bowerrc
Last active January 2, 2016 19:59
Bower + Rails
{
"directory": "vendor/assets/components"
}
@cjbell
cjbell / gist:7912092
Created December 11, 2013 15:13
Simple grid functions
@function grid-calc($n, $g: 12) {
@return ($n / $g) * 100%;
}
// 12 column grid
@for $i from 1 through 12 {
%grid-#{$i}-of-12 { width: grid-calc($i); }
}