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
@dcramer
dcramer / fix_requests.py
Last active December 11, 2015 21:28
Because you should maintain API compatibility when you tell everyone to use your shit.
from requests.models import Response
class fixedjson(object):
def __init__(self, func):
self.func = func
def __get__(self, inst, cls):
result = self.func(inst)
class proxy(type(result)):
@dcramer
dcramer / raven.js
Created February 12, 2013 01:18
sourcemap bug
/*! Raven.js a75cbab | github.com/getsentry/raven-js */
/*
* Includes TraceKit
* https://github.com/getsentry/TraceKit
*
* Copyright 2013 Matt Robenolt and other contributors
* Released under the BSD license
* https://github.com/getsentry/raven-js/blob/master/LICENSE
*
@dcramer
dcramer / gist:4773531
Last active December 12, 2015 12:39
Track last notified
===================
Alert model
-> binds to many users
- alert_date
Alert on Threshold
==================
def meanstdv(x):
n, mean, std = len(x), 0, 0
for a in x:
mean = mean + a
mean = mean / float(n)
for a in x:
std = std + (a - mean) ** 2
std = math.sqrt(std / float(n - 1))
return mean, std
@dcramer
dcramer / 1 dyno
Last active December 13, 2015 17:48
gevent hello world w/ apache bench from an AWS m1.large to Heroku
$ ab -c 100 -t 60 http://pure-depths-6229.herokuapp.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking pure-depths-6229.herokuapp.com (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
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 / args.py
Last active June 1, 2021 14:28
Python Standards (that I would change and enforce if I could)
# dont do this
this_function_name(foo, bar
baz)
# do this
cramers_version(
foo, bar, baz)
# allow this
cramers_version(foo, bar,
@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?