Skip to content

Instantly share code, notes, and snippets.

@miwee
miwee / common_elixir_pitfalls.md
Last active April 20, 2021 07:51
Common Elixir Pitfalls
  • Only nil and false are considered false (falsy values), everything else is considered true (truthy values). The following may surprise those coming from C/Python
iex(1)> x = 0
0
iex(2)> if x do
...(2)>   "True condition matched"
...(2)> else
...(2)>   "False condition matched"
...(2)> end 
@miwee
miwee / rest_client.ex
Created May 19, 2015 08:46
Improved RestClient (HTTPoison based), with support for passing config params as a single map
defmodule RestClient do
require Logger
alias Poison, as: JSON
def get_by_path(config, path, id, params)
when (is_binary(id) or is_integer(id)) and is_list(params) do
get_by_path(config, [path: path, id: id, params: params])
end
def get_by_path(config, path, params)
@miwee
miwee / rest_client.ex
Created May 12, 2015 10:42
Rest Client implementation based on HTTPoison
defmodule RestClient do
require Logger
alias Poison, as: JSON
@baseurl "http://someapi.com"
@username "username"
@password "password"
def get_by_path(path, id, params)
when is_binary(id) or is_integer(id) and is_list(params) do