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
""" | |
Patches the database wrapper and template engine to throw an exception if a query is executed inside of a template. | |
In your urls.py, enable it like so: | |
>>> import monkey | |
>>> monkey.patch_templates() | |
""" | |
import logging |
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
GitHub username: dcramer | |
Day job: DISQUS | |
Favorite open source project: Django | |
Open Source contributions (if any): Sentry, Gargoyle, Debug Toolbar, <100 more> | |
Stranded on an island, what 3 items do you take: Laptop, Mobile Phone, and as much alcohol as I can manage :) | |
Tie-breaker, pick a number between 1 and 20,000: 20,000 |
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
Day job: | |
I build cool Python things at Disqus | |
Favorite Python project: | |
Does it count if I pick my own? :) | |
github.com/dcramer/django-sentry |
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
"data": { | |
"__sentry__": { | |
"frames": [ | |
{ | |
"filename": filename, | |
"module": module, | |
"function": function, | |
"lineno": ..., | |
"vars": { | |
"key": "value" |
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
# install requirements from github | |
pip install git+ssh://[email protected]:dcramer/[email protected]#egg=raven==2.0.0-DEV | |
pip install git+ssh://[email protected]:dcramer/[email protected]#egg=sentry==2.0.0-DEV | |
# start sentry webserver | |
sentry start | |
# add raven to whatever app | |
# e.g. Django: | |
INSTALLED_APPS = ( |
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
# create a dummy heroku app | |
heroku create --stack cedar | |
# add sentry | |
heroku addons:add sentry | |
# fetch your config | |
heroku config | grep SENTRY_DSN | |
# configure your application via http://getsentry.com/guide/ |
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 ManagerMock(manager, return_value=None): | |
""" | |
>>> objects = ManagerMock(Post.objects, ['queryset', 'result']) | |
>>> assert objects.filter() == objects.all() | |
""" | |
return_value = return_value or [] | |
class ManagerMock(mock.MagicMock): | |
def _get_child_mock(self, **kwargs): |
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
Getting Play to work: | |
- Change Gemfile.lock's version of mocha to be 0.11.1 | |
- Open iTunes -> select iTunes DJ -> Start playing a song | |
Some caveats: | |
- iTunes Match songs (that are not on disk) won't queue | |
- Frontend seems sluggish, but it could be the machine it's on (not super powerful, but should be able to keep up) |
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
with cache.Lock('key name'[, timeout]): | |
# do something that usually has a race thats too hard to solve | |
# best example | |
def get_or_create(model, **kwargs): | |
with cache.Lock('get_or_create:%s:%s' % (model, make_key(kwargs)): | |
model.objects.get_or_create(**kwargs) |
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
class Lock(object): | |
""" | |
Uses the defined cache backend to create a lock. | |
>>> with Lock('key name'): | |
>>> # do something | |
""" | |
def __init__(self, lock_key, timeout=10, cache=None): | |
if cache is None: | |
self.cache = _cache |