Skip to content

Instantly share code, notes, and snippets.

View maartenvanvliet's full-sized avatar
🍊

Maarten van Vliet maartenvanvliet

🍊
View GitHub Profile
# TODO:
# Runner like https://github.com/elixir-lang/ecto/blob/master/lib/ecto/migration.ex (does it have state?)
defmodule Ecto.Runner do
def start_command({:create, table}) do
IO.puts "create table: #{table}"
end
def subcommand({:add, column, type}) do
IO.puts "add column: #{column}(#{type})"

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@bsedat
bsedat / Dockerfile
Last active August 8, 2023 05:56
Elixir Phoenix Umbrella App + Distillery Multistage Docker Build
FROM elixir:1.4.5 as asset-builder-mix-getter
ENV HOME=/opt/app
RUN mix do local.hex --force, local.rebar --force
# Cache elixir deps
COPY config/ $HOME/config/
COPY mix.exs mix.lock $HOME/
COPY apps/myproject_web/mix.exs $HOME/apps/myproject_web/
COPY apps/myproject_web/config/ $HOME/apps/myproject_web/config/
@LostKobrakai
LostKobrakai / date_time_generators.ex
Last active March 17, 2024 17:21
stream_data generators to create elixir date/time structs
defmodule DateTimeGenerators do
use ExUnitProperties
@time_zones ["Etc/UTC"]
def date do
gen all year <- integer(1970..2050),
month <- integer(1..12),
day <- integer(1..31),
match?({:ok, _}, Date.from_erl({year, month, day})) do
@almoraes
almoraes / 0x-ebrotate.config
Created January 2, 2018 17:34
EB AWS rotate docker logs
files:
"/etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.dockerlogs.conf":
mode: "000644"
owner: root
group: root
content: |
/var/lib/docker/containers/*/*.log {
size 100M
rotate 14
missingok
@opsb
opsb / ecto_utils.ex
Last active March 1, 2018 16:23
Export elixir Ecto models as plain maps
defmodule Util.Ecto do
def export(model = %{__meta__: _meta, __struct__: _struct}) when is_map(model) do
stripped =
model
|> Map.from_struct()
|> Map.delete(:__meta__)
associations = model.__struct__.__schema__(:associations)
Enum.reduce(associations, stripped, fn assoc, model ->
@ibarchenkov
ibarchenkov / stream_data_ecto_factory.ex
Created January 31, 2019 21:09
Elixir Ecto testing factories combined with StreamData generators.
defmodule MyApp.Factory do
use ExUnitProperties
alias MyApp.{Repo, User, Comment}
### Generators
def generator(:user) do
gen all name <- string(:alphanumeric, min_length: 2),
email <- generator(:email),
age <- integer(10..130) do
@bruce
bruce / absinthe.md
Last active November 2, 2019 16:03
Very brief description of how Absinthe processes GraphQL

Using Elixir releases and multi-stage Docker files to simplify Phoenix deployment

This repo is my experiment in deploying a basic Phoenix app using the release feature from elixir 1.9 (https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-released/) and docker, via a multi-stage Dockerfile (https://docs.docker.com/develop/develop-images/multistage-build/) leveraging bitwalker's docker images for Elixir and Phoenix.

Step 1: Install Elixir 1.9.1 (and Erlang)

The simplest way to manage Elixir versions is to use asdf.

@rhnonose
rhnonose / absinthe_collector.ex
Created October 18, 2019 17:57
Absinthe Collector
defmodule AbsintheCollector do
@moduledoc """
Module to collect absinthe telemetry events
"""
use Prometheus.Metric
require Prometheus.Contrib.HTTP
@events [
[:absinthe, :resolve, :field, :start],
[:absinthe, :resolve, :field],