Skip to content

Instantly share code, notes, and snippets.

View moraisaugusto's full-sized avatar
🎯
Focusing

Augusto Morais moraisaugusto

🎯
Focusing
View GitHub Profile
@moraisaugusto
moraisaugusto / np-where-zero-division.py
Created April 17, 2019 09:15
Prevent np zero division
import numpy as np
x = np.array([[2., 54, 2., 5, 2],
[2, 0, 0.02, 0.00005, 0.0]])
y = [2, 0, 0.02, 0.00005, 0.0]
print(np.where(x[0] > 1e-3, x[0]/(x[1]+(x[1]==0)), 0))
@moraisaugusto
moraisaugusto / dos2unix-file.sh
Created May 23, 2019 14:22
Check if file is dos or unix
# the faster way to check if a file contains CRLF character
dos2unix -ic *.py | xargs dos2unix --info
@moraisaugusto
moraisaugusto / tabularTableStorage.py
Created June 24, 2019 07:54
Create a Azure Tabular Table storage
#!/usr/bin/env python3
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
def execute():
"""docstring for execute"""
the_connection_string = "DefaultEndpointsProtocol=https;AccountName=MYACCOUNTNAME;AccountKey=ACCOUNTKEY;EndpointSuffix=core.windows.net"
@moraisaugusto
moraisaugusto / azureBlobStorage.py
Created June 24, 2019 07:58
Create a Azure Blob Storage Object
#!/usr/bin/env python3
import os, uuid, sys
from azure.storage.blob import BlockBlobService, PublicAccess
def run_sample():
try:
# Create the BlockBlockService that is used to call the Blob service for the storage account
block_blob_service = BlockBlobService(
account_name='ACCOUNTNAME',
git checkout master
git checkout -b hotfix_branch
# work is done commits are added to the hotfix_branch
git checkout develop
git merge hotfix_branch
git checkout master
git merge hotfix_branch
@moraisaugusto
moraisaugusto / drop_role.sql
Created August 1, 2019 08:09
Remove user/role from Postgres
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM username;
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM username;
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM username;
DROP USER username;
DROP ROLE username;
@moraisaugusto
moraisaugusto / env.py
Created August 6, 2019 15:32
SqlAlchemy + Alembic + DYNACONF +SSL enabled
from __future__ import with_statement
import sys,os
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
@moraisaugusto
moraisaugusto / docker-compose.yaml
Last active November 5, 2019 16:14
debug python from docker container
# You should add the line
# `stdin_open: true` and
# `tty: true` on your docker-compose file.
# Then, just add the `__import__("ipdb").set_trace()` as
# usually you do in your python code.
version: "3"
services:
app_tests:
build: .
@moraisaugusto
moraisaugusto / psql_dump_restore.sh
Created November 26, 2019 13:56
Postgresql - Dump and Restore
# to perform a dump with only the Data, not the schema ( using SSL)
$ PGSSLMODE=allow pg_dump -v -Fc --data-only -h HOST -p 5432 -U USERNAME DB_NAME --exclude-table-data NOT_THIS_TABLE > testing-data-only.sql
# to restore the dump
$ pg_restore -h localhost -p 5432 -U USERNAME -d DB_NAME < testing-data-only.sql
@moraisaugusto
moraisaugusto / timeout-postgres.md
Last active January 28, 2021 22:15
Dealing with idle connections in Azure Postgres