Skip to content

Instantly share code, notes, and snippets.

curl -X POST 'https://staging.ebanx.com.br/ws/direct' \
-d 'request_body={
"integration_key": "<bcredi-integration-key>",
"operation": "request",
"payment": {
"name": "José Silva",
"email": "[email protected]",
"document": "853.513.468-93",
"address": "Rua E",
"street_number": "1040",
@mgiacomini
mgiacomini / miner.exs
Created January 15, 2019 01:12
Bcredi miner example
path
|> CsvParser.parse(:stream)
|> Flow.from_enumerable()
|> Flow.map(&cast_contract/1) # will return {:ok, %Contract{}} | {:error, changeset}
|> Flow.map(&apply_blacklist/1) # will return {:ok, %Contract{}} | {:error, changeset} | {:filtered, reason}
|> Flow.partition(key: {:elem, 0})
|> Flow.group_by(& elem(&1, 0))
|> Flow.filter(fn
{:error, changeset} -> log_error(changeset) && false
{:filtered, reason} -> log_filtered(reason) && false
@mgiacomini
mgiacomini / delete-evicted-pods-all-namespaces.sh
Created December 26, 2018 12:28 — forked from psxvoid/delete-evicted-pods-all-namespaces.sh
Delete evicted pods from all namespaces (also ImagePullBackOff and ErrImagePull)
#!/bin/sh
# based on https://gist.github.com/ipedrazas/9c622404fb41f2343a0db85b3821275d
# delete all evicted pods from all namespaces
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
# delete all containers in ImagePullBackOff state from all namespaces
kubectl get pods --all-namespaces | grep 'ImagePullBackOff' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
# delete all containers in ImagePullBackOff or ErrImagePull or Evicted state from all namespaces
@mgiacomini
mgiacomini / Procfile
Created September 20, 2018 14:25
Heroku elixir setup
web: MIX_ENV=prod mix phx.server
@mgiacomini
mgiacomini / drilldown.js
Created August 29, 2018 20:09
How to drill down charts with ChartJS?
// https://stackoverflow.com/questions/51609922/how-to-drill-down-charts-with-chartjs
// https://stackoverflow.com/questions/26257268/click-events-on-pie-charts-in-chart-js
$(document).ready(function() {
var canvas = document.getElementById("myChart");
var ctx = canvas.getContext("2d");
var myNewChart = new Chart(ctx, {
type: 'pie',
data: data
});
@mgiacomini
mgiacomini / retrieve_token.sh
Last active July 25, 2018 14:04
How retrieve Kubernetes access token to current cluster (context)
# Check if the current cluster is right
kubectl config current-context
# Get the current context access token
TOKEN=$(kubectl describe secret $(kubectl get secrets | grep ^default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d " ")
# Print it :)
echo $TOKEN
# More info: https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/
@mgiacomini
mgiacomini / manual.md
Last active June 20, 2018 00:06
Deploy kubernetes in Google Cloud

Before you begin

  1. gcloud config set project [PROJECT_ID]
  2. gcloud config set compute/zone [COMPUTE_ZONE]
  3. gcloud components update

Cluster

Hire resources

  1. Create a container cluster: gcloud container clusters create [CLUSTER_NAME]
  2. Ensure was created: gcloud container clusters list
@mgiacomini
mgiacomini / build_export_query.ex
Created May 9, 2018 14:21
export query for ecto
def build_export_query(user, batch_size \\ 500)
columns = ~w(id name amount amount_currency cycle first_bill_date type type_description)
query = """
COPY (
SELECT #{Enum.join(columns, ",")}
FROM subscriptions
WHERE archived = false
AND user_id = #{user.id}
) to STDOUT WITH CSV DELIMITER ',';
@mgiacomini
mgiacomini / macosx_fix.md
Created April 24, 2018 13:10
MacOSx Update Fix:

MacOSx Update Fix:

  1. Reinicializa em Modo Recovery (Cmd-R), e entra em Utilities -> Terminal

  2. Executa uma busca do pacote em uma pasta temporária: find / -name OSInstall.mpkg

  3. Cria a pasta correta: mkdir -p "/Volumes/Macintosh HD/System/Installation/Packages"

@mgiacomini
mgiacomini / cet.js
Created April 12, 2018 19:39
custo efetivo anual
var MAX_CET = 100000;
var valorCET = 0;
while (true) {
var valorTotal = 0;
for (mes = 1; mes <= gPrazoPagamento; mes++) {
var valorCalculado = parcelasArray[mes - 1].valorParcela / Math.pow((1.0 + valorCET), mes);
valorTotal = valorTotal + valorCalculado;