Used nodes:
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l GNU/Linux
Linux localhost.localdomain 4.14.5-200.fc26.x86_64 #1 SMP Mon Dec 11 16:29:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from urllib.parse import urlparse | |
import codecs | |
from django.conf import settings | |
from django.utils.html_parser import HTMLParser | |
__author__ = 'Paweł Krawczyk' |
# sample implementation for http://stackoverflow.com/questions/37851053/django-query-group-by-month#new-answer | |
from __future__ import unicode_literals | |
from django.db import models | |
from django.db.models import Func, F, Sum | |
from django.db.transaction import atomic, rollback | |
from django.utils.timezone import now | |
class Invoice(models.Model): |
This gist assumes you are migrating an existing site for www.example.com — ideally WordPress — to a new server — ideally Ubuntu Server 16.04 LTS — and wish to enable HTTP/2 (backwards compatibile with HTTP/1.1) with always-on HTTPS, caching, compression, and more. Although these instructions are geared towards WordPress, they should be trivially extensible to other PHP frameworks, other FastCGI backends, and even non-FastCGI backends (using proxy
in lieu of fastcgi
in the terminal Caddyfile stanza).
Quickstart: Use your own naked and canonical domain names instead of example.com and www.example.com and customize the Caddyfile and VCL provided in this gist to your preferences!
These instructions target Varnish Cache 4.1, PHP-FPM 7.0, and Caddy 0.10. (I'm using MariaDB 10.1 as well, but that's not relevant to this guide.)
import functools | |
from channels.handler import AsgiRequest | |
from rest_framework.exceptions import AuthenticationFailed | |
from rest_framework.settings import api_settings | |
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES] | |
from django.db import ProgrammingError, models | |
from django.db.models.constants import LOOKUP_SEP | |
from django.db.models.query import normalize_prefetch_lookups | |
from rest_framework import serializers | |
from rest_framework.utils import model_meta | |
class OptimizeModelViewSetMetaclass(type): | |
""" | |
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related` | |
if the `serializer_class` is an instance of `serializers.ModelSerializer`. |
package main | |
import ( | |
"crypto/sha256" | |
"encoding/base64" | |
"fmt" | |
"golang.org/x/crypto/pbkdf2" | |
"strconv" | |
"strings" | |
) |
<template> | |
<v-avatar v-if="user !== null" | |
:size="size" | |
:style="{'background-color': backgroundColor}"> | |
<strong class="initials" | |
:style="{'color': fontColor, | |
'font-size': fontSize}"> | |
{{ (user.first_name[0] + user.last_name[0]) || '?' }} | |
</strong> |
from django.db import ProgrammingError, models | |
from django.db.models.constants import LOOKUP_SEP | |
from django.db.models.query import normalize_prefetch_lookups | |
from rest_framework import serializers | |
from rest_framework.utils import model_meta | |
class OptimizeRelatedModelViewSetMetaclass(type): | |
""" | |
This metaclass optimizes the queryset using `prefetch_related` and `select_related`. |