Skip to content

Instantly share code, notes, and snippets.

View paulo-ferraz-oliveira's full-sized avatar

Paulo F. Oliveira paulo-ferraz-oliveira

View GitHub Profile
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / renovate.md
Last active August 22, 2024 15:23
Renovate your GitHub repositories
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / simpler_cowboy_rest.md
Last active February 12, 2024 10:41
A simpler `cowboy_rest` behaviour
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / bump_vsn.md
Created September 9, 2023 11:54
Bump a specific dep's version in mix.exs (via AST traversal)

Bump mix.exs dep. version

(from: jelly-beam/rebar3_ex_doc#67)

This little Gist shows how to achieve simple AST walk + update to change a module attribute, that defines a version (in the example), in mix.exs.

# up_version.exs
defmodule UpVersion do
  @mix_exs "mix.exs"
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / gha_plus_rebar3_depup_schedule.md
Last active December 17, 2023 18:28
Schedule your rebar.config version updates with rebar3_depup and GitHub Actions

rebar3_depup-based rebar.config version updates

... on scheduled GitHub Actions.

How to achieve it?

workflow .yml

This is an example scheduled-based workflow to run a .sh at a given time of day.

@paulo-ferraz-oliveira
paulo-ferraz-oliveira / common_test_all_0.md
Created August 23, 2023 18:40
Filling your Erlang/OTP's Common Test suites' `:all/0` automatically

Common Test trickery

We can define an Erlang/OTP Common Test suite with

-module(...).

-compile([export_all, nowarn_export_all]).

all() ->
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / makefile_21.md
Last active July 20, 2024 13:35
Makefile 21st century options

Some Makefile options for the 21st century

SHELL := bash
.ONESHELL:
.SHELLFLAGS := -e -u -c -o pipefail
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / elixir_credo_duplicate_use.md
Created May 12, 2023 17:12
An Elixir Credo custom check for making sure you don't have duplicate `use`

Here's an example on how to do it.

defmodule OneUseAlone do
  use Credo.Check,
    base_priority: :high,
    category: :warning,
    explanations: [
      check: """
      Checks if `use` happens more than once in a given module
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / elixir_fprof_profiling.md
Created May 12, 2023 16:11
Profiling in Elixir using :fprof

Something like

  def trace(ms, where) do
    Task.start(fn ->
      # making sure file is writable (otherwise it'll only crash later, after a WHILE)
      :ok = File.write(where, "")
      :ok = :fprof.stop()
      
 {:ok, _} = :fprof.start()
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / logging_decorator.md
Created May 5, 2023 13:17
Wrap a function in a "timed-performance" log decorator, using Elixir library decorator and Logger

Here's an example of how to do it.

def with_performance_log(options, body, context) do
  quote bind_quoted: [
          context: Macro.escape(context),
          options: Macro.escape(options),
          body: body
        ] do
 module = "#{context.module}"
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / recon_trace_format.md
Last active July 12, 2023 08:31
Shows an (Elixir) example of tracing HTTPoison's :request and extracting from the call and the return value, using Fred Hebert's recon

Tracing in Elixir with :recon, and formatter

I tend to not remember how this is done, so here goes, for easier copy-paste effect:

:recon_trace.calls(
  {_mod = HTTPoison, _fun = :request, fn ([_, _, _, _, _]) -> :return_trace end},
  _calls = 10,
  [scope: :local,
 formatter: fn (tuple) ->