This file contains hidden or 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
# Source: https://stackoverflow.com/a/7936523 | |
from urllib.parse import urlparse, parse_qs | |
def extract_video_id(value): | |
""" | |
Examples: | |
- http://youtu.be/SA2iWivDJiE | |
- http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu | |
- http://www.youtube.com/embed/SA2iWivDJiE |
This file contains hidden or 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 requests | |
from django.conf import settings | |
from rest_framework import serializers | |
from .request import get_client_ip | |
def verify_recaptcha(recaptcha_response, *, remote_ip=None, | |
secret_key=settings.RECAPTCHA_SECRET_KEY): | |
if settings.RECAPTCHA_WILD_CODE and \ |
This file contains hidden or 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
class AlbumAdminForm(forms.ModelForm): | |
photos_batch = forms.FileField( | |
widget=forms.FileInput(attrs={ | |
'accept': 'image/png, image/jpeg', | |
'multiple': True, | |
}), | |
required=False, | |
label='Photos', | |
help_text='Choose multiple files.', | |
) |
This file contains hidden or 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 unittest import mock | |
from django.test import TestCase | |
from django.db import transaction | |
class TransactionCommitHooksMixin: | |
""" | |
Fake transaction commit to run delayed on_commit functions | |
https://medium.com/gitux/speed-up-django-transaction-hooks-tests-6de4a558ef96 | |
""" |
This file contains hidden or 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
Привет. | |
Я думаю, вы не будете счастливы, потому | |
что у меня для вас очень плохие новости. | |
Всего несколько месяцев назад (02/03/2019) я | |
взломал вашу операционную систему и | |
полностью контролировал ваше устройство. | |
Я имплантировал в ваше устройство | |
небольшое приложение, которое отправляет |
This file contains hidden or 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 chunked(data, n): | |
for x in range(0, len(data), n): | |
yield data[x:x+n] | |
if __name__ == '__main__': | |
assert list(chunked([1, 2, 3, 4, 5], 2)) == [[1, 2], [3, 4], [5]] |
This file contains hidden or 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 | |
set -e | |
VSCALE_TOKEN="" | |
SLACK_WEBHOOK_URL="" | |
MIN_BALANCE=20000 | |
log() { | |
ts=$(date '+%Y-%m-%d %H:%M:%S') | |
echo "$ts INFO $1" |
This file contains hidden or 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 | |
set -e | |
DB_NAME=$1 | |
MAX_BACKUPS=${MAX_BACKUPS:-30} | |
DB_USER=${DB_USER:-"postgres"} | |
DB_HOST=${DB_HOST:-""} | |
PGPASSWORD=$DB_PASSWORD | |
BACKUP_DIR=${BACKUP_DIR:-"backups"} | |
BACKUP_FILE=$BACKUP_DIR/$DB_NAME'_'$(date +%F_%H%M%S).pgdump |
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Usage: | |
IMAGE=039718039073.dkr.ecr.us-east-1.amazonaws.com/my-service-api:$BITBUCKET_COMMIT | |
ecs_deploy.py update_taskdef my-service-api --image=$IMAGE | |
ecs_deploy.py update_service my-service-api --taskdef=my-service-api | |
ecs_deploy.py run_task my-service-api-migrate-db | |
""" |
This file contains hidden or 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 unique_slug(queryset, source, pk, slug_field='slug'): | |
slug_base = slugify(source) | |
slug = slug_base | |
index = 1 | |
if isinstance(queryset, ModelBase): | |
queryset = queryset.objects.all() | |
while True: | |
if not queryset.filter(**{slug_field: slug}).exclude(pk=pk).exists(): | |
return slug | |
slug = f'{slug_base}-{index}' |