Skip to content

Instantly share code, notes, and snippets.

View AyemunHossain's full-sized avatar
🔥
Banging Laravel for LMS

Ayemun Hossain AyemunHossain

🔥
Banging Laravel for LMS
View GitHub Profile
@AyemunHossain
AyemunHossain / middlewares.py
Created February 24, 2022 05:34
Disable Client Side Caching in Django
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
@AyemunHossain
AyemunHossain / performanceDecorator.py
Created February 26, 2022 08:43
Performance Chack by decorators
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
@AyemunHossain
AyemunHossain / NewRange.py
Created February 26, 2022 10:06
Implement Your Own Range Function
class NewRange:
current = 0
def __init__(self, first, last):
self.first = first
self.last = last
def __iter__(self):
return self
def __next__(self):
@AyemunHossain
AyemunHossain / Apiview.py
Created February 27, 2022 08:05
Different Read and Write Serializers
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):
@AyemunHossain
AyemunHossain / settings_dbsection.py
Created February 28, 2022 15:11
postgresql connection in django
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "***********",
"USER": "************",
"PASSWORD": "*********",
"HOST": "localhost",
"PORT": "5432",
}
}
@AyemunHossain
AyemunHossain / fileWatcherLimit.txt
Created December 12, 2022 11:17
Node Evironment File Watcher Limit Increasing
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
@AyemunHossain
AyemunHossain / npmikill.txt
Created March 5, 2023 05:15
`npm install` ends with "Killed"
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
@AyemunHossain
AyemunHossain / fiebaseIndexing.js
Created April 25, 2023 06:16
Firebase Realtime Database indexing for query optimization
Data Format:
_DB
___Collction
______Sub Collection
__________Data
TestChatHistory --------------------------------------->(Main DB)
>268 ------------------------------------------------->(Collection)
>>2691680604235655 ----------------------------------->(Sub-collection)
@AyemunHossain
AyemunHossain / app.js
Created April 30, 2023 10:18
MongoDB Nested Population, #mongoDB #populate
Airlines.findById(id)
.populate({
path: 'flights',
populate:[
{
path: 'planeType',
model: 'Plane'
},
{
path: 'destination',
@AyemunHossain
AyemunHossain / awsLambdaToFirebase.js
Created May 3, 2023 07:36
Access Firebase From AWS Lambda Function
'use strict';
var firebase = require("firebase");
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false; //<---Important
var config = {
apiKey: "<<apikey>>",
authDomain: "<<app_id>>.firebaseapp.com",