Skip to content

Instantly share code, notes, and snippets.

View stats_decorator.ex
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 Mar 9, 2018
Authorization Plugs
View plugs.ex
# 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
View keybase.md

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:

View controller.ex
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
View web.ex
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]
View helpers.ex
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
View models.ex
defmodule Shop.Order do
use Shop.Web, :model
schema "orders" do
field :email, :string
has_one :address, Shop.Address
timestamps
end
View html-output.html
<div class="article-43afx flex-3aS32 vertical-2asd4 centered-1xa1d">
</div>
View rails.html.erb
<% styles = import_css("components/article") %>
<div class="<%= styles[:article] %>">
<!-- ... more -->
</div>
View react-css-module.js
import articleStyles from '../../styles/components/article';
class Article extends Component {
render() {
return (
<div className={articleStyles.article}>
// ... more
</div>
);
}