Skip to content

Instantly share code, notes, and snippets.

View hectorcanto's full-sized avatar

Héctor Canto hectorcanto

View GitHub Profile
@hectorcanto
hectorcanto / test_capture_log.py
Created February 13, 2019 15:15
An example on how to capture and test logs with pytest.
import time
import logging
import sqlite3
import pytest
logger = logging.getLogger("ExampleDBClient")
RECONNECT_SLEEP = 30
RECONNECT_ATTEMPTS = 3
@hectorcanto
hectorcanto / pipenv.txt
Last active March 13, 2019 11:33
[Pipenv] pipenv commands #python #pip #pipenv
pipenv -h
pipenv install
pipenv --python3.7
pipenv shell
pipenv install --dev sphinx
pipenv install --dev sphinx --skip-lock
@hectorcanto
hectorcanto / .bashrc
Last active March 12, 2019 15:42
[Configure git aliases] A script to configure several git aliase #git
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;33m\]\$(git_branch)\[\033[00m\]\$ "
alias g='git'
source /usr/share/bash-completion/completions/git
complete -o default -o nospace -F _git g
@hectorcanto
hectorcanto / git_commands.sh
Last active March 19, 2019 11:43
[Git recurrent commands] Git commands that come useful from time to time #git
git rm --cached filename # Remove a file from repository without removing it locally
git reset --hard HEAD~2 # Delete last 2 commits, code included
git diff --name-only $commit # State the files changed in a commit
@hectorcanto
hectorcanto / psql.txt
Last active August 13, 2019 16:57
[postgres quick commands] some interesting commands for Postgres PSQL #db #postgres
ALTER SEQUENCE id_seq_player RENAME TO player_id_seq; # rename a sequence artifact
ALTER SEQUENCE model_id_seq RESTART WITH 1; # there is also select setval();
# Remove connections from a certain DB, useful for ill-finished test runs.
SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='DB_NAME';
@hectorcanto
hectorcanto / networking.sh
Created July 4, 2019 13:08
[Network commands] Command to check open ports and the like #networkin #ops
sudo nmap --min-hostgroup 100 -F -sS -n -T4 $IP/32
nc
@hectorcanto
hectorcanto / elastic.txt
Last active July 12, 2019 10:45
[Elastic commands] Some recurrent Elastic commands #elasticsearch #kibana
# Get all indices, verbose
GET /_cat/indices?v
# Create an index with a mapping
PUT index
{
"mappings": {
"_doc": {
"properties": {
"field": {
@hectorcanto
hectorcanto / adr-template.md
Last active August 1, 2022 07:36
A template for Arquitecture Decision Records

ADR Template

Short Title

Short title of solved problem and solution [Describe the general problem and the chosen solution in free from in a few sentences. Leave specific details for the following sections]

app: for application, many things are considered an application. Use adjectives like web_app, phone_app, django_app
api: application programming interface (any communication protocol may be labelled an API, user rest_api when possible)
rel: relation or relative?
srv: server or service?
@hectorcanto
hectorcanto / Makefile
Created November 11, 2020 11:56
A curated Makefile for a Python repository, with commands for using several code quality and security tools like Pylint, Flake, Bandit, Trivy ... Assumes everything is installed, a full demo repo is pending (it is a promise)
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
RED="\\e[91m"
GREEN="\\e[32m"
BLUE="\\e[94m"
YELLOW="\\e[33m"
REGULAR="\\e[39m"
REPORTS=".coverage-reports"
SRC="app"
VERSION=$(shell cat ${SRC}/__init__.py | head -n 1 | cut -d" " -f 3 | tr -d "'")