This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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}}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import logging | |
import os | |
from logging.handlers import RotatingFileHandler | |
class LogManager: | |
def __init__(self, log_name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
OlderNewer