This file contains 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 logging | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s %(threadName)s %(message)s') | |
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) |
This file contains 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
# run it like `docker-compose up -d` | |
# then go to http://localhost:15672 and login with user and password `guest` | |
version: '3.8' | |
services: | |
rabbitmq: | |
image: rabbitmq:3.10-management-alpine | |
restart: always | |
# environment: | |
# - RABBITMQ_DEFAULT_USER=guest |
This file contains 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
""" | |
useful for local development and unit tests when tasks are run syncronously | |
""" | |
from your_app.settings import TESTING | |
from celery import Task | |
from celery.canvas import Signature | |
def run_task(task_signature: Signature): | |
if TESTING: |
This file contains 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
# put custom modules to ./custom_addons | |
version: '2' | |
services: | |
postgresql: | |
image: docker.io/bitnami/postgresql:13 | |
volumes: | |
- 'postgresql_data:/bitnami/postgresql' | |
environment: | |
# ALLOW_EMPTY_PASSWORD is recommended only for development. | |
- ALLOW_EMPTY_PASSWORD=yes |
This file contains 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
{ | |
"consumer": { | |
"name": "OrderService" | |
}, | |
"provider": { | |
"name": "UserService" | |
}, | |
"interactions": [ | |
{ | |
"description": "GetUser API call for UserA", |
This file contains 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 format_exception_as_python_does(e: BaseException): | |
# taken from https://stackoverflow.com/a/35498685 | |
return traceback.format_exception(type(e), e, e.__traceback__) | |
This file contains 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
# pip install saga_py | |
from saga import SagaBuilder, SagaError | |
counter1 = 0 | |
counter2 = 0 | |
def _print_counters(): | |
global counter1, counter2 | |
print(f'After this action, {counter1=}, {counter2=} \n') |
This file contains 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 dict_without_keys(data_: dict, keys: list): | |
""" | |
Example: | |
from dictdiffer import diff | |
assert list(diff( | |
dict_without_keys(listing.to_dict(), ['_id', '_cls', 'created_date', 'updated_date', 'rooms[].id', 'photos']), | |
dict_without_keys(normal_listing_dict, ['photos']) |
This file contains 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 method works well on ALL data | |
# see https://towardsdatascience.com/my-notes-for-singular-value-decomposition-with-interactive-code-feat-peter-mills-7584f4f2930a | |
import numpy as np | |
from sklearn import preprocessing | |
np.set_printoptions(precision=2) | |
X = np.array([ | |
[1,2,3], | |
[4,10,1], | |
[5,3,2], |
This file contains 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 visualize_grid_cv_params(grid_cv): | |
df = pd.DataFrame(grid_cv.cv_results_['params']) | |
df['score'] = grid_cv.cv_results_['mean_test_score'] | |
fig, axes = plt.subplots(1, len(grid_cv.param_grid), sharey=True, figsize=(15,4)) | |
i = 0 | |
for param in grid_cv.param_grid: | |
data = df.groupby(param).mean()['score'].to_dict() | |
param_values = list(data.keys()) |
NewerOlder