Skip to content

Instantly share code, notes, and snippets.

@absent1706
absent1706 / test.py
Created July 13, 2023 12:03
logging.basicConfig
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)
@absent1706
absent1706 / docker-compose.yml
Created June 8, 2023 09:40
Docker-compose file for RabbitMQ
# 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
@absent1706
absent1706 / celery_sync.py
Created October 21, 2022 10:30
run and retry Celery tasks synchronously
"""
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:
@absent1706
absent1706 / docker-compose.yml
Created August 3, 2022 08:59
Odoo docker-compose file
# 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
@absent1706
absent1706 / pact_contract_example.json
Last active February 17, 2022 12:27
Pact contract example
{
"consumer": {
"name": "OrderService"
},
"provider": {
"name": "UserService"
},
"interactions": [
{
"description": "GetUser API call for UserA",
def format_exception_as_python_does(e: BaseException):
# taken from https://stackoverflow.com/a/35498685
return traceback.format_exception(type(e), e, e.__traceback__)
# 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')
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'])
@absent1706
absent1706 / svd-from-scratch.py
Created April 25, 2019 16:36
svd-from-scratch
# 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],
@absent1706
absent1706 / datascience-visualize-grid-cv.py
Created April 7, 2019 08:49
datascience-visualize-grid-cv
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())