This file contains hidden or 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
| 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: |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| $ 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| Track last notified | |
| =================== | |
| Alert model | |
| -> binds to many users | |
| - alert_date | |
| Alert on Threshold | |
| ================== |
This file contains hidden or 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
| /*! 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 | |
| * |
This file contains hidden or 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
| 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)): |
This file contains hidden or 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
| The gist is, you give a path expression (xpath-like), a condition, and a action. | |
| ---- | |
| Scrub all local vars in a stackframe where the key matches something like a password: | |
| Path: | |
| //sentry.interfaces.Stacktrace/frames[*]/vars/key | |
| Condition: |
This file contains hidden or 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 heapq | |
| from threading import Lock | |
| class HeapQueue(object): | |
| def __init__(self, values=None, maxsize=None, reversed=False): | |
| """ | |
| Create a new heap queue. | |
| - ``maxsize`` will create a capped queue. |