Skip to content

Instantly share code, notes, and snippets.

View favtuts's full-sized avatar

FavTuts favtuts

View GitHub Profile
go mod edit -module {NEW_MODULE_NAME}
-- rename all imported module
find . -type f -name '*.go' \
-exec sed -i -e 's,{OLD_MODULE},{NEW_MODULE},g' {} \;
@favtuts
favtuts / lru_cache.py
Last active February 23, 2022 08:30
Python cache using LRU_cache from functools standard library. More details on blog post: https://www.favtuts.com/every-python-programmer-should-know-lru_cache-from-the-standard-library/
from functools import lru_cache
from datetime import datetime
@lru_cache(maxsize=None)
def fib_cache(n):
if n < 2:
return n
return fib_cache(n-1) + fib_cache(n-2)
def fib_no_cache(n):
@favtuts
favtuts / retry-decorator.py
Last active February 22, 2022 04:45
Python retry decorator implements simple retry pattern with exponential backoff algorithm. More details on blog post: https://www.favtuts.com/retry-decorator-as-python-utility-to-protect-unexpected-one-off-exceptions-while-calling-apis/
from asyncio.log import logger
from functools import wraps
import time
import logging
import random
logger = logging.getLogger(__name__)
def log(msg, logger = None):
if logger: