Skip to content

Instantly share code, notes, and snippets.

View trbngr's full-sized avatar

Chris Martin trbngr

  • Phoenix, AZ, USA
View GitHub Profile
@trbngr
trbngr / docker-compose.yml
Created April 12, 2023 22:24
Redpanda Local Docker
---
version: '3.7'
name: redpanda-quickstart
networks:
redpanda_network:
driver: bridge
volumes:
redpanda-0:
services:
redpanda-0:
@trbngr
trbngr / delete_stream_events_of_type_function.sql
Last active March 16, 2023 11:40
Delete events of a certain type from a stream
create or replace function delete_stream_events_of_type(target_stream_id bigint, target_event_type text) returns integer
language sql
as
$$
-- disable triggers
alter table stream_events disable trigger no_update_stream_events;
alter table stream_events disable trigger no_delete_stream_events;
alter table events disable trigger no_delete_events;
defmodule ShutUpDialyzer do
defmacro __using__(_opts) do
quote do
@on_definition unquote(__MODULE__)
@before_compile unquote(__MODULE__)
Module.register_attribute(__MODULE__, :funs, accumulate: true)
end
end
def __on_definition__(%{module: module}, :def, name, args, _guards, _body) do
defmodule Mix.Tasks.InspectAggregate do
use Mix.Task
alias MyApp.EventStore
def run(args) do
Application.ensure_all_started(:eventstore)
_ = EventStore.start_link()
{opts, _} =
Mix.install([:decimal])
defmodule DecimalMath do
alias Decimal, as: D
import Decimal
defmacro __using__(_opts) do
quote do
import Kernel, except: [*: 2, /: 2, +: 2, -: 2]
import DecimalMath
@trbngr
trbngr / handle_exceptions.ex
Last active September 13, 2021 16:46
Absinthe Handle Exceptions
defmodule Middleware.HandleExceptions do
require Logger
alias Absinthe.Resolution
alias Ecto.Query.CastError
alias AbsintheErrorPayload.ChangesetParser
alias Ecto.{InvalidChangesetError, NoResultsError, StaleEntryError}
def handle_exceptions(middleware_spec) do
fn resolution, config ->
directive @connection(key: String!, filters: [String], handler: String, dynamicKey_UNSTABLE: String) on FIELD
directive @stream_connection(
key: String!
filters: [String]
handler: String
initial_count: Int!
if: Boolean = true
use_customized_batch: Boolean = false
dynamicKey_UNSTABLE: String
@trbngr
trbngr / absinthe_json_schema.livemd
Last active August 27, 2021 05:06
Absinthe GraphQL Query to JSON Schema

Absinthe to JSON Schema

Deps

Mix.install([
  {:jason, "~> 1.2"},
  {:absinthe, "~> 1.6"},

  # Not required for generating json schema. Only used to validate data.
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,
@trbngr
trbngr / deploy_workflow.yml.tpl
Last active May 19, 2023 06:30
TF ECS + Deploy
name: ${environment} deploy
on:
push:
branches:
- ${deploy_branch}
workflow_dispatch:
env:
CONTAINER_NAME: ${container_name}