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 / 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
 
@yordis
yordis / git-subdirectory-tracking.md
Created September 16, 2021 07:15 — forked from tswaters/git-subdirectory-tracking.md
Adding subdirectory of a remote repo to a subdirectory in local repo

This is way more complicated than it should be. The following conditions need to be met :

  1. need to be able to track and merge in upstream changes
  2. don't want remote commit messages in master
  3. only interested in sub-directory of another repo
  4. needs to go in a subdirectory in my repo.

In this particular case, I'm interested in bringing in the 'default' template of jsdoc as a sub-directory in my project so I could potentially make changes to the markup it genereates while also being able to update from upstream if there are changes. Ideally their template should be a separate repo added to jsdoc via a submodule -- this way I could fork it and things would be much easier.... but, it is what it is.

After much struggling with git, subtree and git-subtree, I ended up finding this http://archive.h2ik.co/2011/03/having-fun-with-git-subtree/ -- it basically sets up separate branches from tracking remote, the particular sub-directory, and uses git subtree contrib module to pull it all togther. Following are

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,
@yordis
yordis / frontmatter.js
Created July 25, 2021 21:53 — forked from sudkumar/frontmatter.js
MDX Remark plugin to handle frontmatter
// helps us in parsing the frontmatter from text content
const matter = require('gray-matter')
// helps us safely stringigy the frontmatter as a json object
const stringifyObject = require('stringify-object')
// helps us in getting the reading time for a given text
const readingTime = require('reading-time')
// please make sure you have installed these dependencies
// before proceeding further, or remove the require statements
// that you don't use