Skip to content

Instantly share code, notes, and snippets.

View viniroger's full-sized avatar

Vinicius Roggério da Rocha viniroger

View GitHub Profile
@viniroger
viniroger / print_all.py
Last active October 7, 2019 17:48
Print all elements from array
# Print all numpy array, without truncation
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)
# Print all pandas dataframe, without truncation
with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
print(df)
@viniroger
viniroger / filtro.py
Created August 8, 2019 15:17
Ideas for extreme value filter
def filtro(self, df, uid):
"""Filter forecasted values
Check acceptable values, replacing when it isn't
"""
import statistics
if uid == 215:
lower_limit = 10
upper_limit = 3000
elif uid == 216:
lower_limit = 10
@viniroger
viniroger / convert.py
Created July 22, 2019 13:08
Convert object to datetime64 ns and print columns types
y_true['ds'] = pd.to_datetime(y_true['ds'])
print(y_true.dtypes)
@viniroger
viniroger / zip_files.sh
Created July 10, 2019 21:10
Select files by pattern and zip into new file
ls *VS00* *VSS.* | zip -@ saida/arquivo.zip
@viniroger
viniroger / send_mail.sh
Last active July 10, 2019 18:39
Shell script to send e-mail with attachments and body to mails list
envio_email(){
# Escrever corpo do e-mail
echo "Seguem anexos" >> $arq_email
printf "\n" >> $arq_email
# Arquivo de texto no corpo de e-mail
cat $arq_descr >> $arq_email
# Criar lista de e-mails a partir de arquivo
readarray -t lista_emails < <(cat $DIR/helpers/destinatarios_teste.txt | grep $grupo | awk -F',' '{print $1}')
@viniroger
viniroger / trycatch.R
Created April 22, 2019 19:56
Try catch read CSV file with error function and warning print
diretorio = '/home/user/model'
uid = 1
filename = sprintf('%s/saida/saida_%s/prevaz_%s.csv', diretorio, 'semanal', uid)
values = tryCatch(read.csv(filename,as.is = TRUE),
error = function(e) NA, warning = function(w) print('Without semanal file'))
@viniroger
viniroger / randompass.sh
Created March 26, 2019 21:19
Generate random password
openssl rand -base64 8
@viniroger
viniroger / fill_random.py
Created March 21, 2019 09:37
Fill a column from a pandas dataframe with random values
import random
random.seed(42)
df['column_name'] = df['column_name'].apply(lambda v: random.random() * 100)
@viniroger
viniroger / print_all_df.py
Created February 28, 2019 08:39
Pretty-print an entire Pandas Series / DataFrame
def print_all_df(self, df):
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(df)
@viniroger
viniroger / bash_execution.py
Created February 28, 2019 08:38
Execute bash script using python
from subprocess import check_output
# List files using pattern and get most recent
bashCommand = ("ls -1t %s/saida/arquivos_clientes/cn*.txt | head -1" %path)
# Define file name as last string, striping by '/'
filename = str(check_output(bashCommand, shell=True).strip(), 'utf-8')
remoteFileName = filename.split('/')[-1]