Skip to content

Instantly share code, notes, and snippets.

View manjitkumar's full-sized avatar
:octocat:
There's no place like ~/

Manjit Kumar manjitkumar

:octocat:
There's no place like ~/
View GitHub Profile
"""
In this python implementation of LRUCache,
We are using a hashmap `cache={}` to be able to retrieve data at O(1) and
using a Doubly Linked List to maintain the order of keys to know which one
are most recently used to least recently used as we move from head to tail.
"""
class Node:
def __init__(self, key, value, next=None, prev=None) -> None:
@manjitkumar
manjitkumar / mixins.py
Last active February 11, 2017 12:02
dynamic fields modification in django restframework serializer
from rest_framework import serializers
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
'''
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displayed.
'''
def __init__(self, *args, **kwargs):
super(DynamicFieldsModelSerializer, self).__init__(*args, **kwargs)