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
you can use ~W or ~w to convert strings into list. | |
~w""" | |
...> the | |
...> cat | |
...> sat | |
...> """ | |
# ["the", "cat", "sat"] | |
str = "This is Test String" # "This is Test String" | |
~w<#{str}> # ["This", "is", "Test", "String"] |
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 TodoList do | |
use GenServer | |
@moduledoc """ | |
A TodoList add, list, find, update & remove. | |
""" | |
def start do | |
{:ok, state} = GenServer.start_link(__MODULE__, []) | |
state | |
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 Cal do | |
def start do | |
spawn(fn -> loop(0) end) | |
end | |
def view(server_pid) do | |
send(server_pid, {:view, self()}) | |
receive do | |
{:response, value} -> |
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
def index(conn, _params) do | |
conn = conn | |
|> put_resp_content_type("text/csv") | |
|> put_resp_header("content-disposition", "attachment; filename=export.csv") | |
|> send_cunked(200) | |
Repo.transaction fn -> | |
Ecto.Adapters.SQL.stream(Repo, "COPY expensive_report TO STDOUT CSV HEADER") | |
|> Stream.map(&(chunk(conn, &1.rows))) | |
|> Stream.run |