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
""" | |
Allowing CORS for some of your url in Django can be confusing sometime. | |
This Decorator makes things easy | |
""" | |
def allow_cors(function): | |
""" | |
A decorator to allow CORS for urls by setting the cors headers to the response. | |
""" | |
def enabled_cors(request, *args, **kwargs): |
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
#!/bin/bash | |
NAME='project' | |
PROJECT_DIR='/home/project/project/repo' | |
USER='projectuser' | |
GROUP='projectuser' | |
NUMWORKER=3 #choose based on number or cores | |
DJANGO_WSGI_MODULE=project.wsgi | |
VENV_SOURCE=/home/project/project/venv/bin/activate #path to activte the virtualenv | |
SOCKFILE=/home/project/project/sockets/project.sock #sockets are fast- reverse proxy server will send requests to this |
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 XcodeAutoSchema(SwaggerAutoSchema): | |
def __init__(self, view, path, method, components, request, overrides): | |
super(XcodeAutoSchema, self).__init__(view, | |
path, | |
method, | |
components, | |
request, | |
overrides) | |
def get_operation(self, operation_keys): |
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 MagicApiView(APIView): | |
@swagger_auto_schema( | |
auto_schema= CustomSwaggerAutoSchema, | |
query_serializer=RequestBodySerializer, | |
responses={ | |
'200': OKResponseSerializer, | |
'400': "Bad Request" | |
}, | |
security=[], |
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 dns import resolver | |
try: | |
mx_record = resolver.query('gmail.com', 'MX') | |
exchanges = [exchange.to_text().split() for exchange in mx_record] | |
except (resolver.NoAnswer, resolver.NXDOMAIN, resolver.NoNameservers): | |
exchanges = [] |
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 smtplib import SMTP | |
address_to_test = "arjunsinghy96@gmail.com" | |
try: | |
with SMTP('gmail-smtp-in.l.google.com') as smtp: | |
host_exists = True | |
smtp.helo() # send the HELO command | |
smtp.mail('admin@emailgardener.com') # send the MAIL command | |
resp = smtp.rcpt(address_to_test) |
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
import socket | |
import socks # PySocks | |
from smtplib import SMTP | |
class SocksSMTP(SMTP): | |
def __init__(self, | |
host='', | |
port=0, |
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
curl -X {{method}} \ | |
{% for header, value in headers.items %}--header "{{header}}:{{value}}" \ | |
{% endfor %}'{{request_url}}{% if query %}?{{query_format | safe}} {% endif %}' \{% for key, value in payload.items %} | |
-d {{key}}={{value}} \{% endfor %} |