Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Everton Ribeiro nuxlli

🎯
Focusing
View GitHub Profile
@nuxlli
nuxlli / load_dotenv.sh
Last active Feb 7, 2022
Loading dotenv files with exports and interpolations without override the current vars
View load_dotenv.sh
#!/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 Dec 1, 2020
A protection to not push code for main by accident
View pre-push
#!/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 Nov 19, 2020
List port by process on macOS
View port_pid.sh
#!/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
View TestConnect.java
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 Oct 21, 2020
Constraint uniq external reference for two rows
View accounts.sql
-- 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)
View s3_edit.sh
#!/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}"
View address_capture.exs
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 Jul 6, 2020
Fish k8s alias and scripts
View init.fish
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 Dec 3, 2019
Absinthe middleware for auth with Guardian
View auth_context.ex
# 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
View JSON.ex
defmodule Web.Graphql.Types.Scalars.JSON do
@moduledoc """
The Json scalar type allows arbitrary JSON values to be passed in and out.
Requires `{ :jason, "~> 1.1" }` package: https://github.com/michalmuskala/jason
"""
use Absinthe.Schema.Notation
scalar :json_text, name: "Json" do
description("""
The `Json` scalar type represents arbitrary json string data, represented as UTF-8