/.../: Start and end regex delimiters|: Alternation(): Grouping
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
| # https://github.com/eproxus/meck | |
| # add meck as a dependency in mix.exs | |
| defmodule GithubIssuesTest do | |
| use ExUnit.Case | |
| import :meck | |
| setup_all do | |
| new(Issues.GithubIssues) | |
| on_exit fn -> unload 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
| defmodule Math do | |
| def sum_list([head|tail]) do | |
| sum_list(tail, head) | |
| end | |
| def sum_list([head|tail], accumulator) do | |
| sum_list(tail, head + accumulator) | |
| end | |
| def sum_list([], accumulator) 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 CheckDefaults do | |
| def foo(a, b, c \\ 0) do | |
| a+b+c | |
| end | |
| def foo(a, b, c, d \\ 0) do | |
| a+b+c+d | |
| end | |
| end | |
| iex:13: warning: redefining module CheckDefaults |
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 Cool do | |
| @flags [:herp, :derp] | |
| Enum.each @flags, fn flag -> | |
| def valid_flag?(unquote flag), do: true | |
| end | |
| def valid_flag?(flag), do: false | |
| 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
| defmodule VercheckEx do | |
| use Application | |
| require HTTPoison | |
| require Floki | |
| require Timex | |
| use Timex | |
| def fetch_content() do | |
| IO.puts("fetch_content") | |
| receive do | |
| {caller,url,type,i} -> |
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
| def create(conn, %{"stress" => stress_params}) do | |
| changeset = Stress.changeset(%Stress{}, stress_params) | |
| IO.inspect stress_params | |
| {long, lat, type} = {stress_params["long"], stress_params["lat"], stress_params["type"]} | |
| q = from p in Plataforma.Average, | |
| select: p, | |
| where: p.long == ^long and p.lat == ^lat and p.type == ^type | |
| average = Repo.all(q) |> first_or_create | |
| average_params = %Plataforma.Average{"long" => stress_params["long"], | |
| "lat" => stress_params["lat"], |
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
| what = :a | |
| [:a, :a, :b, :a] |> Enum.filter(fn | |
| ^what -> true | |
| _any -> false | |
| end) | |
| # ** (CompileError) compile_error.exs:3: unbound variable ^what | |
| # (stdlib) lists.erl:1353: :lists.mapfoldl/3 | |
| # (elixir) src/elixir_fn.erl:26: :elixir_fn.translate_fn_match/2 | |
| # (elixir) src/elixir_fn.erl:9: anonymous fn/3 in :elixir_fn.translate/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
| [#HashDict<[{"number", 3400}, {"comments", 14}, | |
| {"title", "Float.round is inconsistent"}, | |
| {"created_at", "2015-06-17T13:04:45Z"}, {"state", "open"}, {"locked", false}, | |
| {"url", "https://api.github.com/repos/elixir-lang/elixir/issues/3400"}, | |
| {"comments_url", | |
| "https://api.github.com/repos/elixir-lang/elixir/issues/3400/comments"}, | |
| {"labels", | |
| [[{"url", | |
| "https://api.github.com/repos/elixir-lang/elixir/labels/App:Elixir"}, | |
| {"name", "App:Elixir"}, {"color", "CCCCCC"}], |
Elixir is a beautiful language. Among its strength is its powerful pattern matching system which allows one to write very declarative, elegant code. FizzBuzz is a trivial problem often presented to new programmers or interviewees to determine baseline programming ability. Here is a solution Elixir:
defmodule FizzBuzz do