Skip to content

Instantly share code, notes, and snippets.

View afbio's full-sized avatar

Fabio Coelho afbio

  • São Paulo, Brazil
View GitHub Profile
@afbio
afbio / postgre_statement_timeout.py
Created May 2, 2018 20:08
Get and Set Statement Timeout to PostgreSQL using django
class StatementTimeout(object):
@classmethod
def _execute_query(cls, query, db_alias):
from django.db import connections
cur = connections[db_alias].cursor()
try:
cur.execute(query)
return cls._as_dict(cur) if cur.rowcount > 0 else True
@afbio
afbio / image_barcode_generator.py
Last active April 5, 2018 14:25
Generate barcode .png from a .csv data source file
import csv
import os
import requests
import shutil
import urllib
"""
Docs: http://labelary.com/service.html
"""
url = 'http://api.labelary.com/v1/printers/8dpmm/labels/3x1.5/0/'
@afbio
afbio / reset_sequence.py
Created March 29, 2018 12:54
Reset database sequence among tests on same module
# Postgre tested
@pytest.fixture(autouse=True)
def reset_sequence():
cur = connection.cursor()
cur.execute('ALTER SEQUENCE table_name RESTART WITH 1;')
@afbio
afbio / find_to_list_count_delete.sh
Last active March 2, 2018 21:27
Listing and filtering files in a directory using find command
#listar arquivos:
find . -type f
#listar diferentes do padrão:
find . -type f -not -name "*cteproc.xml"
#Contar colocando na frente um:
find . -type f | wc -l
find . -type f -not -name "*cteproc.xml" | wc -l
@afbio
afbio / copy_with_xxd.sh
Last active October 17, 2017 21:13
Copy/Send files using xxd
# WORKAROUND to use when "scp"/"kubectl cp"/"docker cp" is unvailable
# on local machine
xxd ~/file_aaa.xlsx > /tmp/bin_file_aaa
# md5sum to compare on end
md5sum ~/file_aaa.xlsx
# open and copy full content file
gedit /tmp/bin_file_aaa
@afbio
afbio / ps1
Created October 4, 2017 15:34
Bash PS1
# paste on .bashrc and run source command
PS1='\[\033[0;37m\][\t]\[\033[0;32m\][\u]\[\033[31m\][\h]`git branch 2>/dev/null | grep \* | head -1 | sed "s/\* //g" | awk "{ print \"[ \"\\\$1 \" ]\" }"` \[\033[1;33m\]\w\a\[\033[0m\]\n\$ '
@afbio
afbio / git.txt
Created October 4, 2017 15:28
Git tricks
# List branchs sorted by last commit(from config.user) date
git branch --list --sort=-committerdate
@afbio
afbio / db_snapshot_using_docker.md
Created December 10, 2015 19:16
Database's snapshot using Docker

Pull da imagem base para o DB

docker pull mysql:5.5

Pull da imagem a ser usada para extrair o snapshot. Pode ser qualquer outro que contenha o tar

docker pull ubuntu

Cria pasta onde serao salvos os snapshots

mkdir scenes

Criar o container com o DB