Skip to content

Instantly share code, notes, and snippets.

View JohnSpeno's full-sized avatar
🦋
I may never respond.

John Speno JohnSpeno

🦋
I may never respond.
View GitHub Profile
@JohnSpeno
JohnSpeno / join_promotion
Created May 23, 2023 22:21 — forked from akaariai/join_promotion
Django join promotion
=========================
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]
@JohnSpeno
JohnSpeno / durability.py
Created November 20, 2020 20:00 — forked from seddonym/durability.py
Durable decorator
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.
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
import queue
import threading
import time
import random
NUM_WORKERS = 20
class Worker(threading.Thread):
"""A worker thread."""
def __init__(self, input, output=None):
#!/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.
create type numeric_quartiles_plus as (
min float,
q05 float,
q10 float,
q25 float,
q50 float,
q75 float,
q90 float,
q95 float,
max float,
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)
#!/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'
@JohnSpeno
JohnSpeno / .screenrc
Created September 24, 2014 17:37
my .screenrc file
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
#!/bin/sh
#
# gunicorn_sr Startup script for gunicorn for sr
#
# chkconfig: - 86 14
# processname: gunicorn
# pidfile:
# description: Python application server
#
### BEGIN INIT INFO