Skip to content

Instantly share code, notes, and snippets.

Avatar
😆
I may be slow to respond.

Allwin Raju Allwin12

😆
I may be slow to respond.
View GitHub Profile
View admin.py
from datetime import timedelta
from django.contrib import admin
from myapp.models import CronTask
class CronTaskAdmin(admin.ModelAdmin):
list_display = ['name', 'get_ist']
list_filter = ['name']
View sendgrid_email.py
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email="verified_email@gmail.com",
to_emails="receiver@gmail.com",
subject="test",
html_content="<p>hi</hi>"
View luhn.py
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))
View views.py
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, ]
View puts_sample.c
#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;
}
View sample.c
#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]);
}
View middleware.py
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:
View unescape_html.py
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;
View html_escape.py
from html import escape
html_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
View views.py
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')