Skip to content

Instantly share code, notes, and snippets.

View wesleyit's full-sized avatar

Wesley Rodrigues wesleyit

View GitHub Profile
@wesleyit
wesleyit / Stocks 2017.ipynb
Created February 16, 2018 02:30
Brazilian Stocks (2017)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wesleyit
wesleyit / get_uol_finance.py
Created February 27, 2018 00:30
Get Brazilian economic information from UOL's website
from os import system
from requests import get
from bs4 import BeautifulSoup
headers = {'Accept': 'text/html, application/xhtml+xml, application/xml',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'en-US, en',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)'
}
@wesleyit
wesleyit / R_basic_packages.r
Created April 18, 2018 19:15
Install some R useful packages
install.packages(c("ggplot2", "reshape2", "plyr", "languageR",
"lme4", "psych", "RMySQL", "RPostgresSQL", "RSQLite", "xlsx",
"XLConnect", "foreign", "dplyr", "tidyr", "stringr", "lubridate",
"ggplot2", "ggvis", "htmlwidgets", "googleVis", "maptools",
"maps", "ggmap", "zoo", "xts", "quantmod", "httr", "jsonlite",
"sp", "neuralnet", "RODBC", "gmodels", "class", "tm", "wordcloud",
"rpart", "kernlab", "e1071", "randomForest", "caret", "ROCR"))
@wesleyit
wesleyit / start_local_db.sh
Created May 14, 2018 12:13
Start a local container with Postgresql
mkdir -p share
mkdir -p pgdata
docker rm -f local_db || true
docker run --name local_db \
-e POSTGRES_PASSWORD=secret \
-p 5432:5432 \
-v $(pwd)/share:/share \
-v $(pwd)/pgdata:/var/lib/postgresql/data \
@wesleyit
wesleyit / test_tensorflow.py
Created May 15, 2018 17:40
Test tensorflow to verify the GPU availability
from tensorflow.python.client import device_lib
def get_available_devices():
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos]
print(get_available_devices())
@wesleyit
wesleyit / imc.py
Created May 20, 2018 01:30
Creating a graphical application using python and QT
import sys
import time
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
class IMC(QDialog):
def __init__(self):
super().__init__()
loadUi('imc.ui', self)
@wesleyit
wesleyit / get_csv.py
Created August 13, 2018 13:19
Get a CSV file from a SQL query
import sys
import pyodbc as odbc
import datetime
dsn = sys.argv[1]
query_file = sys.argv[2]
csv_file = sys.argv[3]
print(f'Connecting to {dsn}')
print(f'Executing {query_file}')
@wesleyit
wesleyit / get_csv_by_1000.py
Created August 13, 2018 13:20
Get a CSV file from a SQL query using batches of 1000 lines
import sys
import pyodbc as odbc
import datetime
dsn = sys.argv[1]
query_file = sys.argv[2]
csv_file = sys.argv[3]
print(f'Connecting to {dsn}')
print(f'Executing {query_file}')
@wesleyit
wesleyit / pandas_sql_odbc.py
Created August 31, 2018 18:08
Pandas fetching SQL from Athena with pyODBC
import pandas as pd
import pyodbc as odbc
import os
query = 'select * from vendas'
# Trago os dados do servidor caso não exista um cache local,
# senão apenas carrego o cache
if os.path.isfile('./dados/julho_com_sala.csv'):
@wesleyit
wesleyit / offline_setup.sh
Created August 31, 2018 21:38
Control/Block the internet access of specific programs and commands
#!/bin/bash
# Com este script você cria uma forma de executar comandos
# que não terão acesso à rede externa e Internet.
# Por exemplo, se você quiser forçar o Spotify a fica offline:
# offline spotify.bin
sudo groupadd offline
echo '#!/bin/bash' | sudo tee /usr/local/bin/offline
echo 'sg offline "$*"' | sudo tee -a /usr/local/bin/offline
sudo chmod a+x /usr/local/bin/offline