Skip to content

Instantly share code, notes, and snippets.

View fuelen's full-sized avatar
🇺🇦

Artur Plysiuk fuelen

🇺🇦
View GitHub Profile
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
@fuelen
fuelen / bump-version.sh
Last active January 15, 2018 09:22 — forked from mareksuscak/bump-version.sh
Bump version shell script.
#!/bin/bash
# Thanks goes to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
#
# Original version modified by Marek Suscak
#
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3" or even "1.2.3-beta+001.ab"