This file contains 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 MyTwitterWeb.CounterLive do | |
use MyTwitterWeb, :live_view | |
def render(assigns) do | |
~H""" | |
<div> | |
<.button phx-click="dec">-</.button> | |
<%= @counter %> | |
<.button phx-click="inc">+</.button> | |
</div> |
This file contains 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 Pagination do | |
import Ecto.Query | |
alias Snippets.Repo | |
# | |
# ## Example | |
# | |
# Snippets.Snippet | |
# |> order_by(desc: :inserted_at) | |
# |> Pagination.page(0, per_page: 10) | |
# |
This file contains 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 ManyToManyHelper do | |
defmacro __using__(_opts) do | |
quote do | |
import Ecto.Query, only: [from: 2] | |
import unquote(__MODULE__) | |
end | |
end | |
defmacro many_to_many_params(opts) do | |
association = Keyword.fetch!(opts, :association) |
This file contains 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 MyApp do | |
def split_and_reverse(string) do | |
string | |
|> String.split() | |
|> Enum.reverse() | |
end | |
end | |
"This is a test" | |
|> MyApp.split_and_reverse() |
This file contains 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
// Code handling the card payment | |
const payWithCard = function (stripe, card, clientSecret, liveView) { | |
stripe | |
.confirmCardPayment(clientSecret, { | |
payment_method: { | |
card: card, | |
}, | |
}) | |
.then(function (result) { | |
if (result.error) { |
This file contains 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
[info] GET /dashboard/tos_acceptance/edit | |
[debug] QUERY OK source="users" db=0.4ms | |
SELECT u0."id", u0."first_name", u0."last_name", u0."address", u0."city", u0."country", u0."nationality", u0."email", u0."company_name", u0."zip_code", u0."region_code", u0."phone_number", u0."date_of_birth", u0."description", u0."facebook_uid", u0."google_uid", u0."coordinates", u0."lat", u0."lng", u0."images_group_url", u0."banner_image_url", u0."retrieval_information", u0."encrypted_password", u0."role", u0."reset_password_token", u0."reset_password_sent_at", u0."general_tos_accepted_at", u0."producer_tos_accepted_at", u0."mangopay_user_id", u0."slug", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [2] | |
[debug] Processing with DokkitoWeb.Dashboard.TosAcceptanceController.edit/2 | |
Parameters: %{} | |
Pipelines: [:browser, :dashboard] | |
[info] Sent 200 in 1ms | |
[info] Replied phoenix:live_reload :ok | |
[error] #PID<0.2434.0> running DokkitoWeb.Endpoint (connection #PID<0.2433.0>, stream id 1) terminated | |
Server |
This file contains 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, result} <- do_some_heavy_stuff, | |
{:ok, second_result} <- do_other_stuff(result) do | |
send_email(second_result) | |
else | |
error -> # ... | |
end |
This file contains 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
if result = do_some_heavy_stuff | |
if second_result = do_other_stuff(result) | |
send_email(second_result) | |
else | |
# ... | |
end | |
else | |
# ... | |
end |
This file contains 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 EctoAutoslugField.ForceSlugGeneration do | |
alias EctoAutoslugField.SlugBase | |
defmacro __using__(_opts) do | |
quote do | |
def force_generate_slug(changeset) do | |
opts = [ | |
from: @from, | |
to: @to, | |
always_change: true, |
This file contains 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 DokkitoWeb.AuthController do | |
use DokkitoWeb, :controller | |
# ... | |
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do | |
case Auth.find_or_create(auth) do | |
{:ok, user} -> | |
conn | |
|> put_flash(:info, "Successfully authenticated.") |
NewerOlder