Skip to content

Instantly share code, notes, and snippets.

View nuxlli's full-sized avatar
🎯
Focusing

Everton Ribeiro nuxlli

🎯
Focusing
View GitHub Profile
@nuxlli
nuxlli / mokable_task.ex
Last active October 23, 2023 15:48
A mockable Task module for elixir (with mox)
# lib/my_project/task.ex
defmodule MyProject.Task do
@moduledoc """
TODO: run async task on tests will not work, with unpredictable side effects
"""
@adapter Keyword.get(
Application.compile_env(:my_project, __MODULE__, []),
:adapter,
Task
@nuxlli
nuxlli / load_dotenv.sh
Last active February 1, 2024 03:39
Loading dotenv files with exports and interpolations without override the current vars
#!/usr/bin/env bash
# This function loads variables from a .env (dotenv format) files without
# override the current variables. It will fix the relative paths.
#
# Example:
#
# $ export ENV=developer
# $ cat dotenvs/.env
# ENV=staging
@nuxlli
nuxlli / pre-push
Created December 1, 2020 15:05
A protection to not push code for main by accident
#!/bin/bash
# Warn before pushing to protected branches
# - Make script executable with
# chmod +x pre-push
# - Bypass with:
# git push --no-verify
# - To add hooks on global configuration
# git config --global core.hooksPath [path for folder with hooks]
# References:
@nuxlli
nuxlli / port_pid.sh
Created November 19, 2020 23:16
List port by process on macOS
#!/bin/sh
# Map LISTENing TCP ports to their PIDs using lsof
LSOF=/usr/sbin/lsof
# e.g. netstat -an
# 127.0.0.1.25 *.* 0 0 49152 0 LISTEN
# *.22 *.* 0 0 49152 0 LISTEN
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Connection;
public class TestConnect {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
System.out.println("Connection test...");
//you need create database with this name 'github-example-jdbc'
String url = System.getenv("RUNDECK_DATABASE_URL");
String user = System.getenv("RUNDECK_DATABASE_USERNAME");
@nuxlli
nuxlli / accounts.sql
Last active October 21, 2020 17:35
Constraint uniq external reference for two rows
-- References:
-- https://stackoverflow.com/a/55223096/4constraint 69463
-- Table Definition ----------------------------------------------
CREATE TABLE accounts (
id bigint DEFAULT nextval('id_seq'::regclass) PRIMARY KEY,
natural_person_id bigint,
legal_entity_id bigint,
CONSTRAINT chk_only_one_is_not_null CHECK (num_nonnulls(natural_person_id, legal_entity_id) = 1)
#!/usr/bin/env bash
set -e
bucket_path=$1
bucket_bk_path="$1_$(date +%s)"
tmp_file=$(mktemp)
# Donwload a temporary file
aws s3 cp "${bucket_path}" "${tmp_file}"
regex = ~r/^(?:(?<number1>\d{1,}|sn|s\/n)\s*[-,]?\s*)?(?<street>.*?)(?:\s*[-,]?\s*(?<number2>\d{1,}|sn|s\/n))?$/
streets = [
"201 Rua Almirante Calheiros",
"201, Rua Almirante Calheiros",
"201 - Rua Almirante Calheiros",
"sn Rua Almirante Calheiros",
"s/n, Rua Almirante Calheiros",
"Rua Almirante Calheiros 201",
"Rua Almirante Calheiros, s/n",
@nuxlli
nuxlli / init.fish
Created July 6, 2020 14:47
Fish k8s alias and scripts
function av-exec
aws-vault exec $argv[1] -- $argv[2..-1]
end
function av-shell
av-exec $argv[1] fish
end
alias kexec-dev="kubectl-exec firma-dev"
alias kexec-stage="kubectl-exec firma-stage"
@nuxlli
nuxlli / auth_context.ex
Created December 3, 2019 21:37
Absinthe middleware for auth with Guardian
# Adaptação de http://www.east5th.co/blog/2017/05/08/graphql-authentication-with-elixir-and-absinthe/
defmodule DemoWeb.AuthContext do
@moduledoc false
@behaviour Plug
import Plug.Conn
alias Guardian.Plug.Pipeline