Skip to content

Instantly share code, notes, and snippets.

View Allwin12's full-sized avatar

Allwin Raju Allwin12

  • Genesys
  • chennai
View GitHub Profile
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))
@Allwin12
Allwin12 / views.py
Last active November 23, 2020 05:08
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, ]
#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;
}
@Allwin12
Allwin12 / sample.c
Last active November 19, 2020 07:00
#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]);
}
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:
from html import unescape
escaped_string = '''
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
from html import escape
html_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
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')
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})
class SampleView(APIView):
def get(self, request):
agent = request.META['HTTP_USER_AGENT']
print(agent)
return Response({'agent': agent})