Skip to content

Instantly share code, notes, and snippets.

View dp-quant's full-sized avatar

Dmytro Podoprosvietov dp-quant

View GitHub Profile
@dp-quant
dp-quant / opp.py
Last active March 24, 2023 13:58
oop
class Building:
# do not use magic words
PLACE_OUT_OF_STOCK = 'Out of Stock'
PLACE_REMOTE_WAREHOUSE = 'Remove Warehouse'
# it's just an optimization
__slots__ = ['_material', '_color', '_number', '_store_place', '_original_place']
# lets make everything private
def __init__(self, material: str, color: str, store_place: str, number: int=0):
@dp-quant
dp-quant / ct.py
Last active January 27, 2021 16:46
import sys
import re
from collections import defaultdict
try:
testing_string = sys.argv[1]
except IndexError:
exit(1)
print('Initial String: ', testing_string)
import time
import json
import orjson
import rapidjson
m = {
"timestamp": 1556283673.1523004,
"task_uuid": "0ed1a1c3-050c-4fb9-9426-a7e72d0acfc7",
"task_level": [1, 2, 1],
"action_status": "started",
@dp-quant
dp-quant / client.py
Created August 31, 2020 12:09 — forked from zapstar/client.py
Python Asyncio SSL client and server examples
#!/usr/bin/env python3
import asyncio
import ssl
@asyncio.coroutine
async def echo_client(data, loop):
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_ctx.options |= ssl.OP_NO_TLSv1
@dp-quant
dp-quant / customize-save-in-django-admin-inline-form.org
Created January 29, 2020 08:22 — forked from shymonk/customize-save-in-django-admin-inline-form.org
How to customize save in django admin inline form?

Customize Save In Django Admin Inline Form

Background

This is a common case in django ORM.

from django.db import models

class Author(models.Model):
from rest_framework.test import APITestCase
from rest_framework import status
from django.core.urlresolvers import reverse
from core.tests.creator_mixin import TestSuitesCreatorMixin
from ..models import ContractChangesRecord
from profilesmanagement.constants import SUBSCRIPTION_LEVEL_CHOICES
import logging
logger = logging.getLogger(__name__)
import datetime
from django.conf import settings
from django.apps import apps
from django.test import TestCase, mock
from django.core.urlresolvers import reverse
import random
from rest_framework.test import APIRequestFactory
from ..serializers import AccountStatusesSerializer, CreateAccountSerializer, UpdateAccountSerializer,\
RetrieveAccountSerializer
from ..constants import STATUS_CHOICES
from django.test import TestCase, mock
from django.conf import settings
from django.apps import apps
import datetime
from ..constants import STATUS_CHOICES
class AccountModelTestCase(TestCase):
TEST_USERNAME = 'test_user'
TEST_EMAIL = '[email protected]'
class Private:
__number = 1
# def __add__(self, other):
def __say(self):
print('private say')
def say(self):
print('public say')
self.__say()
def _say(self):
class Building:
__matherial = None
__color = None
__quantity = 0
def __init__(self, matherial, color, number = 0):
self.__matherial = matherial
self.__color = color
self.__quantity = number