Skip to content

Instantly share code, notes, and snippets.

View arjunsinghy96's full-sized avatar

Arjun Singh Yadav arjunsinghy96

View GitHub Profile
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 %}
import socket
import socks # PySocks
from smtplib import SMTP
class SocksSMTP(SMTP):
def __init__(self,
host='',
port=0,
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)
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 = []
class MagicApiView(APIView):
@swagger_auto_schema(
auto_schema= CustomSwaggerAutoSchema,
query_serializer=RequestBodySerializer,
responses={
'200': OKResponseSerializer,
'400': "Bad Request"
},
security=[],
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):
@arjunsinghy96
arjunsinghy96 / deploy.sh
Last active March 28, 2018 10:47
A template bash script to run under supervisord to deploy django server.
#!/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
@arjunsinghy96
arjunsinghy96 / django_cors.py
Created February 22, 2018 06:16
Allowing CORS for only specific urls in Django apps can be confusing. Sure there are tools present. But for simple cases this little decorator is all we need.
"""
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):