Skip to content

Instantly share code, notes, and snippets.

View sillasgonzaga's full-sized avatar

Sillas Teixeira Gonzaga sillasgonzaga

View GitHub Profile
@sillasgonzaga
sillasgonzaga / api_quotas_fundos.R
Last active June 15, 2023 13:17
API para baixar quotas de fundos
library(httr)
library(magrittr)
library(xml2)
library(rvest)
url_raw <- "http://dados.cvm.gov.br/dados/FI/DOC/INF_DIARIO/DADOS/"
output_file <- "fundos/api/informe_diario.csv"
csv_links <- httr::GET(url_raw) %>%
httr::content("text") %>%
import panel as pn # GUI
pn.extension()
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model's output
)
# filtrar ano mais recente
df_idhm = df_idhm[df_idhm['ANO'] == np.max(df_idhm['ANO'])]
# selecionar colunas
df_idhm = df_idhm[['Codmun7', 'IDHM']]
# renomear colunas
df_idhm.columns = ['cod_municipio', 'idhm']
df_idhm.head()
# baixar dados
library(tidyverse)
library(foreign)
library(readxl)
library(janitor)
library(fuzzyjoin)
# download.file("http://www.metro.sp.gov.br/pesquisa-od/arquivos/Pesquisa-Origem-Destino-2017-Banco-Dados.zip",
# destfile = "od.zip")
#
cdb <- function(capital, data_aplicacao, data_resgate, di, pct_cdi){
library(dplyr)
library(bizdays)
dias_corridos <- as.numeric(difftime(data_resgate, data_aplicacao, units = "days"))
# computar biz days entre datas
bizdays::create.calendar("Brazil/ANBIMA",
bizdays::holidaysANBIMA,
weekdays=c("saturday", "sunday"))
library(tabulizer)
library(tidyverse)
arquivo <- "C:/Users/sillas.gonzaga/Downloads/gsa.pdf"
tab <- tabulizer::extract_tables(arquivo, encoding = "UTF-8", method = "lattice")
map(tab,dim)
# extrair tabelas com 8 colunas
@sillasgonzaga
sillasgonzaga / plot_rf_tree.R
Last active November 6, 2020 18:32
Plot a tree from a Random Forest Model
plot_rf_tree <- function(final_model, tree_num, shorten_label = TRUE) {
# source: https://shiring.github.io/machine_learning/2017/03/16/rf_plot_ggraph
# get tree by index
tree <- randomForest::getTree(final_model,
k = tree_num,
labelVar = TRUE) %>%
tibble::rownames_to_column() %>%
# make leaf split points to NA, so the 0s won't get plotted
def correl_df(dframe):
correl_matrix = dframe.corr()
# Select upper triangle of correlation matrix
upper = correl_matrix.where(np.triu(np.ones(correl_matrix.shape), k=1).astype(np.bool)).head()
upper = upper.unstack().reset_index()
# rename columns
upper.columns = ['var1', 'var2', 'correl']
# drop na
upper = upper.dropna()
upper['correl_abs'] = np.abs(upper['correl'])
library(spotifyr)
library(tidyverse)
Sys.setenv(SPOTIFY_CLIENT_ID = '')
Sys.setenv(SPOTIFY_CLIENT_SECRET = '')
xml <- read_html("https://developer.spotify.com/documentation/general/guides/scopes/")
scopes <- xml %>% html_nodes("code") %>% html_text() %>% unique()
auth <- get_spotify_authorization_code(scope = scopes)
@sillasgonzaga
sillasgonzaga / dash_runner.py
Created March 15, 2016 23:59 — forked from ChuckWoodraska/dash_runner.py
Used to sniff traffic for Amazon dash button and play a song through my chromecast.
import time
import sys
import logging
import pychromecast
from scapy.all import *
mac_address = '00:00:00:00:00:00'
def arp_display(pkt):
if pkt[ARP].op == 1:
if pkt[ARP].hwsrc == mac_address: