Skip to content

Instantly share code, notes, and snippets.

View mailtodanish's full-sized avatar
:octocat:
Working From Home

Mohd Ahshan Danish mailtodanish

:octocat:
Working From Home
View GitHub Profile
@widoyo
widoyo / kas.py
Created October 16, 2012 07:42
Generating PDF using Flask & ReportLab
from flask import make_response
from reportlab.pdfgen import canvas
# ...
@app.route('/pdf')
def pdf():
import cStringIO
output = cStringIO.StringIO()
# https://code.djangoproject.com/ticket/17209
import urlparse
from django.conf import settings
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect, QueryDict
from django.utils.decorators import method_decorator
from django.utils.http import base36_to_int
from django.utils.translation import ugettext as _
from django.views import generic
@hakib
hakib / custom_django_checks.py
Last active July 1, 2024 09:20
Custom django checks using Django check framework, inspect and ast.
"""
Custom django checks.
H001: Field has no verbose name.
H002: Verbose name should use gettext.
H003: Words in verbose name must be all upper case or all lower case.
H004: Help text should use gettext.
H005: Model must define class Meta.
H006: Model has no verbose name.
H007: Model has no verbose name plural.
@akshar-raaj
akshar-raaj / serializers.py
Created August 7, 2019 17:13
UserSerializer with overridden create
class UserSerializer(serializers.ModelSerializer):
def validate_password(self, value):
if value.isalnum():
raise serializers.ValidationError('password must have atleast one special character.')
return value
def validate(self, data):
if data['first_name'] == data['last_name']:
raise serializers.ValidationError("first_name and last_name shouldn't be same.")
# -*- coding: utf-8 -*-
from flask import (
Flask,
request,
render_template,
jsonify,
url_for
)
from make_celery import make_celery
import time
@velotiotech
velotiotech / gist:c508894ad72932e174c83d64e866ab30
Last active September 5, 2021 05:10
multiprocessing in python
from multiprocessing import Process
def print_func(continent='Asia'):
print('The name of continent is : ', continent)
if __name__ == "__main__": # confirms that the code is under main function
names = ['America', 'Europe', 'Africa']
procs = []
proc = Process(target=print_func) # instantiating without any argument
import threading
def print_cube(num):
"""
function to print cube of given num
"""
print("Cube: {}".format(num * num * num))
def print_square(num):
"""
import tempfile
from django.contrib import admin
from django.core import serializers
from django.http import HttpResponse
from example_app.models import *
@admin.action(description="Export Model")
from django.db import models
class PersonManager(models.Manager):
def get_by_natural_key(self, first_name, last_name):
return self.get(first_name=first_name, last_name=last_name)
class Person(models.Model):
first_name = models.CharField(max_length=100)