This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
========================= | |
Join promotion in the ORM | |
========================= | |
[NOTE: We need better terms than promote and demote for changing the join | |
type. These terms are extremely easy to mix up. Maybe the ORM methods could | |
be to_inner_joins and to_louter_joins instead of promote_joins and demote_joins? | |
I tried to clean up the mis-usages of promotion/demotion but there could still | |
be some cases where these are mixed up] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from django.conf import settings | |
from django.db import transaction | |
def durable(func): | |
""" | |
Decorator to ensure that a function is not being called from an atomic block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
from django.db import transaction | |
from django.db.models import Count, Func, IntegerField, OuterRef, Subquery | |
from django.contrib.postgres.aggregates import ArrayAgg | |
from django.contrib.postgres.fields import ArrayField | |
from sql_util.utils import SubqueryAggregate | |
django.setup() | |
from pizza.models import Topping, Pizza |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import queue | |
import threading | |
import time | |
import random | |
NUM_WORKERS = 20 | |
class Worker(threading.Thread): | |
"""A worker thread.""" | |
def __init__(self, input, output=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import argparse | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description=""" | |
I never freaking remember argparse syntax and the docs are so all over the place | |
that I need this for an example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create type numeric_quartiles_plus as ( | |
min float, | |
q05 float, | |
q10 float, | |
q25 float, | |
q50 float, | |
q75 float, | |
q90 float, | |
q95 float, | |
max float, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PeekIter: | |
""" Create an iterator which allows you to peek() at the | |
next item to be yielded. It also stores the exception | |
and re-raises it on the next next() call. | |
""" | |
def __init__(self, iterable): | |
self._exn = None | |
self._it = iter(iterable) | |
self._peek = next(self._it) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Some things taken from here | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# Set the colours you can use | |
black='\033[0;30m' | |
white='\033[0;37m' | |
red='\033[0;31m' | |
green='\033[0;32m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shell -$SHELL | |
startup_message off | |
defscrollback 8192 | |
bind j focus down | |
bind k focus up | |
bind t focus top | |
bind b focus bottom | |
bind W windowlist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# gunicorn_sr Startup script for gunicorn for sr | |
# | |
# chkconfig: - 86 14 | |
# processname: gunicorn | |
# pidfile: | |
# description: Python application server | |
# | |
### BEGIN INIT INFO |
NewerOlder