sudo pacman -R postgresql postgresql-libs
sudo rm -rfv /var/lib/postgres
defmodule Hello do | |
def hello(name,age) when is_kid(age) do | |
IO.puts "Hello Kid #{name}" | |
end | |
def hello(name,age) when is_adult(age) do | |
IO.puts "Hello Mister #{name}" | |
end | |
def is_kid age do | |
age < 12 | |
end |
defmodule MyGuards do | |
defmacro is_kid age do | |
quote do: unquote(age) < 12 | |
end | |
defmacro is_adult age do | |
quote do: unquote(age) > 18 | |
end |
defmodule EtsKeys do | |
def keys(table_name) do | |
first_key = :ets.first(table_name) | |
keys(table_name, first_key, [first_key]) | |
end | |
def keys(_table_name, '$end_of_table', ['$end_of_table'|acc]) do | |
acc | |
end | |
def keys(table_name, current_key, acc) do |
defmodule TcpServer do | |
use GenServer | |
def start_link() do | |
ip = Application.get_env :tcp_server, :ip, {127,0,0,1} | |
port = Application.get_env :tcp_server, :port, 6666 | |
GenServer.start_link(__MODULE__,[ip,port],[]) | |
end | |
def init [ip,port] do |
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
# project_root/.formatter.exs | |
[ | |
# functions to let allow the no parens like def print value | |
locals_without_parens: [hello: 2, get_user: 1, addtion: *], | |
# files to format | |
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"], |
# Elixir V1.6 | |
defmodule Array do | |
@moduledoc """ | |
A collective data module with some helpful functions | |
""" | |
@doc """ | |
Flattens the given list of nested lists. By default it gives out the unique list of items by removing the duplicates | |
inside. |
# stack.ex | |
defmodule Stack do | |
use GenServer | |
# server callbacks | |
def init(args), do: {:ok, args} | |
#used to handle synchronous requests | |
def handle_call(:get, _from, state) do |
defmodule Bank do | |
use GenServer | |
alias Bank.Cache | |
@moduledoc """ | |
Documentation for Bank. | |
""" | |
# client API | |
def start_link(cache_pid) do | |
GenServer.start_link(Bank, cache_pid, name: Bank) | |
end |