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 tempfile | |
class TempFileManager(): | |
def __init__(self): | |
self.files = [] | |
def __enter__(self): | |
return self |
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 | |
# Environment variables: | |
# REMOTE_USER, REMOTE_HOST — obviously | |
# Read more about deployment over SSH: | |
# https://confluence.atlassian.com/bitbucket/access-remote-hosts-via-ssh-847452940.html | |
set -e # automatic exit on error |
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 rest_framework.authentication import BaseAuthentication | |
class SessionAuthenticationWithoutCsrf(BaseAuthentication): | |
def authenticate(self, request): | |
request = request._request | |
user = getattr(request, 'user', None) | |
if not user or not user.is_active: | |
return None |
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 time | |
from django.core.cache import cache as default_cache | |
from rest_framework.exceptions import Throttled | |
class RateLimitThrottle: | |
""" | |
The alternative implementation of Rest Framework's throttling feature, that is more driven | |
but is incompatible with a throttling_classes attribute. The example below gives 10 login |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="2.0" | |
xmlns:html="http://www.w3.org/TR/REC-html40" | |
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> | |
<xsl:template match="/"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>XML Sitemap</title> |
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 rest_framework import routers | |
class RestRouter(routers.SimpleRouter): | |
routes = [ | |
# list | |
routers.Route( | |
url=r'^{prefix}/?$', | |
mapping={ | |
'get': 'list', |
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 os | |
from django.conf import settings | |
from django.http import HttpRequest | |
import flex | |
from flex.core import validate_api_call | |
from flex.exceptions import ValidationError | |
APISPEC_PATH = os.path.join(settings.BASE_DIR, 'apispec', 'swagger.yml') | |
flex_schema = flex.load(APISPEC_PATH) |
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 django_filters import rest_framework as drf_filters | |
import copy | |
class NestedFilter: | |
def __init__(self, filterset, name, prefix=''): | |
self.filterset = filterset | |
self.name = name | |
self.prefix = prefix |
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 string | |
def normalize_phone(phone): | |
if not phone: | |
return None | |
phone = ''.join(n for n in phone if n in set(string.digits + '+')) | |
phone_len = len(phone) |
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
CUR_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |