This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.cache import add_never_cache_headers | |
class DisableClientSideCachingMiddleware(object): | |
""" | |
Internet Explorer / Edge tends to cache REST API calls, unless some specific HTTP headers are added by our | |
application. | |
- no_cache | |
- no_store | |
- must_revalidate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
def performance(fn): | |
def wrapper(*args, **kwargs): | |
t1 = time() | |
result = fn(*args, **kwargs) | |
t2 = time() | |
print(f'took {t2-t1}') | |
return result | |
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewRange: | |
current = 0 | |
def __init__(self, first, last): | |
self.first = first | |
self.last = last | |
def __iter__(self): | |
return self | |
def __next__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import viewsets | |
from .models import MyModel | |
from .serializers import MyModelWriteSerializer, MyModelReadSerializer | |
class MyViewSet(viewsets.ModelViewSet): | |
queryset = MyModel.objects.all() | |
def get_serializer_class(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATABASES = { | |
"default": { | |
"ENGINE": "django.db.backends.postgresql", | |
"NAME": "***********", | |
"USER": "************", | |
"PASSWORD": "*********", | |
"HOST": "localhost", | |
"PORT": "5432", | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo sysctl -w fs.inotify.max_user_watches=XXXXX | |
HERE XXXXX IS THE NUMBER OF FILE YOU WANT TO ADD IN WATCH LIST. | |
Typically what i do is : 1000000 | |
So the final CMD is : sudo sysctl -w fs.inotify.max_user_watches=1000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 | |
sudo /sbin/mkswap /var/swap.1 | |
sudo /sbin/swapon /var/swap.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Data Format: | |
_DB | |
___Collction | |
______Sub Collection | |
__________Data | |
TestChatHistory --------------------------------------->(Main DB) | |
>268 ------------------------------------------------->(Collection) | |
>>2691680604235655 ----------------------------------->(Sub-collection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Airlines.findById(id) | |
.populate({ | |
path: 'flights', | |
populate:[ | |
{ | |
path: 'planeType', | |
model: 'Plane' | |
}, | |
{ | |
path: 'destination', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var firebase = require("firebase"); | |
exports.handler = (event, context, callback) => { | |
context.callbackWaitsForEmptyEventLoop = false; //<---Important | |
var config = { | |
apiKey: "<<apikey>>", | |
authDomain: "<<app_id>>.firebaseapp.com", |
OlderNewer