Skip to content

Instantly share code, notes, and snippets.

@umarmughal824
umarmughal824 / pytest_mute_signals_fixture.py
Created March 22, 2023 17:02 — forked from qcoumes/pytest_mute_signals_fixture.py
This fixture disable django's signals in every test. You can indiviually enable them for a function using '@pytest.mark.enable_signals' decorator or for a file using 'pytestmark = pytest.mark.enable_signals'
@pytest.fixture(autouse=True)
def mute_signals(request):
# Skip applying, if marked with `enabled_signals`
if 'enable_signals' in request.keywords:
return
signals = [pre_save, post_save, pre_delete, post_delete, m2m_changed]
restore = {}
for signal in signals:
restore[signal] = signal.receivers
@umarmughal824
umarmughal824 / mako.py
Created March 24, 2021 20:10 — forked from iamjazzar/mako.py
Mako Templates for Django Projects
"""
Mako Template Backend
This is the implementation of Mako template backend in order to use
it as a Django Template Backend alternative in this project template
system. This backend is a class that inherits
django.template.backends.base.BaseEngine. It must implement
get_template() and optionally from_string().
"""
@umarmughal824
umarmughal824 / put_as_create.py
Created March 22, 2021 21:03 — forked from lovelydinosaur/put_as_create.py
PUT-as-create mixin class for Django REST framework.
class AllowPUTAsCreateMixin(object):
"""
The following mixin class may be used in order to support PUT-as-create
behavior for incoming requests.
"""
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = self.get_object_or_none()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
@umarmughal824
umarmughal824 / token_auth.py
Created March 17, 2021 18:39 — forked from rluts/token_auth.py
Token authorization middleware for Django Channels 2
from channels.auth import AuthMiddlewareStack
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import AnonymousUser
from django.db import close_old_connections
class TokenAuthMiddleware:
"""
Token authorization middleware for Django Channels 2
"""
You can use either GenericViewSet or ModelViewSet(as its also inherited from GenericViewSet).
Using GenericViewSet or ModelViewSet
# or class PolicyViewSet(viewsets.GenericViewSet):
class PolicyViewSet(viewsets.ModelViewSet):
def list(self, request):
queryset = Policy.objects.all()
page = self.paginate_queryset(queryset)
@umarmughal824
umarmughal824 / domain-to-aws-ec2-instance.md
Created December 7, 2020 06:12 — forked from keithweaver/domain-to-aws-ec2-instance.md
Point Domain to Amazon Web Services (AWS) EC2 Instance

Point Domain to Amazon Web Services (AWS) EC2 Instance

  1. Open the Amazon Route 53 console at https://console.aws.amazon.com/route53/.
  2. If you are new to Amazon Route 53, you see a welcome page; choose Get Started Now for DNS Management. Otherwise, choose Hosted Zones in the navigation pane.
  3. Choose Create Hosted Zone.
  4. For Domain Name, type your domain name.
  5. Choose Create.
  6. Click the Hosted Zone, edit record set.
  7. In the value, add ec2-54-152-134-146.compute-1.amazonaws.com.
  8. Change your DNS file to point to the IPv4 address (This would be in something like GoDaddy).
function killemall(){
sudo ps aux | grep -e $1 | grep -v grep | awk '{print $2}' | xargs kill -9
}
export DJANGO_PORT=8080
alias run='python manage.py runserver'
alias rr='killemall manage.py;reset;run $DJANGO_PORT'
@umarmughal824
umarmughal824 / docker-compose.yml
Created November 12, 2020 20:06 — forked from shavo007/docker-compose.yml
Docker compose (mysql, elasticsearch, kibana) with healthchecks
version: '2.1'
services:
mysql:
container_name: mysql
image: mysql:5.7
ports:
- "13306:3306"
environment:
- MYSQL_ROOT_PASSWORD=Welcome123
healthcheck:
@umarmughal824
umarmughal824 / docker-compose.yml
Created November 12, 2020 20:06 — forked from shavo007/docker-compose.yml
Docker compose (mysql, elasticsearch, kibana) with healthchecks
version: '2.1'
services:
mysql:
container_name: mysql
image: mysql:5.7
ports:
- "13306:3306"
environment:
- MYSQL_ROOT_PASSWORD=Welcome123
healthcheck:
/* global SETTINGS:false zE:false _:false */
__webpack_public_path__ = `${SETTINGS.public_path}` // eslint-disable-line no-undef, camelcase
import R from "ramda"
import _ from "lodash"
import { wait } from "../util/util"
// Start of odl Zendesk Widget script
/* eslint-disable no-sequences, prefer-const */
/*<![CDATA[*/