Skip to content

Instantly share code, notes, and snippets.

@vitorbritto
vitorbritto / regex.md
Last active September 27, 2025 02:41
Regex Cheat Sheet

Regular Expressions

Basic Syntax

  • /.../: Start and end regex delimiters
  • |: Alternation
  • (): Grouping
@cheeyeo
cheeyeo / test.exs
Last active September 25, 2022 19:56
Example of mocking a web api in ExUnit in Elixir using Meck
# 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
@shiwork
shiwork / math.exs
Created May 26, 2015 09:01
elixir
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
@orendon
orendon / defaults.ex
Created June 25, 2015 16:46
default conflicts error on Elixir 1.0.4
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
@hackervera
hackervera / cool.ex
Last active September 25, 2022 19:54
Elixir
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
@shibacow
shibacow / VercheckEx_main.ex
Last active September 25, 2022 19:58
http://qiita.com/HirofumiTamori/items/06ab8e85c25f118f8e72 を試してみる。ubuntu 14.04,Elixir1.0.5で確認。
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} ->
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"],
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
[#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"}],
@jarednorman
jarednorman / fizzbuzz.markdown
Created February 22, 2016 07:59
Fizzbuzz in Elixir

Fizzbuzz in Elixir

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