Saturday 3 October 2015

Protagoras’s Paradox a real life example of deadlock.

It is part of ancient Greek history a unsolved case .It is used in debates of law schools as a logic problem . 

Case -

Protagoras agreed to instruct a poor young man, Euthalos (from a working-class family) in law and rhetoric free of charge on the condition that he would pay the Sophist’s fee in full if, and only if, he won his first court case. Once Euthalos had completed his course of study with Protagoras he assiduously avoided taking any cases at all. Protagoras, finally out of patience with the young man, took him to court for payment and argued thusly: “ If I win this case, Euthalos will have to pay me what he owes me. If I do not win this case then Euthalos will still have to pay me because, under our agreement, he will then have won his first court case. Therefore, no matter what the outcome, Euthalos will have to pay me.” Euthalos, however, contested this claim, stating, “If I win this case I will not have to pay Protagoras, as the court has declared his case invalid. If I do not win this case I still do not have to pay as I will then have not won my first court case. Therefore, no matter what, I do not have to pay.”

In technical term we can consider it a real life example of the deadlock in computer science. 

Source : Quora , http://www.ancient.eu

Wednesday 23 September 2015

create a RESTful API in Django without using thirdparty framework like Django Rest Framework and Tastypie


If you want to implement Rest API in django and you do not want to user Django Rest Framework , tastypie or any other third party framework then you can follow rules give below to implement REST API almost .

Use HTTP verbs  (GET, POST, PUT, DELETE, PATCH)

You should return response in JSON(you can also return in xml)

If you are writing one url to group all of your api related to a object calling by using proper HTTP verbs  then you can almost achieve it.

URL       /users/

Then REST API for user related operations can be -


GET  /users/        To get all users's information.
GET  /users/<pk>/    To get a user's information.
POST  /users/   To create a user.
PUT /users/<pk>   To update a user information.
PUT  /users/   To update all user's information at once.
DELETE /users/<pk>/  To delete a user.
DELETE /users/  To delete all users.


To implement view it will be great if you are writing class based views and you view can be .

class UserView(View):
    def get(self, request, *args, **kwargs):
        # logic
    def post(self, request, *args, **kwargs):
        # logic
    def put(self, request, *args, **kwargs):
        # logic
    def delete(self, request, *args, **kwargs):
        # logic


You can return JSON in response by following below pattern in each your method in your view.

import json

from django.http import HttpResponse

def method(arguments):
    # logic --
    # logic  --
    data = {'pk': '1'}
    response = json.dumps(data)
    return HttpResponse(response, content_type="application/json")