This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create(order_params, customer, auth) do | |
| with {:ok, order} <- validate_order(order_params, customer), | |
| {:ok, order} <- validate_tour_shipment_in_backend(order, auth), | |
| {:ok, order} <- Repo.insert(order) do | |
| {:ok, order} | |
| else | |
| {:error, changeset} -> {:error, changeset} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @doc """ | |
| ## Examples | |
| iex> {:ok, pid} = Agent.start_link(fn -> 42 end) | |
| iex> Agent.get_and_update(pid, fn(state) -> {state, state + 1} end) | |
| 42 | |
| iex> Agent.get(pid, fn(state) -> state end) | |
| 43 | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @type job_name :: String.t | atom | |
| @spec benchmark(Suite.t, job_name, fun, module) :: Suite.t | |
| def benchmark(suite = %Suite{scenarios: scenarios}, job_name, function, printer \\ Printer) do | |
| #... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def new_changeset(model, params \\ %{}) do | |
| model | |
| |> cast(params, ~w(name username)) | |
| |> validate_required(~w(name username)) | |
| |> unique_constraint(:username) | |
| |> validate_length(:username, min: 1, max: 20) | |
| end | |
| def registration_changeset(model, params) do | |
| model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iex(13)> user = Repo.get_by(User, name: "Homer") | |
| iex(14)> user.videos | |
| #Ecto.Association.NotLoaded<association :videos is not loaded> | |
| iex(17)> user = Repo.preload(user, :videos) | |
| iex(18)> user.videos | |
| # all the videos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def new(conn, _params) do | |
| changeset = User.new_changeset(%User{}) | |
| render conn, "new.html", changeset: changeset | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with {:ok, record} <- validate_data(params), | |
| {:ok, record} <- validate_in_other_system(record), | |
| {:ok, record} <- Repo.insert(record) do | |
| {:ok, record} | |
| else | |
| {:error, changeset} -> {:error, changeset} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config | |
| |> Benchee.init | |
| |> Benchee.system | |
| |> Benchee.benchmark("job", fn -> magic end) | |
| |> Benchee.measure | |
| |> Benchee.statistics | |
| |> Benchee.Formatters.Console.output | |
| |> Benchee.Formatters.HTML.output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mp3_byte_size = (byte_size(binary) - 128) | |
| << _ :: binary-size(mp3_byte_size), id3_tag :: binary >> = binary | |
| << "TAG", | |
| title :: binary-size(30), | |
| artist :: binary-size(30), | |
| album :: binary-size(30), | |
| year :: binary-size(4), | |
| comment :: binary-size(30), | |
| _rest :: binary >> = id3_tag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Patterns do | |
| def greet(%{name: name, age: age}) do | |
| IO.puts "Hi there #{name}, what's up at #{age}?" | |
| end | |
| def greet(%{name: "José Valim"}) do | |
| IO.puts "Hi José, thanks for elixir! <3" | |
| end | |
| def greet(%{name: name}) do | |
| IO.puts "Hi there #{name}" | |
| end |