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
def luhn_checksum(card_number): | |
def digits_of(n): | |
return [int(d) for d in str(n)] | |
digits = digits_of(card_number) | |
odd_digits = digits[-1::-2] | |
even_digits = digits[-2::-2] | |
checksum = 0 | |
checksum += sum(odd_digits) | |
for d in even_digits: | |
checksum += sum(digits_of(d*2)) |
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.response import Response | |
from rest_framework.views import APIView | |
from rest_framework_xml.renderers import XMLRenderer | |
from student.models import School | |
from student.serializers import SchoolListSerializer | |
class SchoolView(APIView): | |
renderer_classes = [XMLRenderer, ] |
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
#include<stdio.h> | |
int main() | |
{ | |
char words[4][5] = {"word", "bird", "lost", "grid"}; | |
for(int i=0; i<4; i++) | |
{ | |
puts(words[i]); | |
} | |
return 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
#include<stdio.h> | |
int main() | |
{ | |
char words[4][5] = {"word", "bird", "lost", "grid"}; | |
for(int i=0; i<4; i++) | |
{ | |
for(int j=0;j<4;j++) | |
{ | |
printf("%c", words[i][j]); | |
} |
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.http import HttpResponse | |
from django.utils.deprecation import MiddlewareMixin | |
class ProcessRequestMiddleware(MiddlewareMixin): | |
def process_view(self, request, view_func, *view_args, **view_kwargs): | |
user = request.user | |
if user.is_authenticated: | |
return HttpResponse(status=200) | |
else: |
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 html import unescape | |
escaped_string = ''' | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> |
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 html import escape | |
html_string = ''' | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> |
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 SampleView(APIView): | |
def get(self, request): | |
user_agent = request.user_agent | |
browser = user_agent.browser.family | |
browser_version = user_agent.browser.version_string | |
os = user_agent.os.family | |
os_version = user_agent.os.version_string | |
is_pc = user_agent.is_pc | |
is_mobile = user_agent.is_mobile | |
return Response('success') |
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 SampleView(APIView): | |
def get(self, request): | |
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
if x_forwarded_for: | |
ip = x_forwarded_for | |
else: | |
ip = request.META.get('REMOTE_ADDR') | |
return Response({'ip_address': ip}) |
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 SampleView(APIView): | |
def get(self, request): | |
agent = request.META['HTTP_USER_AGENT'] | |
print(agent) | |
return Response({'agent': agent}) |