Skip to content

Instantly share code, notes, and snippets.

View akhundMurad's full-sized avatar
🦍

Murad Akhundov akhundMurad

🦍
View GitHub Profile

Contributor License Agreement

Thank you for your interest in contributing to the Pacta project.

This Contributor License Agreement ("Agreement") applies to any contribution that you make to the Pacta project.

  1. Definitions

"You" (or "Your") shall mean the copyright owner or legal entity

@akhundMurad
akhundMurad / ocl.md
Created December 17, 2024 16:43
Object Constraint Language (OCL) Cheatsheet

# Object Constraint Language (OCL) Cheatsheet

1. Introduction to OCL

The Object Constraint Language (OCL) is a formal language used to describe constraints, business rules, and logic that cannot be expressed using UML diagrams alone. OCL is declarative, meaning it describes what must be true, rather than how to make it true.

Common Use Cases:

  • Defining preconditions, postconditions, and invariants
  • Defining derived attributes
  • Specifying query operations
@akhundMurad
akhundMurad / dto_mapper.py
Last active December 27, 2022 16:50
Example of DTO mapper
from typing import Type
from automapper import create_mapper
from multimethod import multimethod
from src.domain.dto import ProfileDTO, UserDTO
class DTOMapper:
def __init__(self) -> None:
self._mapper = create_mapper()
from src.application.ports.uow import IUnitOfWork
from src.application.ports.analytics_gateway import IAnalyticsGateway
from src.domain.analytics.queries.analytics_query import AnalyticsQuery, AnalyticsQueryResult
class AnalyticsQueryHandler:
def __init__(self, uow: IUnitOfWork, analytics_gateway: IAnalyticsGateway):
self._uow = uow
self._analytics_gateway = analytics_gateway
@akhundMurad
akhundMurad / asgi.py
Last active September 27, 2022 18:27
Aiohttp client session and FastAPI DI
from di import ClientSessionManager, provide_client_session_stub, provide_client_session
async def on_shutdown() -> None:
await ClientSessionManager.close()
def build_asgi_application() -> FastAPI:
application = FastAPI(on_shutdown=[on_shutdown])
@akhundMurad
akhundMurad / dao.py
Created August 17, 2022 17:15
Example of seperation of concepts
from pymongo import MongoClient
class BaseDAO:
def create(self):
...
def get(self):
...
@akhundMurad
akhundMurad / example_di.py
Created August 15, 2022 16:36
DI with testing
def some_func(redis_client) -> dict:
data = redis_client.get(...)
# logic...
return data
class FakeRedisClient:
_storage = dict()
def get(key):
def build_app() -> FastAPI:
app = FastAPI()
nodepends_provide_dao = lambda: provide_dao(provide_session_factory)
nodepends_provide_service = lambda: provide_service(dao=nodepends_provide_dao())
app.dependency_overrides[provide_service_stub] = nodepends_provide_service
return app
# providers.py
def provide_dao() -> SomeDAO:
return SomeDAO()
def provide_service(dao_provider: Callable([], SomeDAO)) -> Service:
return Service(dao=dao_provider())
# tasks.py
import uuid
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.dialects import postgresql as sa_psql
from sqlalchemy.orm import registry, sessionmaker
mapper_registry = registry()