Skip to content

Instantly share code, notes, and snippets.

View eliassoares's full-sized avatar
🐺
I'm tired of reading about the achievements of better men - Samwell Tarly

Elias Soares eliassoares

🐺
I'm tired of reading about the achievements of better men - Samwell Tarly
View GitHub Profile
@eliassoares
eliassoares / test_main.py
Created May 28, 2020 11:58
Testes das funções do post sobre como documentar seu código.
from main import calculate_simple_interest_investment, calculate_compound_interest_investment
def test_calculate_compound_interest_investment_when_principal_amount_is_zero():
principal_amount = 0.0
rate = 0.07
time = 2
expected_interest = 0
interest = calculate_compound_interest_investment(
@eliassoares
eliassoares / main.py
Last active May 28, 2020 11:31
Funções do post sobre como documentar seu código.
def calculate_compound_interest_investment(
principal_amount: float, rate: float, time: int
) -> float:
"""
Returns the compound interest an accrued amount that includes
principal plus interest.
:param principal_amount: float
:param rate: float
:param time: int
@eliassoares
eliassoares / postgre_audit_trigger_aws_rds.sql
Last active November 23, 2019 01:34
Triggers de auditoria do postgre para RDS da AWS. Adaptação do: https://github.com/2ndQuadrant/audit-trigger/blob/master/audit.sql
-- An audit history is important on most tables. Provide an audit trigger that logs to
-- a dedicated audit table for the major relations.
--
-- This file should be generic and not depend on application roles or structures,
-- as it's being listed here:
--
-- https://wiki.postgresql.org/wiki/Audit_trigger_91plus
--
-- This trigger was originally based on
-- http://wiki.postgresql.org/wiki/Audit_trigger
from re import findall, M, I
import os.path
def parse_queries():
"""
Irá parsear um arquivo .sql com as queries de SELECT necessárias
e irá retornar um dicionário contendo o nome da query no arquivo, como chave
e a query especificamente como valor.
"""
@eliassoares
eliassoares / json_to_map.go
Created September 17, 2018 00:10 — forked from cuixin/json_to_map.go
json to map[string]interface{} example in golang
package main
import (
"encoding/json"
"fmt"
)
func dumpMap(space string, m map[string]interface{}) {
for k, v := range m {
if mv, ok := v.(map[string]interface{}); ok {
@eliassoares
eliassoares / listAllDatabases.py
Created September 12, 2018 12:00
List all databases Postgres
conn = psycopg2.connect("user='eliassoares' host='127.0.0.1' password='mysecretpassword'")
cur = conn.cursor()
cur.execute('SELECT datname FROM pg_database WHERE datistemplate = false;')
rows = cur.fetchall()
print(rows)
@eliassoares
eliassoares / neo4j_readme
Created April 25, 2018 23:34
Tutorial Neo4j
1° Configura os nós:
-Configurando o nó para busca:
CREATE INDEX ON :Person(personID);
CREATE INDEX ON :Person(name);
-Configurando a chave:
CREATE CONSTRAINT ON (p:Person) ASSERT p.personID IS UNIQUE;
#Um INDEX não pode ser usado como chave, caso o tenha feito, usa-se:
DROP INDEX ON :Person(name);
para retirar o index.
@eliassoares
eliassoares / mysql-docker.sh
Created January 22, 2018 01:02 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@eliassoares
eliassoares / gist:604fc73005584b6dd22b59091e03f33c
Created December 14, 2017 00:09 — forked from gjreda/gist:7433f5f70299610d9b6b
pandas' read_csv parse_dates vs explicit date conversion
# When you're sure of the format, it's much quicker to explicitly convert your dates than use `parse_dates`
# Makes sense; was just surprised by the time difference.
import pandas as pd
from datetime import datetime
to_datetime = lambda d: datetime.strptime(d, '%m/%d/%Y %H:%M')
%time trips = pd.read_csv('data/divvy/Divvy_Trips_2013.csv', parse_dates=['starttime', 'stoptime'])
# CPU times: user 1min 29s, sys: 331 ms, total: 1min 29s
# Wall time: 1min 30s
@eliassoares
eliassoares / bitbot.py
Last active December 13, 2017 10:02
bitbot.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Version: 2.0
import urllib
import json
#Coloque as informações sobre suas comprar aqui:
compras = [