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 / README.md
Created May 22, 2024 14:58
Routing Structure

Routing

  • Fractal Pattern: repeatable pattern at each level of the routing hierarchy.

This example shows the organization based on Next Reserved Naming to define the routing behavior, you could ignore that and adopt whatever naming convention you prefer when it comes to the naming.

In order to add a new URL Subdirectory, you must create a routes directory.

// https://twitter.com/alchemist_ubi/status/1786275138532790439
function proxy(proxy: string, req: Request): Request {
const url = new URL(proxy);
const originUrl = new URL(req.url);
const header = new Headers(req.headers);
header.set('X-Forwarded-For', 'some-ip');
url.pathname = originUrl.pathname;
@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
Mix.install([
  {:tesla, github: "elixir-tesla/tesla", branch: "master"},
  {:mint, "1.5.1"},
  {:castore, "1.0.2"}
])