Skip to content

Instantly share code, notes, and snippets.

View ftfarias's full-sized avatar
🎯
Focusing

Felipe Farias ftfarias

🎯
Focusing
  • Data Lead at Alice
  • São Paulo, Brazil
View GitHub Profile
# !pip install watermark
%load_ext watermark
%watermark -udtz -v -m -iv -rg
@ftfarias
ftfarias / gist:2b2d5146e85aaa7b445a50f87a16e04c
Last active September 24, 2018 16:40
Read csv as dictionary from S3
import boto3
from io import TextIOWrapper, BytesIO
from gzip import GzipFile
import csv
import logging
import collections
from tqdm import tqdm_notebook as tqdm
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@ftfarias
ftfarias / aws_reserved_instances.sh
Last active August 29, 2018 14:11
Script to list reserved instances in AWS
#! /usr/bin/env python
from argparse import ArgumentParser
import boto3
import pandas as pd
CSV_FILENAME = 'ec2_reserves.csv'
ec2 = boto3.client('ec2')
@ftfarias
ftfarias / elastic_urllib3.py
Last active December 7, 2018 19:01
elasticsearch / urllib3
import os
import json
import urllib3
url_delete = 'http://172.31.x.x:9200/my_index/_delete_by_query'
query_delete = {
"query": { "match": { "fk_xxx": day }}
}
@ftfarias
ftfarias / Linux_useful_commands.txt
Last active October 11, 2018 16:55
Linux useful commands
watch -n 2 'ip address'
# Du para diretórios
https://dev.yorhel.nl/ncdu
Freeing disk space on your Linux server
- Get to the root of your machine by running cd /
- Run sudo du -h --max-depth=1.
- Note which directories are using a lot of disk space.
@ftfarias
ftfarias / readS3CSV.txt
Created May 22, 2018 19:09
How to read files from Amazon AWS S3 line by line
import boto3
import argparse
import elasticsearch
from io import TextIOWrapper
from gzip import GzipFile
import csv
fact_key = "/2018/05/15/mycsv_files"
BUCKET = 'csv_data'
print(f'Reading files at {fact_key}')
@ftfarias
ftfarias / basic.py
Last active August 4, 2022 13:52
basic general all-purpose python file template
"""
{USAGE}
python thisfile.py param1
"""
import sys
import os
import pprint as pp
import argparse
import logging
import traceback
@ftfarias
ftfarias / nlp_portugues.py
Created December 5, 2017 15:49
NLP Portugues
# Combinações e contrações do português
https://pt.wiktionary.org/wiki/Ap%C3%AAndice:Adv%C3%A9rbios_do_portugu%C3%AAs
https://pt.wiktionary.org/wiki/Ap%C3%AAndice:Gent%C3%ADlicos_e_top%C3%B3nimos_em_portugu%C3%AAs
CONTRACOES = [
# Com a preposição "com" + Artigos definidos
(('com','um'),'cum'),
# A preposição "de" + Artigos definidos
(('de','o'),'do'),
(('de','a'),'da'),
@ftfarias
ftfarias / import_request_zipped.py
Created November 3, 2017 19:38
Read from zipped file in internet
import requests
from io import BytesIO
from zipfile import ZipFile
# Download the dataset
dk = requests.get('http://www.ssfpack.com/files/DK-data.zip').content
f = BytesIO(dk)
zipped = ZipFile(f)
df = pd.read_table(
BytesIO(zipped.read('internet.dat')),
@ftfarias
ftfarias / data_cleaning.py
Last active April 7, 2020 17:59
Data cleaning
import csv
import re
EMAIL_REGEXP = '^[_A-Za-z0-9-+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,3})$'
#from tqdm import tqdm_notebook as tqdm
import gensim
import collections
import nltk