Skip to content

Instantly share code, notes, and snippets.

View vhcandido's full-sized avatar

Victor Hugo Cândido de Oliveira vhcandido

View GitHub Profile
@tomotake-koike
tomotake-koike / s3_gziped_text_lines.py
Last active March 28, 2020 21:41
Count lines of the gzip text file on S3
import boto3
import zlib
s3 = boto3.session.Session().client('s3')
resp = s3.get_object( Bucket='BUCKET', Key='PATH' )
b = resp['Body']
i = 0
cnt = 0
c = 0
decb = b''
dec = zlib.decompressobj(zlib.MAX_WBITS|32)
@pvgomes
pvgomes / python3_s3_to_redshift_loader.py
Created January 23, 2019 16:16
Load data from S3 to Redshift using Python3
############ REQUIREMENTS TO INSTALL ####################
# THIS SCRIPT use category table from AWS sample data (https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html)
# we use this sample data s3://awssampledbuswest2/tickit/category_pipe.txt
###### Linux users
#`sudo apt-get install libpq-dev`
###### Mac users
#`brew install libpq`
@tobywf
tobywf / boto3-gzip.py
Last active June 19, 2025 14:33
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""
@pratos
pratos / condaenv.txt
Created November 30, 2016 07:01
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
@RayLty
RayLty / gist:d828ebe4391e564c3319680dbd0dc300
Created November 14, 2016 22:34
Foreign Exchange Algorithmic Trading method
from base import *
import datetime
class FXBot(BaseBot):
def __init__(self):
super(FXBot, self).__init__()
self.contracts = [0]*8 # EURJPY/CHFJPY/USDCHF/EURCHF/EURCAD/EURUSD/USDJPY/USDCAD
self.cash = [0]*8 # JPY/EUR/USD/CHF/CAD
self.limits = [102000000, 900000, 1000000, 980000, 1300000] # JPY/EUR/USD/CHF/CAD
self.bids = [] # EURJPY/CHFJPY/USDCHF/EURCHF/EURCAD/EURUSD/USDJPY/USDCAD
self.asks = [] # EURJPY/CHFJPY/USDCHF/EURCHF/EURCAD/EURUSD/USDJPY/USDCAD
#required libraries
library(quantmod)
library(zoo)
library(chron)
#following section loads "Systematic Investor Toolbox"
setInternet2(TRUE)
con <- gzcon(url('https://github.com/systematicinvestor/SIT/raw/master/sit.gz', 'rb'))
source(con)
close(con)
library(quantmod)
library(zoo)
library(chron)
#following section loads "Systematic Investor Toolbox"
setInternet2(TRUE)
con <- gzcon(url('https://github.com/systematicinvestor/SIT/raw/master/sit.gz', 'rb'))
source(con)
close(con)
@BaxterEaves
BaxterEaves / bhc.py
Created July 16, 2015 21:20
Bayesian hierarchical clustering
"""
Copyright (C) 2015 Baxter Eaves
License: Do what the fuck you want to public license (WTFPL) V2
Bayesian hierarchical clustering.
Heller, K. A., & Ghahramani, Z. (2005). Bayesian Hierarchical Clustering.
Neuroscience, 6(section 2), 297–304. doi:10.1145/1102351.1102389
"""
import itertools as it
@Yagisanatode
Yagisanatode / Tkinter_filedialog.py
Last active July 15, 2021 11:58
Python 3 - Open file dialog window in tkinter with filedialog
#! Python 3.4
"""
Open a file dialog window in tkinter using the filedialog method.
Tkinter has a prebuilt dialog window to access files.
This example is designed to show how you might use a file dialog askopenfilename
and use it in a program.
"""
@TomAugspurger
TomAugspurger / to_redshift.py
Last active September 16, 2021 16:55
to_redshift.py
# see also https://github.com/wrobstory/pgshift
import gzip
from io import StringIO, BytesIO
from functools import wraps
import boto
from sqlalchemy import MetaData
from pandas import DataFrame
from pandas.io.sql import SQLTable, pandasSQL_builder