Skip to content

Instantly share code, notes, and snippets.

View collinanderson's full-sized avatar

Collin Anderson collinanderson

  • South Bend, Indiana
View GitHub Profile
@collinanderson
collinanderson / py2sorting.py
Created February 26, 2015 03:43
python 2 sorting
def default_3way_compare(v, w): # Yes, this is how Python 2 sorted things :)
if type(v) is type(w):
return -1 if id(v) < id(w) else (1 if id(v) > id(w) else 0)
if v is None:
return -1
if w is None:
return 1
if isinstance(v, (int, float)):
vname = ''
else:
September 2008 1.0 2.3, 2.4, 2.5, 2.6
July 2009 1.1 2.3, 2.4, 2.5, 2.6
May 2010 1.2 2.4, 2.5, 2.6, 2.7
March 2011 1.3 2.4, 2.5, 2.6, 2.7
March 2012 1.4 2.5, 2.6, 2.7
Feburary 2013 1.5 2.6, 2.7 and 3.2, 3.3 (experimental)
November 2013 1.6 2.6, 2.7 and 3.2, 3.3
September 2014 1.7 2.7 and 3.2, 3.3, 3.4
April 2015? 1.8 2.7 and 3.2, 3.3, 3.4
November 2015? 1.9 2.7 and 3.3, 3.4, 3.5
from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend as SmtpEmailBackend
class CustomEmailBackend(SmtpEmailBackend):
def _send(self, email_message):
if not email_message.recipients():
return False
message = email_message.message()
try:
# in my settings_local.py
import datetime
import logging
from django.http import HttpRequest
class TimingHandler(logging.Handler):
def __init__(self, *args, **kwargs):
@collinanderson
collinanderson / py2sort.py
Created January 15, 2019 02:44
Python 2 sorting in python3
def default_3way_compare(v, w): # Yes, this is how Python 2 sorted things :)
tv, tw = type(v), type(w)
if tv is tw:
return -1 if id(v) < id(w) else (1 if id(v) > id(w) else 0)
if v is None:
return -1
if w is None:
return 1
if isinstance(v, (int, float)):
vname = ''