Skip to content

Instantly share code, notes, and snippets.

View benfalk's full-sized avatar
🏠
Working from home

Benjamin Falk benfalk

🏠
Working from home
View GitHub Profile
add = fn(a, b) -> a + b end
short_add = &(&1 + &2)
false || SomeModule #=> SomeModule
true && SomeModule #=> SomeModule
nil || "A String Value" #=> "A String Value"
:a || :b #=> :a
:a && :b #=> :b
defmodule EOD.Network.Packet do
defstruct id: nil,
size: 0,
session_id: 0,
parameter: 0,
sequence: 0,
data: "",
check: 0,
type: nil
from(
a in Actor,
select: fragment("unnest(?) as ids", a.loot_ids),
group_by: fragment("ids")
)
defmodule Test do
def foo, do: :bar
end
from(
q in query,
where: fragment(
"""
EXISTS(
SELECT NULL FROM froo
WHERE foo.foreign_id = ?
AND foo.is_published = 't'
)
""", q.id
format = "{YYYY}-{0M}-{0D}"
Timex.parse!("2016-12-31", format) > Timex.parse!("2017-01-02", format) # => true
Timex.parse!("2016-12-30", format) > Timex.parse!("2016-12-31", format) # => false
{limit, offset} =
with {limit, _} <- Integer.parse(params["limit"] || "10"),
{offset, _} <- Integer.parse(params["offset"] || "0")
do
{limit, offset}
else
_ -> {10, 0}
end
WITH vals AS (
SELECT * FROM(VALUES
('t'::boolean),
(NULL),
('f'::boolean),
('t'::boolean),
(NULL),
('f'::boolean)
) AS map(val)
)