A curated list of awesome Go storage projects and libraries. Inspired by awesome-go.
Please take a quick gander at the contribution guidelines first. Thanks to all contributors; you rock!
from rest_framework.generics import get_object_or_404 | |
class CaseInsensitiveLookupMixin(object): | |
""" | |
Apply this mixin to any view or viewset to get kwargs with lowercase | |
values. Based on a `lookup_field` attribute. | |
""" | |
def get_object(self): | |
queryset = self.get_queryset() # Get the base queryset |
from PIL import Image | |
from io import BytesIO | |
def compress_image(original_file, max_size, scale): | |
""" | |
It should compress the size of the given file with the particular `scale` | |
until `max_size` limit is achieved. | |
""" | |
assert(0.0 < scale < 1.0) |
func levenshteinDistance(s string, t string) int { | |
s = strings.ToLower(s) | |
t = strings.ToLower(t) | |
if s == t { | |
return 0 | |
} | |
if len(s) == 0 { | |
return len(t) | |
} | |
if len(t) == 0 { |
A curated list of awesome Go storage projects and libraries. Inspired by awesome-go.
Please take a quick gander at the contribution guidelines first. Thanks to all contributors; you rock!
# Run the following command: | |
sudo apt-get install python-setuptools python-dev build-essential | |
# Install pip: | |
sudo apt-get install python-pip | |
# Install `virtualenv`: | |
pip install virtualenv |
""" | |
List of all disposable email service domains. | |
Possible usage: | |
- To prevent email address from temporary email services while registering users. | |
""" | |
DESPOSABLE_EMAIL_DOMAINS = [ | |
'0-mail.com', | |
'027168.com', | |
'0815.ru', |
def generate_client_key(): | |
""" | |
Generate a suitable client key | |
""" | |
api_key = hashlib.sha1(os.urandom(32)).hexdigest() | |
return api_key | |
def generate_client_secret(): | |
""" | |
Generate a suitable client secret |
import random, string | |
def random_generator(size=6, chars=string.ascii_uppercase + string.digits): | |
""" | |
Usage: | |
>>> random_generator().lower() | |
'w9gz1z' | |
>>> random_generator(3, "6793YUIO") | |
'6U7' | |
""" |
from random import choice | |
from string import ascii_lowercase, digits | |
from django.contrib.auth.models import User | |
def generate_random_username(length=16, chars=ascii_lowercase+digits, split=4, delimiter='-'): | |
username = ''.join([choice(chars) for i in xrange(length)]) | |
if split: | |
username = delimiter.join([username[start:start+split] for start in range(0, len(username), split)]) |
""" | |
To run the script | |
s3_meta.py --access-key=AWS_ACCESS_KEY_ID | |
--secret-key=AWS_SECRET_ACCESS_KEY | |
--bucket-name=BUCKET_NAME | |
-d=METADATA | |
e.g. | |
python s3_meta.py --access_key=AKIAIOSFODNN7EXAMPLE --secret-key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY --bucket-name=test-bucket -d '{"Cache-Control": "max-age=3600"}' | |
""" |