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 / sqlalchemy-truncate_db.py
Last active April 5, 2023 03:50
Sqlalchemy: Truncate all tables
def truncate_db(engine):
# delete all table data (but keep tables)
# we do cleanup before test 'cause if previous test errored,
# DB can contain dust
meta = MetaData(bind=engine, reflect=True)
con = engine.connect()
trans = con.begin()
con.execute('SET FOREIGN_KEY_CHECKS = 0;')
for table in meta.sorted_tables:
con.execute(table.delete())
@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",
@absent1706
absent1706 / yandex_api_example.php
Created April 8, 2016 13:00
PHP:yandex API example
<?php
/*
Пример программного кода для работы с API сервиса Яндекс.Директ
В примере использован рекомендуемый синтаксис для работы с API сервиса Яндекс.Директ
на языке PHP с использованием протокола JSON и авторизацией по токенам.
Обращаем внимание, что все текстовые данные должны быть в кодировке UTF8
@absent1706
absent1706 / example.html
Last active July 24, 2021 12:10
Bootstrap-collapse rotate icon. https://jsfiddle.net/1L3xy40k/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
[data-toggle="collapse"][aria-expanded="true"] > .js-rotate-if-collapsed
{
-webkit-transform: rotate(180deg);
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')