Skip to content

Instantly share code, notes, and snippets.

View allanbatista's full-sized avatar

Allan Batista allanbatista

View GitHub Profile
@allanbatista
allanbatista / keras_layer.py
Last active June 4, 2019 14:03
Custom Normalization function to convert max to 1 and set 0 to others
import tensorflow as tf
from tensorflow.keras.layers import Layer
class ClasseNormalizationLayer(Layer):
"""
ClasseNormalizationLayer output with same input shape.
model = Sequential()
model.add(Dense(32, activation="relu", input_shape=(32,)))
model.add(ClasseNormalizationLayer())
@allanbatista
allanbatista / README.md
Last active July 12, 2019 13:21
Machine Learning Avaliate Metrics

Tabela de Predição

TP = True Positive A quantidade de tudo que era classe X e foi classificado como X.

FP = False Positive A quantidade de tudo que era classe não X e foi classificado como X.

FN = False Negative A quantidade de tudo que era X e foi classificado como não X

@allanbatista
allanbatista / deploy_rstudio_with_dataproc.md
Last active March 27, 2023 09:11
Deploy RStudio with Dataproc

Create cluster

$ gcloud beta dataproc clusters create [CLUSTER-NAME] \
                              --enable-component-gateway \
                              --bucket bucket-name \
                              --region us-central1 \
                              --subnet default \
                              --zone us-central1-a \
                              --master-machine-type n1-standard-4 \

--master-boot-disk-size 500 \

@allanbatista
allanbatista / README.md
Last active April 22, 2022 12:54
Elixir para programadores Python

Elixir para programadores Python

A motivação para a criação deste artigo começa com uma solicitação da minha equipe no B2WADS para fazer um tutorial de como usar o Elixir. Como todos aqui dominam Python, então decidi criar este tutorial específico para esses desenvolvedores.

O que é o Elixir

O Elixir é uma linguagem funcional e compilada que é executado em cima da ErlangVM. Foi projetada para ser de fácil entendimento e em muitos casos é muito similar a sintaxe do Ruby.

Podemos dizer que o Elixir é uma abstração para a linguagem Erlang, pois o Elixir é transpilado para Erlang antes de der convertido para BEAM bytecode que poisteriormente será executado na ErlangVM.

@allanbatista
allanbatista / singularize.py
Created January 15, 2019 15:37
Transforma palavras no plural para palavras no singular.
import re
def rule(match, replace):
return (re.compile("^([a-zA-z]*){}$".format(match)), re.compile("{}$".format(match)), replace)
def singularize(word):
rules = [
rule("as", "a"),
rule("es", "e"),
rule("is", "i"),
@allanbatista
allanbatista / .bashrc
Created January 5, 2019 21:46
Instalação do spark (helper)
export SPARK_HOME=/path/to/spark/spark-2.4.0-bin-hadoop2.7
export PATH=$SPARK_HOME/bin:$PATH
export PYTHONPATH=$SPARK_HOME/python:$PYTHONPATH
export PYSPARK_DRIVE_PYTHON="jupyter"
export PYSPARK_DRIVE_PYTHON_OPTS="notebook"
export PYSPARK_PYTHON=python3
@allanbatista
allanbatista / 01_create_template.sh
Last active October 30, 2018 18:08
Create new Custom Template and Dataflow JOB from DataflowTemplates git repository
mvn compile exec:java \
-Dexec.mainClass=com.google.cloud.teleport.templates.PubSubToBigQuery \
-Dexec.cleanupDaemonThreads=false \
-Dexec.args=" \
--project=XXXXXXX \
--stagingLocation=gs://GPS_NAME/staging \
--tempLocation=gs://GPS_NAME/tmp \
--templateLocation=gs://GPS_NAME/PubSubToBigQuery.json \
--runner=DataflowRunner \
--subnetwork=https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-east1/subnetworks/NETWORK_NAME \
@allanbatista
allanbatista / gcp.sh
Created October 30, 2018 17:59
Create BigQuery table with time expirationa and custom field
bq mk \
--require_partition_filter \
--time_partitioning_type=DAY \
--time_partitioning_expiration=604800 \
--time_partitioning_field=bucket \
--schema=account_id:STRING,sku:STRING,variation_sku:STRING,action:STRING,promise:STRING,done:BOOLEAN,status:STRING,created_at:TIMESTAMP,bucket:DATE \
dataset_name.table_name
@allanbatista
allanbatista / encryto.rb
Created October 29, 2018 18:15
Exemplo de encrypt de arquivo.
require 'openssl'
key = OpenSSL::PKey::RSA.new(2048)
public_key_s = key.public_key.to_s
private_key_s = key.to_s(OpenSSL::Cipher::AES256.new(:CBC), "password")
encrypted_data = OpenSSL::PKey::RSA.new(public_key_s).public_encrypt("data to encrypt")
opened_data = OpenSSL::PKey::RSA.new(public_key_s, "password").private_decrypt(encrypted_data)
@allanbatista
allanbatista / README.md
Created October 11, 2018 17:59
How encrypt and decrypt with public and private key

Create x509 certification

openssl req -x509 -nodes -days 100000 -newkey rsa:2048  -keyout private.pem  -out public.pub

Encrypt

openssl smime -encrypt -aes256 -in filename.input -binary -outform DEM -out filename.encrypted public.pub

Decrypt