Skip to content

Instantly share code, notes, and snippets.

View slashdotdash's full-sized avatar

Ben Smith slashdotdash

View GitHub Profile
@danhawkins
danhawkins / command.ex
Created September 7, 2022 04:31
Command macro
defmodule Cmd.Command do
@moduledoc """
Utility for command definition, wrapping a design pattern into code
For our commands we will used type_embedded_schema to design an in memory schema
which will be used for the command payload
As well as this we require the developer to implement a changeset/2 function
"""
defmodule Mix.Tasks.InspectAggregate do
use Mix.Task
alias MyApp.EventStore
def run(args) do
Application.ensure_all_started(:eventstore)
_ = EventStore.start_link()
{opts, _} =
defmodule EventStore.CategoryStreamLinker do
@moduledoc """
Links streams from aggregate instances to their respective category streams.
example: events from stream_uuid of `contractors_contract-07c52787-da0c-444f-9783-5d380f7093f9` will be
linked to stream_uuid of `contractors_contract`.
"""
use Commanded.Event.Handler,
application: My.App,

Phoenix 1.4.x to 1.5.0 upgrade instructions

Phoenix 1.5 requires Elixir >= 1.7. Be sure your existing version is up to date by running elixir -v on the command line.

Install the new phx.new project generator

$ mix archive.uninstall phx_new
$ mix archive.install hex phx_new 1.5.0
@ishikawa
ishikawa / parameterized_test.exs
Last active December 10, 2019 12:18
My preferred way to write parameterized tests in Elixir.
# The helper functions for the test module. To make it possible to import
# this helper module in the test module, define this module outside the context that uses it.
defmodule MyTest.Helpers do
@spec fake_params(Enumrable.t()) :: map
def fake_params(override \\ %{}) do
%{
country: "jp",
phone_number: Faker.phone_number(),
locale: "ja",
company: "My Company",
@PaoloLaurenti
PaoloLaurenti / aggregate_case.ex
Last active May 9, 2020 10:19
A proposal for the Commanded AggregateCase that allows to test aggregates states
defmodule MyApp.AggregateCase do
@moduledoc """
This module defines the test case to be used by aggregate tests.
"""
use ExUnit.CaseTemplate
using aggregate: aggregate do
quote bind_quoted: [aggregate: aggregate] do
@aggregate_module aggregate
name: Elixir CI
on: push
jobs:
build:
runs-on: ubuntu-latest
container:
@nathanl
nathanl / jeg_stateful_web_applications.md
Last active October 31, 2019 16:48
James Edward Gray II describing the ability to build *stateful* web application in Elixir

James Edward Gray II

Quote from Elixir Mix 63 - "063: Designing Elixir Systems With OTP with Bruce Tate and James Gray", starting at 01:03:13

"I've worked at a bunch of companies building web apps for a long time, and I keep seeing this same pattern, and it haunts me. In the web world, all we want is these long interactions with people, and we live in this stateless world. So what we do is, the first part of every request, we do thirty queries to re-establish the state of the world that we just forgot a few seconds ago after the last request. And then we go forward and make one tiny step forward, and then we forget everything again, so that when the next request comes in we can do thirty queries to put it all back and make one more tiny step. And I kept thinking, "there has to be a better way than this, right?"

And if you look at web advancements over the years, most of the things we're doing are

Microservices presentation

Autonomous Microservices don't share data. Period.

The demo used in the presentation can be found on GitHub in the SOA Done Right workshop repository. The code used was from exercise 02, the after folder.
To be able to compose a user interface, there are several frameworks available. To be able to see how to compose data together into a viewmodel that can be offered to ASP.NET MVC (WebAPI) see the demo in the same repository.


If you're interested in the free ADSD videos: