Skip to content

Instantly share code, notes, and snippets.

👓
Doing Android stuff

Mitch Tabian mitchtabian

👓
Doing Android stuff
Block or report user

Report or block mitchtabian

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View logd.kt
android.util.Log.d(TAG, "$METHOD_NAME$: $content$")
View example.html
<div class="embed-responsive embed-responsive-16by9">
<iframe id="player" class="embed-responsive-item" src="https://player.vimeo.com/video/371393039?enablejsapi=1" allowfullscreen allow=autoplay></iframe>
</div>
View serializers.py
from rest_framework import serializers
from account.models import Account
class RegistrationSerializer(serializers.ModelSerializer):
password2 = serializers.CharField(style={'input_type': 'password'}, write_only=True)
class Meta:
View forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate
from account.models import Account
class RegistrationForm(UserCreationForm):
email = forms.EmailField(max_length=254, help_text='Required. Add a valid email address.')
View views.py
from rest_framework import status
from rest_framework.response import Response
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from rest_framework.generics import UpdateAPIView
from django.contrib.auth import authenticate
from rest_framework.authentication import TokenAuthentication
from rest_framework.decorators import api_view, authentication_classes, permission_classes
View backends.py
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
class CaseInsensitiveModelBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
UserModel = get_user_model()
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
try:
View BlogPostUpdateSerializer.py
class BlogPostUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = BlogPost
fields = ['title', 'body', 'image']
def validate(self, blog_post):
try:
title = blog_post['title']
if len(title) < MIN_TITLE_LENGTH:
View BlogPostCreateSerializer.py
import os
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.storage import FileSystemStorage
IMAGE_SIZE_MAX_BYTES = 1024 * 1024 * 2 # 2MB
MIN_TITLE_LENGTH = 5
MIN_BODY_LENGTH = 50
from blog.utils import is_image_aspect_ratio_valid, is_image_size_valid
View utils.py
import cv2
import os
def is_image_aspect_ratio_valid(img_url):
img = cv2.imread(img_url)
dimensions = tuple(img.shape[1::-1]) # gives: (width, height)
print("dimensions: " + str(dimensions))
aspect_ratio = dimensions[0] / dimensions[1] # divide w / h
print("aspect_ratio: " + str(aspect_ratio))
if aspect_ratio < 1:
View serializers.py
class ChangePasswordSerializer(serializers.Serializer):
old_password = serializers.CharField(required=True)
new_password = serializers.CharField(required=True)
confirm_new_password = serializers.CharField(required=True)
You can’t perform that action at this time.