Skip to content

Instantly share code, notes, and snippets.

View caiaffa's full-sized avatar
🏠
Working from home

Luís Felipe caiaffa

🏠
Working from home
View GitHub Profile
@caiaffa
caiaffa / cache.py
Created April 16, 2019 17:19 — forked from cloverstd/cache.py
tornado cache
# coding: utf-8
try:
import cPickle as pickle
except ImportError:
import pickle
try:
import hashlib
sha1 = hashlib.sha1
import sys
from contextlib import contextmanager
import paramiko
sys.tracebacklimit = 0
class FtpClient:
import os
import gnupg
def initialize_gpg(key_paths):
gpg = gnupg.GPG()
for path in key_paths:
key_data = open(path).read()
gpg.import_keys(key_data)
# return
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Example of thread pool
https://docs.python.org/3/library/concurrent.futures.html
https://docs.python.org/3/library/multiprocessing.html
"""
import concurrent.futures as confu
import multiprocessing.pool as mpp
import time
def map_paramiko_log_methods(respective_method, module) -> None:
for each_class in map(module.__dict__.get, module.__all__):
if hasattr(each_class, '_log'):
each_class._log = respective_method
def log_wrapper(*args, **kwargs):
pass
@caiaffa
caiaffa / mock_requests.py
Created June 24, 2019 14:14 — forked from evansde77/mock_requests.py
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError
import calendar
import time
from datetime import timedelta, datetime
from aiobreaker import CircuitBreaker
from aiobreaker.state import STATE_CLOSED
from aiobreaker.storage.redis import CircuitRedisStorage
from functools import wraps
from configs.settings import CB_SETTINGS, CACHE_KEY_PREFIX
from helpers.cache_servers import RedisServer
@caiaffa
caiaffa / BSTNode.py
Created August 19, 2019 21:57 — forked from stummjr/BSTNode.py
BSTNode.py - Binary Search Tree
# -*- encoding:utf-8 -*-
from __future__ import print_function
class BSTNode(object):
def __init__(self, key, value=None, left=None, right=None):
self.key = key
self.value = value
self.left = left
@caiaffa
caiaffa / Python Async Decorator.py
Created August 23, 2019 17:08 — forked from Integralist/Python Async Decorator.py
[Python Async Decorator] #python #asyncio #decorator
import asyncio
from functools import wraps
def dec(fn):
@wraps(fn)
async def wrapper(*args, **kwargs):
print(fn, args, kwargs) # <function foo at 0x10952d598> () {}
await asyncio.sleep(5)
@caiaffa
caiaffa / docker-compose.yaml
Created January 3, 2020 15:00
Redis Cluster for Mac
version: '3'
services:
redis-1:
container_name: redis-1
image: redis:latest
ports:
- 7000:7000
- '7001:7001'
- '7002:7002'
- '7003:7003'