Skip to content

Instantly share code, notes, and snippets.

DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
...
'OPTIONS': {'charset': 'utf8mb4'},
}
}
from itertools import chain
from operator import attrgetter
# ascending oreder
result_list = sorted(
chain(queryset1, queryset2),
key=attrgetter('date_created'))
# descending order
# install via MacPorts
sudo port install openssl
sudo env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
# install via Homebrew
brew install openssl
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography
find . \( -name '*.py' -o -name '*.coffee' -o -name '*.scss' \) | xargs wc -l
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
# enforce NO www
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
from django.forms import ModelForm
from django.forms import ValidationError
from django.forms import FileField
# Django 1.6 Version
class BaseModelForm(ModelForm):
# strip leading or trailing whitespace
def _clean_fields(self):
# round robin load balance pool
# servers can be local or remote
upstream lbpool {
ip_hash;
server 10.10.10.1:8000 max_fails=3 fail_timeout=120;
server 10.10.10.2:8000 max_fails=3 fail_timeout=120;
# additional servers
}
# http server
# the following assumes a typical MacPorts install to /opt/local
# create a directory to hold local ports
sudo mkdir /opt/custom
# edit /opt/local/etc/macports/sources.conf and add the following line before rsync://rsync.macports.org/release/tarballs/ports.tar
# file:///opt/custom
# create the directories to hold the port file
sudo mkdir -p /opt/custom/databases/mysql56/files/
upstream php-sendy-example-com {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name sendy.example.com;
root /home/webapps/sendy.example.com/;
access_log /var/log/nginx/sendy.example.com.access.log main;
error_log /var/log/nginx/sendy.example.com.error.log;
server {
listen 80;
server_name jira.example.com;
access_log /var/log/nginx/jira.example.com.access.log main;
error_log /var/log/nginx/jira.example.com.error.log;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;