Skip to content

Instantly share code, notes, and snippets.

View Wigny's full-sized avatar

Wígny Almeida Wigny

  • Up Learn
  • Ji-Paraná - RO
  • 12:05 (UTC -04:00)
View GitHub Profile
Mix.install([
{:ecto_sql, "~> 3.11"},
{:myxql, "~> 0.6.4"},
{:testcontainers, "~> 1.8"}
])
alias Testcontainers.MySqlContainer
{:ok, _} = Testcontainers.start_link()
{:ok, container} = Testcontainers.start_container(MySqlContainer.with_image(MySqlContainer.new(), "mysql:8.4"))
defmacro delegate_functions_for(module, functions) do
for {fun_name, fun_arity} <- functions do
fun_args = Macro.generate_arguments(fun_arity, Macro.expand_literals(module, __CALLER__))
quote do
defdelegate unquote(fun_name)(unquote_splicing(fun_args)), to: unquote(module)
end
end
end
Application.put_env(:input, Input.Endpoint,
server: true,
http: [ip: {127, 0, 0, 1}, port: 4001],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: Input.ErrorHTML],
layout: false
],
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
defmodule Decimal.Range do
defstruct [:first, :last, :step]
def new(first, last, step) do
%__MODULE__{first: first, last: last, step: step}
end
def size(range) do
range.last
|> Decimal.sub(range.first)
defmodule MyApp.Type.Duration do
use Ecto.Type
alias Postgrex.Interval
defguardp is_duration(value) when is_struct(value, Duration)
defguardp is_interval(value) when is_struct(value, Interval)
@impl true
def type, do: :interval
@Wigny
Wigny / duration.exs
Last active August 29, 2023 00:21
Ecto Duration ParameterizedType
Mix.install([
{:ecto_sql, "~> 3.10"},
{:timex, "~> 3.7"}
])
defmodule MyApp.Type.Duration do
use Ecto.ParameterizedType
alias Timex.Duration
defmodule DefMaybe do
defmacro defmaybe(fun) do
quote bind_quoted: [fun: Macro.escape(fun, unquote: true)], location: :keep do
{fun_name, fun_args} = Macro.decompose_call(fun)
resource = List.first(fun_args)
action = Keyword.get(opts, :action)
def unquote(:"maybe_#{fun_name}")({:ok, unquote_splicing(fun_args)}) do
{:ok, unquote(fun_name)(unquote_splicing(fun_args))}
end
defmodule DefBang do
defmacro def!(call, do: block) do
quote bind_quoted: [call: Macro.escape(call, unquote: true), block: Macro.escape(block)], location: :keep do
{name, args} = Macro.decompose_call(call)
def unquote(name)(unquote_splicing(args)) do
unquote(block)
end
def unquote(:"#{name}!")(unquote_splicing(args)) do
Mix.install([evision: "~> 0.1"],
system_env: [
EVISION_PREFER_PRECOMPILED: "false",
CMAKE_OPENCV_OPTIONS: "-D WITH_FFMPEG=ON"
]
)
alias Evision.VideoCapture
url = "rtsp://172.28.6.108:8554/mystream"
docker run -d --restart unless-stopped --name parking_lot_database -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=parking_lot -p 5432:5432 -v postgres:/var/lib/postgresql/data postgres
echo 'DATABASE_URL=ecto://postgres:postgres@172.17.0.1:5432/parking_lot' >> ~/parking_lot.env
echo 'SECRET_KEY_BASE=my_ramdom_secure_and_at_least_64_bits_long_secret_______________' >> ~/parking_lot.env
echo 'PHX_HOST=127.0.0.1' >> ~/parking_lot.env
echo 'CACHE_DIR=/data' >> ~/parking_lot.env
docker pull ghcr.io/wigny/parking_lot:latest
docker run --env-file ~/parking_lot.env -it ghcr.io/wigny/parking_lot bin/migrate
docker run --name parking_lot --restart unless-stopped --env-file ~/parking_lot.env -p 4000:4000 -v /tmp:/data -itd ghcr.io/wigny/parking_lot