Skip to content

Instantly share code, notes, and snippets.

View andreapavoni's full-sized avatar
🎧
❤️‍🔥🪩🕺🏻🚀

Andrea Pavoni andreapavoni

🎧
❤️‍🔥🪩🕺🏻🚀
View GitHub Profile
@andreapavoni
andreapavoni / Slug.elm
Created May 7, 2020 08:09
Slug widget made with Elm
module Slug exposing (..)
import Html exposing (Html, Attribute, beginnerProgram, text, div, input)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import String exposing (toLower)
import Regex exposing (replace, regex)
-- MAIN
// Pizza Party (#8 from https://pragprog.com/book/bhwb/exercises-for-programmers)
// Write a program to evenly divide pizzas. Prompt for the number of people, the
// number of pizzas, and the number of slices per pizza. Ensure that the number of
// pieces comes out even. Display the number of pieces of pizza each person should
// get. If there are leftovers, show the number of leftover pieces.
// Challenges
// * Revise the program to ensure that inputs are entered as numeric values.
// * Alter the output so it handles pluralization properly, for example:
@andreapavoni
andreapavoni / event_payload_encoder.ex
Last active May 27, 2019 10:15
A simple protol to encode struct(s) as a serialized event payload. When used with `Protocol.derive` it accepts `only` and `except` options for black/white-listing of attributes. Mostly ripped from Poison.
defmodule EventPayloadEncoderError do
@type t :: %__MODULE__{message: String.t(), value: any}
defexception message: nil, value: nil
def message(%{message: nil, value: value}) do
"unable to serialize value: #{inspect(value)}"
end
def message(%{message: message}) do
@andreapavoni
andreapavoni / Event-stream based GraphQL subscriptions.md
Created October 8, 2018 13:27 — forked from OlegIlyenko/Event-stream based GraphQL subscriptions.md
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.

@andreapavoni
andreapavoni / rel-config.exs
Last active May 14, 2018 08:55
A phoenix release task to run migration. It's a modified version of the one found on the official [Distillery documentation](https://hexdocs.pm/distillery/running-migrations.html)
# ...
release :my_app do
# ...
set(
applications: [
:runtime_tools,
my_app: :permanent
]
@andreapavoni
andreapavoni / Flexible Dockerized Phoenix Deployments.md
Created May 12, 2018 18:02 — forked from jswny/Flexible Dockerized Phoenix Deployments.md
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

<tags-input>
<%= hidden_input form, :tags, value: [] , class: "input" %>
</tags-input>
@andreapavoni
andreapavoni / elixir_run_for_envs.md
Last active May 24, 2017 09:50
Running a block code only with a specific Mix.env

Ever found yourself writing code like this?

case Mix.env() do
  :prod -> do_something1()
  :dev  -> do_something2()
  :test -> do_something3()
end
@andreapavoni
andreapavoni / .deliver_config
Created May 22, 2017 08:53
Edeliver configuration to deploy a Phoenix app compiling and digesting assets locally
# MYAPP/.deliver/config
APP="<APP NAME>"
MAIN_HOST="<BUILD & PRODUCTION HOST>"
MAIN_USER="<MAIN USER FOR BUILD AND DEPLOY>"
BUILD_HOST="${MAIN_HOST}"
BUILD_USER="${MAIN_USER}"
BUILD_AT="/tmp/edeliver/${APP}/builds"
module Geometry do
@moduledoc """
Calculates area of different shapes
"""
@doc """
Some other comment
"""
def area({:rectangle, width, height}) do: width * height
def area({:square, side}) do: side * side