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
LOGGING = { | |
# ... (other logging configurations) | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'class': 'django.utils.log.AdminEmailHandler', | |
'include_html': True, | |
}, | |
}, | |
# ... (loggers, filters, and formatters) |
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.db import models | |
class TimeStampedModel(models.Model): | |
created_at = models.DateTimeField(auto_now_add=True) | |
updated_at = models.DateTimeField(auto_now=True) | |
class Meta: | |
abstract = True |
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 compress_image(image): | |
# Define your compression settings here | |
# For example, you can resize the image and adjust the quality | |
max_size = (800, 800) | |
quality = 80 | |
# Resize the image while preserving aspect ratio | |
image.thumbnail(max_size, Image.ANTIALIAS) | |
# Convert the image to RGB mode (necessary for saving as JPEG) |
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.db import models | |
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
from PIL import Image | |
from io import BytesIO | |
from django.core.files.uploadedfile import InMemoryUploadedFile | |
class CompressedImage(models.Model): | |
original_image = models.ImageField(upload_to='images/') | |
compressed_image = models.ImageField(upload_to='images/compressed/', blank=True) |
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 query_debugger(func): | |
@functools.wraps(func) | |
def inner_func(*args, **kwargs): | |
reset_queries() | |
start_queries = len(connection.queries) | |
start = time.perf_counter() |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
# References | |
# https://towardsdatascience.com/animations-with-matplotlib-d96375c5442c | |
# https://riptutorial.com/matplotlib/example/23558/basic-animation-with-funcanimation | |
def func(t, line): |
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
import readline | |
import requests | |
class MyCompleter(object): # Custom completer | |
def __init__(self, options): | |
self.options = sorted(options) |
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
# make sure you have opencv installed, "pip install opencv-python" | |
# make sure your video is .avi or .mp4 encoded, else change the encoder accordingly | |
import cv2 | |
output_file = "output.mp4" | |
cap = cv2.VideoCapture("Video File Location") | |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
fps = cap.get(cv2.CAP_PROP_FPS) | |
check , vid = cap.read() | |
counter = 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
#!/bin/bash | |
# Simple password generator | |
echo "This is a simple password generator" | |
echo "Please enter the length of the password" | |
read PASS_LENGTH | |
echo "Please enter number of passwords to be generated" | |
read NO_OF_PASS | |
echo "Enter website for which password is to be generated" | |
read COMPANY |
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 random import * | |
l=["Head","Tail"] | |
shuffle(l) | |
print(l[0]) |
NewerOlder