Skip to content

Instantly share code, notes, and snippets.

View yordis's full-sized avatar
💜
Helping people one second at the time

Yordis Prieto yordis

💜
Helping people one second at the time
View GitHub Profile
@yordis
yordis / dynamic.ex
Created June 25, 2025 01:17 — forked from thiagomajesk/dynamic.ex
An Ecto type that allows handling polymorphic embeddings
defmodule Dynamic do
@moduledoc """
A dynamic Ecto type that allows handling differently-shaped maps using structured data.
This module relies on embedded schemas to cast and validate data based on the provided mappings.
## Example
# Will load values from [%{type: "foo", ...}, %{type: "bar", ...}]
field :custom, Dynamic, mappings: [foo: Foo, bar: Bar]

You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.

IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse. IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code).

Here are useful slash commands users can run to interact with you:

  • /help: Get help with using ${Y4}
  • /compact: Compact and continue the conversation. This is useful if the conversation is reach
# install
# add apt registry: https://packagecloud.io/EventStore/EventStore-OSS/install
apt install eventstore-oss
#if you need eventstore to run on a port < 1024
sudo setcap CAP_NET_BIND_SERVICE=+eip $(which eventstored)
# edit /etc/systemd/system/eventstore.service
# add `RestartSec=5` to section [Service]
@yordis
yordis / authorized_introspection.ex
Created July 8, 2024 16:33 — forked from afhammad/authorized_introspection.ex
Disable GraphQL schema introspection in Elixir Absinthe using a plugin
defmodule MyAppWeb.Schema.Middleware.AuthorizedIntrospection do
@moduledoc """
Disable or restrict schema introspection to authorized requests
"""
@behaviour Absinthe.Plugin
@impl Absinthe.Plugin
def before_resolution(%{context: %{admin: true}} = exec), do: exec
def before_resolution(exec) do
@yordis
yordis / EsBankAccount.ts
Created November 14, 2023 19:21 — forked from akhansari/EsBankAccount.ts
TypeScript prototype of the Decider pattern. (F# version: https://github.com/akhansari/EsBankAccount)
import * as assert from "assert";
/** Decider Pattern **/
type Transaction = {
amount: number
date: Date
}
type Deposited = Transaction & {
@yordis
yordis / playlist.ex
Created October 3, 2023 16:17 — forked from Boettner-eric/playlist.ex
Write a spotify playlist to a text file
Mix.install([:httpoison, :poison])
defmodule Spotify do
[playlist_id] = System.argv()
@token_url "https://accounts.spotify.com/api/token"
@playlist_url "https://api.spotify.com/v1/playlists/#{playlist_id}"
def get_token() do
client_id = System.get_env("SPOTIFY_CLIENT_ID")
@yordis
yordis / polling_log_reader.ex
Created July 23, 2023 20:53 — forked from kylethebaker/polling_log_reader.ex
Example polling a log file
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Log Reader - polls log file and sends new lines to channel
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
defmodule LogReader do
use GenServer
@log_file "priv/some_log.log"
@poll_interval 5 * 1000 # 5 seconds
def run_test() do
@yordis
yordis / 01 Erlang GitHub Actions With setup-beam and Caching.md
Created December 24, 2022 22:19 — forked from eproxus/01 Erlang GitHub Actions With setup-beam and Caching.md
How to Setup Erlang GitHub Actions With setup-beam and Caching

Erlang GitHub Actions With setup-beam and Caching

To build and test Erlang projects on GitHub actions with Rebar 3 it is fastest to use the setup-beam action and use caching.

To get started, create a workflow file in .github/workflows in your repository. For this example we use a file called .github/workflows/continuous_integration.yml.

defmodule Mix.Tasks.InspectAggregate do
use Mix.Task
alias MyApp.EventStore
def run(args) do
Application.ensure_all_started(:eventstore)
_ = EventStore.start_link()
{opts, _} =
@yordis
yordis / README.md
Created January 26, 2022 16:24 — forked from slashdotdash/README.md
Commanded middleware to enrich commands during dispatch, such as calling an external API.

Commanded middleware for command enrichment

Usage

Add the EnrichCommand middleware to your command router:

defmodule MyApp.Router do
  use Commanded.Commands.Router