Skip to content

Instantly share code, notes, and snippets.

View rafaelhenrique's full-sized avatar

Rafael Henrique da Silva Correia rafaelhenrique

View GitHub Profile
@rafaelhenrique
rafaelhenrique / go_references.md
Last active July 26, 2018 12:45
Go references for study
@rafaelhenrique
rafaelhenrique / measure_things_time.py
Created July 14, 2018 15:04
Measure things with time (DONT USE THIS!)
from time import time
start = time()
summation = 0
for element in range(1, 1000):
summation += element
end = time()
print(end - start)
start = time()
@rafaelhenrique
rafaelhenrique / measure_things_timeit.py
Last active July 14, 2018 15:03
Measure things with timeit
from timeit import timeit
for_summation = """
summation = 0
for element in range(1, 1000):
summation += element
"""
summation = """
sum(range(1, 1000))
@rafaelhenrique
rafaelhenrique / load_test.sh
Created July 14, 2018 14:47
Teste de carga com Apache Benchmark
#!/bin/bash
GENERATE_TAR=$(echo ${GENERATE_TAR})
DATETIME=$(date +%Y-%m-%d_%H.%M.%S)
OUTPUT_DIRECTORY="load_test_"$(echo $HOSTNAME)_${DATETIME}
REQUESTS_QUANTITY=4000
EXPECTED_THRESHOLD_MS=700
URL="http://someurl.com/"
echo '{"key1": "value1"}' > /tmp/postfile
# CONCURRENCY=(1 10 20 30 40 50 60)
CONCURRENCY=(60)
@rafaelhenrique
rafaelhenrique / profile_things.py
Last active July 14, 2018 14:58
Python profile some code
import cProfile
import pstats
import io
import pdb
pr = cProfile.Profile()
pr.enable()
[code here]
pr.disable()
@rafaelhenrique
rafaelhenrique / read_csv.py
Last active December 3, 2018 18:01
Read csv file
import csv
with open('file.csv', 'r', encoding='utf-8-sig') as csvfile:
reader = csv.DictReader(csvfile)
data = [line for line in reader]
@rafaelhenrique
rafaelhenrique / write_csv.py
Created July 5, 2018 12:12
Write csv file
import csv
result = [{'field1': 'teste', 'field2': 'teste'}, {'field1': 'teste1', 'field2': 'teste1'}]
with open('file.csv', 'w', encoding='utf-8') as csvfile:
fieldnames = ['field1', 'field2']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for row in result:
@rafaelhenrique
rafaelhenrique / upload_file_to_s3.py
Created March 27, 2018 21:33
Upload file to AWS S3 (with boto3)
import io
import boto3
aws_access_key_id = 'secret'
aws_secret_access_key = 'secret'
bucket_name = 'my-bucket'
_aws_access_key_id = aws_access_key_id
_aws_secret_access_key = aws_secret_access_key
_resource = boto3.resource(
's3',
@rafaelhenrique
rafaelhenrique / create_redis_container.sh
Created March 1, 2018 20:31
Create redis docker container
#!/bin/bash
PORT=$(echo $PORT)
NAME=$(echo $NAME)
VOLUME=$(echo $VOLUME)
DATE=$(date +"%d%m%Y-%H%M%S")
VERSION="latest"
SO=$(uname)
if [ "$PARAM" == '-h' ]; then
echo "environment: PORT, NAME, VOLUME"
@rafaelhenrique
rafaelhenrique / tsuru-service-api.service
Created March 24, 2017 17:58
Systemd unit of tsurud service
[Unit]
Description=Tsuru (tsuru-server-api)
After=network.target
Requires=mongod.service redis.service
Documentation=https://tsuru.io/
[Service]
Type=simple
ExecStart=/usr/bin/tsurud api --config=/etc/tsuru/tsuru.conf
PIDFile=/var/run/tsuru-server-api.pid