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 / 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"}
])
@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