initial commit

This commit is contained in:
Marc Planard 2022-04-07 19:28:36 +02:00
parent d91e8e7dcd
commit 836e828371
53 changed files with 2142 additions and 0 deletions

36
lib/demo/application.ex Normal file
View file

@ -0,0 +1,36 @@
defmodule Demo.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
# Start the Ecto repository
Demo.Repo,
# Start the Telemetry supervisor
DemoWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Demo.PubSub},
# Start the Endpoint (http/https)
DemoWeb.Endpoint
# Start a worker by calling: Demo.Worker.start_link(arg)
# {Demo.Worker, arg}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Demo.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
DemoWeb.Endpoint.config_change(changed, removed)
:ok
end
end

15
lib/demo/funcs.ex Normal file
View file

@ -0,0 +1,15 @@
defmodule Funcs do
# Naive, slow and buggy implementation:
def fib(0), do: 0
def fib(1), do: 1
def fib(n), do: fib(n-1) + fib(n-2)
# Fast version:
# def fib(n) when not is_number(n) or n < 0, do: raise("arg!")
# def fib(n), do: fib(0, 1, n)
#
# def fib(a, b, 0), do: a
# def fib(a, b, n), do: fib(b, a+b, n-1)
end

10
lib/demo/funcs.ex~ Normal file
View file

@ -0,0 +1,10 @@
defmodule Funcs do
def fib(n) when not is_number(n) or n < 0, do: raise("arg!")
def fib(n), do: fib(0, 1, n)
def fib(a, b, 0), do: a
def fib(a, b, n), do: fib(b, a+b, n-1)
end

3
lib/demo/mailer.ex Normal file
View file

@ -0,0 +1,3 @@
defmodule Demo.Mailer do
use Swoosh.Mailer, otp_app: :demo
end

5
lib/demo/repo.ex Normal file
View file

@ -0,0 +1,5 @@
defmodule Demo.Repo do
use Ecto.Repo,
otp_app: :demo,
adapter: Ecto.Adapters.SQLite3
end