Skip to content

Instantly share code, notes, and snippets.

View fuelen's full-sized avatar
🇺🇦

Artur Plysiuk fuelen

🇺🇦
View GitHub Profile
@fuelen
fuelen / shunting_yard.ex
Created October 2, 2024 07:50
Shunting yard
defmodule ShuntingYard do
@doc """
Implementation of https://en.wikipedia.org/wiki/Shunting-yard_algorithm
## Examples
iex> ShuntingYard.to_rpn(
...> [
...> value: 4,
...> operator: :*,
defmodule SafeEval do
def valid_data do
"""
%{
recipient: %{first_name: "John", age: 18},
employments: [%{start_year: 2020}, %{start_year: 2020}],
valid: true,
status: :archived,
date: ~D[2011-01-01],
datetime: ~U[2021-06-10 10:57:51.929284Z],
Mix.install([:ratatouille])
defmodule ReorderMigrations do
@behaviour Ratatouille.App
alias Ratatouille.Runtime.Command
import Ratatouille.View
import Ratatouille.Constants, only: [key: 1]
@enter key(:enter)
@arrow_up key(:arrow_up)
@fuelen
fuelen / ecto_cond.ex
Created November 12, 2020 15:17
Ecto cond
defmodule Ecto.Extension.Query.API do
defmacro cond_(do: block) do
bindings =
Enum.reduce(block, [], fn
{:->, _, [[clause], branch]}, acc ->
[branch, clause | acc]
end)
|> Enum.reverse()
bindings_number = length(bindings)
defmodule SQL do
defmodule LogParser do
import NimbleParsec
defcombinatorp(
:string,
ascii_char([?"])
|> ignore()
|> repeat_while(
choice([
@fuelen
fuelen / array_substract_macro.ex
Last active July 28, 2021 13:48
How to remove array from array using ecto
defmodule MyProject.Macro do
@doc """
@doc """
## Examples:
iex> query |> update([t], set: [unread_message_ids: array_substract(t.unread_message_ids, ^message_ids)])
"""
defmacro array_substract(first, second) do