Add the following snippet at the bottom of ~/.zshrc
file.
RPROMPT='[%D{%L:%M:%S}] '$RPROMPT
# Add this code in any Django app's admin.py | |
# Works for all Task Statuses; you can filter them in line 12. | |
import ast | |
import importlib | |
import json | |
from django.contrib import admin | |
from django.contrib import messages | |
from django.utils.safestring import mark_safe |
from collections import OrderedDict | |
from rest_framework.fields import SkipField | |
from rest_framework.relations import PKOnlyObject | |
class RestrictedFieldsSerializerMixin(object): | |
""" | |
API Serializer mixin which provides support for restricting serialized data to only a subset of fields. |
import pyrsistent | |
import immutables | |
import time | |
I = 1_000_000 | |
KEY = '5' | |
for N in [5, 10, 20, 30, 100, 200, 300, 400, 500, 1000]: | |
print('=============') |
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`. |
'use strict'; | |
const co = require('co'); | |
const EventEmitter = require('events'); | |
const Promise = require('bluebird'); | |
const AWS = require('aws-sdk'); | |
const ssm = Promise.promisifyAll(new AWS.SSM()); | |
const DEFAULT_EXPIRY = 3 * 60 * 1000; // default expiry is 3 mins |
The following instructions describe a set of processes allowing you to run Django database migrations against a production database without having to bring the web service down.
Note that in the below instructions, migrations are all run manually at explicit points, and are not an automatic part of the deployment process.
import time | |
import redis | |
def get_redis_connection(): | |
return redis.connect() | |
class TaskDebouncer(object): | |
""" A simple Celery task debouncer. |
Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv
instead. If you are looking for the previous version of this document, see the revision history.
$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10
$ pyenv install 2.6.9
# delete local tag '12345' | |
git tag -d 12345 | |
# delete remote tag '12345' (eg, GitHub version too) | |
git push origin :refs/tags/12345 | |
# alternative approach | |
git push --delete origin tagName | |
git tag -d tagName |