Skip to content

Instantly share code, notes, and snippets.

View dcramer's full-sized avatar
💭
I may be slow to respond.

David Cramer dcramer

💭
I may be slow to respond.
View GitHub Profile
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded'
class FixedOAuthFilter(OAuthFilter):
def on_request(self, request):
if not self.on_path(request):
return
params = {}
parsed_url = request.parsed_url
from time import time
from functools import wraps
MINUTE = 60
HOUR = MINUTE * 60
DAY = HOUR * 24
class Metrics(object):
def __init__(self, redis, keyspace='metrics'):
self.db = redis
@dcramer
dcramer / gist:5078280
Last active December 14, 2015 11:19
New Sentry Buffers
When an update comes into the system we fire off something like the following:
>>> app.buffer.incr(
>>> Group, # model class,
>>> {'times_seen': 1}, # counters
>>> {'id': group.id}, # filter restrictions, sometimes a composite key
>>> {'last_seen': now}, # metadata to update when buffer is processed
>>> )
This would get stored in a hash key as following:
@dcramer
dcramer / gist:5146800
Last active December 14, 2015 20:49
Code Review Quality/Performance Indicators

Questions to answer:

  • Is it a productivity hit?
  • What happens when only new hires are required to do code review?
  • How bad at large patches?
  • What about lack of automated tests?
  • Does a lot of back and forth (e.g. comments) indicate problems?
  • Does assigning more people (or less) to reviews improve anything?
  • How does a person spending more time committing (vs reviewing) affect the team?
@dcramer
dcramer / create_or_update.py
Created March 13, 2013 20:25
MySQL create_or_update for Django ORM
from __future__ import unicode_literals, division
import operator
from django.db import connections, transaction, DEFAULT_DB_ALIAS
from django.db.models.expressions import ExpressionNode, F
def create_or_update(model, using=DEFAULT_DB_ALIAS, **kwargs):
"""
Similar to get_or_create, either creates a row or updates it.
$ py.test -x
======================================================== test session starts ========================================================
platform darwin -- Python 2.7.2 -- pytest-2.3.4
plugins: django
collected 3 items
tests/djnydus/db/base/tests.py E
============================================================== ERRORS ===============================================================
________________________________________ ERROR at setup of DjangoConnectionsTest.test_simple ________________________________________
roles/queue.rb
roles/worker.rb
roles/web.rb
# vagrant / local (composite roles)
# runs with chef-solo
roles/development.rb
role[web]
role[queue]
role[worker]
@hosts('one', 'two')
def foo():
puts 'bar'
def test():
execute(foo)
$ fab test -P
[one] bar
[two] bar
def in_role(host, role):
return host in env.roledefs.get(role, '')
def only_roles(*role_names):
"""
Guarantee a task is only run on the host if its a member of one of the
given roles.
"""
def decorator(func):
@task
def test():
execute(test_parallel)
execute(test_serial)
@parallel()
@task
def test_parallel():
puts("parallel")