Skip to content

Instantly share code, notes, and snippets.

View luizhenriquefbb's full-sized avatar

Luiz Henrique Freire Barros luizhenriquefbb

View GitHub Profile
@luizhenriquefbb
luizhenriquefbb / timeit_decorator.py
Created October 21, 2021 20:05
A decorator that prints how long a function took
# see gist of LogManager (https://gist.github.com/luizhenriquefbb/040124818a5c56ffba81d91929801be5)
def timeit(logger:LogManager=None):
def decorator(function):
def wrapper(*args, **kwargs):
ts = time.time()
result = function(*args, **kwargs)
te = time.time()
log_string = f'func:{function.__name__} args:[{args}, {kwargs}] took: {"{:.2f}".format(te-ts)} sec'
@luizhenriquefbb
luizhenriquefbb / pool_of_threads_example1.py
Last active July 29, 2021 15:41
example of a for in a pool of threads
def lambda_handler(event, context):
from concurrent.futures import ThreadPoolExecutor, as_completed
def task(data):
print(f"computing data {data}")
with ThreadPoolExecutor(max_workers = 5) as executor:
future_to_data = { executor.submit(task, data) : data for data in list(range(100)) }
response = []
@luizhenriquefbb
luizhenriquefbb / decorators.py
Last active April 16, 2021 15:09
timed memoized
import functools
import threading
import time
def timed_memoized(time_to_reset: int = 300):
"""
Decorator that caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned, and
not re-evaluated.
@luizhenriquefbb
luizhenriquefbb / logger.py
Last active October 18, 2021 18:44
Python logger
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import os
from logging.handlers import RotatingFileHandler
class LogManager:
def __init__(self, log_name,
@luizhenriquefbb
luizhenriquefbb / firebase_pre-request_script.js
Last active September 10, 2020 17:48 — forked from moneal/firebase_pre-request_script.js
Postman pre-request script to create a Firebase authentication JWT header.
/**
* This script expects the global variables 'refresh_token' and 'firebase_api_key' to be set. 'firebase_api_key' can be found
* in the Firebase console under project settings then 'Web API Key'.
* 'refresh_token' as to be gathered from watching the network requests to https://securetoken.googleapis.com/v1/token from
* your Firebase app, look for the formdata values
*
* If all the data is found it makes a request to get a new token and sets a 'auth_jwt' environment variable and updates the
* global 'refresh_token'.
*
* Requests that need authentication should have a header with a key of 'Authentication' and value of '{{auth_jwt}}'
@luizhenriquefbb
luizhenriquefbb / Git deploy-eng.md
Last active July 27, 2020 11:37
Deploying ONLY with git. How to configure a server to "listen" to pushes on a particular branch and automatically update itself.

Git deploy

English 🇺🇸

Deploy with Git

That is it! You read right. If you are building small applications and don't need to prepare a super complex environment to deploy it and just want to keep the code on an updated server, you can set up a bare repository on your remote machine and "listen" changes on the master. So, with a push, you can always update the code on the remote machine.

Step 1: Create the repository that will listen to the pushes on GIT and the folder where the files will be stored

@luizhenriquefbb
luizhenriquefbb / eng.md
Created July 26, 2020 21:37
The first post is about deploying ONLY with git. How to configure a server to "listen" to pushes on a particular branch and automatically update itself.

Git deploy

English 🇺🇸

Deploy with Git

That is it! You read right. If you are building small applications and don't need to prepare a super complex environment to deploy it and just want to keep the code on an updated server, you can set up a bare repository on your remote machine and "listen" changes on the master. So, with a push, you can always update the code on the remote machine.

Step 1: Create the repository that will listen to the pushes on GIT and the folder where the files will be stored

@luizhenriquefbb
luizhenriquefbb / Nos.py
Last active June 7, 2020 17:14
busca a estrela
import numpy as np
# Variável onde seu índice representa a posíção no labirinto
# E seu valor representa os possíveis lugares para se mover
# em outras palavras, a tabela de adjacencia
NOS = [
[1],#nó 0
[0, 2, 4, 3],#nó 1
[1],#nó 2
[1, 5],#nó 3
@luizhenriquefbb
luizhenriquefbb / readme.md
Created April 4, 2020 20:36
[pm2] how to

Install

yarn global add pm2

edit the file ~/.bashrc and add the following line in the end

export PATH=$(yarn global bin):$PATH
@luizhenriquefbb
luizhenriquefbb / .pylintrc
Created March 16, 2020 18:39
pylint config
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS