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
| # To show hot code uploading, we first need to build a simple phoenix project so we can see it happen in real time. | |
| # Start by making a new phoenix project | |
| $ mix phoenix.new hotcode | |
| # Go into the directory | |
| $ cd hotcode | |
| # Add exrm dependency to mix.exs file | |
| {:exrm, "~> 1.0.3"} |
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
| # The golden trinity of Erlang is the secret sauce behind what makes | |
| # Elixir a strong choice for any backend application and/or system. | |
| # https://tkowal.wordpress.com/2015/10/20/failing-fast-and-slow-in-erlang-and-elixir/ | |
| # The supervision and worker system, commonly referred to as OTP (Open | |
| # Telecom Platform, which has nothing to do with telephony), is what | |
| # gives Erlang/Elixir applications them a robust "self-healing" type | |
| # property that makes them extremely fault tolerant. |
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
| # mix.exs | |
| defmodule RedisRabbitElixir.Mixfile do | |
| use Mix.Project | |
| def project do | |
| [app: :redis_rabbit_elixir, | |
| version: "0.0.1", | |
| elixir: "~> 1.2", | |
| build_embedded: Mix.env == :prod, |
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
| # This demonstrates that, when using async/await, a crash in the task will crash the caller | |
| defmodule Tasker do | |
| def good(message) do | |
| IO.puts message | |
| end | |
| def bad(message) do | |
| IO.puts message | |
| raise "I'm BAD!" | |
| 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
| """ | |
| Given that "Sample.txt" exists and looks like: https://dl.dropboxusercontent.com/u/2736799/learn-elixir/exercises/sample.txt" | |
| """ | |
| {:ok, words} = File.read "Sample.txt" | |
| splitWords = String.split(words, "\n\n") | |
| streamSplitWords = Stream.take_every(splitWords, 2) | |
| |> Stream.filter(&String.first(&1) == "d") |
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
| Imagine you have the following structure: | |
| ```elixir | |
| iex> users = [ | |
| john: %{name: "John", age: 27, languages: ["Erlang", "Ruby", "Elixir"]}, | |
| mary: %{name: "Mary", age: 29, languages: ["Elixir", "F#", "Clojure"]} | |
| ] | |
| ``` | |
| We have a keyword list of users where each value is a map containing the name, age and a list of programming languages each user likes. If we wanted to access the age for john, we could write: |
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 ElixirJobBoard.Plugs.AuthenticateJobPoster do | |
| import Plug.Conn | |
| import Phoenix.Controller, only: [put_flash: 3, redirect: 2] | |
| alias ElixirJobBoard.Repo | |
| alias ElixirJobBoard.User | |
| def init(opts), do: opts | |
| def call(conn, _opts) do |
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 LearningElixir do | |
| use Application | |
| # See http://elixir-lang.org/docs/stable/elixir/Application.html | |
| # for more information on OTP Applications | |
| def start(_type, _args) do | |
| import Supervisor.Spec, warn: false | |
| children = [ | |
| # Define workers and child supervisors to be supervised |
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
| # The call 'Elixir.NAClaims.ClaimAgent':add_claim_field( | |
| # cpid@1::pid(), | |
| # cf@4::#{'__struct__':='Elixir.NAClaims.ClaimField', ...}, | |
| # fd@1::#{'__struct__':='Elixir.NAClaims.FieldDefs.FieldDef', ...}, | |
| # opts@1::any()) | |
| # will never return since the success typing is | |
| # ( | |
| # pid(), | |
| # #{'__struct__':='Elixir.NAClaims.ClaimField', ...}, | |
| # #{'__struct__':='Elixir.NAClaims.FieldDefs.FieldDef', ...}, |
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 Kipatest.AccessToken do | |
| use Kipatest.Web, :model | |
| @type t :: %{__struct__: atom} | |
| @primary_key {:id, Ecto.UUID, autogenerate: true} | |
| schema "access_tokens" do | |
| field :is_valid, :boolean, default: true | |
| field :refresh_token, Ecto.UUID, autogenerate: true | |
| field :expired_at, Timex.Ecto.DateTime |