This file contains 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 WSGIApp(object): | |
POST_PROCESSING_TIMEOUT = 3 | |
def async_response_handler(self, request, response): | |
log.debug('Running async handler') | |
time.sleep(2) | |
log.debug('Finished async handler') | |
def __call__(self, environ, start_response): | |
# snip | |
log.debug('Dispatching post-response handlers...') | |
gevent.spawn( |
This file contains 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 sys | |
import logging | |
log = logging.getLogger(__name__) | |
def fn(*args): | |
log.debug('Got %s as args' % (args,)) | |
log.info('This function does nothing.') | |
log.warning("We've run out of Colombian coffee.") | |
sys.stderr.write('This is on stderr.\n') | |
sys.stdout.write('This is on stdout.\n') |
This file contains 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
[31/Mar/2013 13:37:15] "GET /admin/ HTTP/1.1" 500 59 | |
Traceback (most recent call last): | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run | |
self.result = application(self.environ, self.start_response) | |
File "/Users/jag/Development/playwithfeincms/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__ | |
response = self.get_response(request) | |
File "/Users/jag/Development/playwithfeincms/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response | |
response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) | |
File "/Users/jag/Development/playwithfeincms/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception | |
if resolver.urlconf_module is None: |
This file contains 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
tif_files = [] | |
for filename in files: | |
if not filename.endswith('.tif'): | |
continue | |
tif_files.append(filename) | |
# ooooorrrrrr.... | |
tif_files = [filename for filename in files if filename.endswith('.tif')] |
This file contains 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
map $host $desktop_host { | |
default $host; | |
~^m\.(?<domain>.*) $domain; | |
} | |
server { | |
# ... snip ... | |
if ($desktop_rewrite = perform) { | |
rewrite ^(.*)$ http://$desktop_host$1; |
This file contains 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
config.vm.provision :puppet do |puppet| | |
puppet.manifests_path = "puppet/manifests" | |
puppet.manifest_file = "vagrant.pp" | |
puppet.facter = { | |
"dom0_uid" => Process.uid.to_s(), | |
"dom0_gid" => Process.gid.to_s(), | |
} | |
end |
This file contains 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
{'query': {'filtered': {'filter': {'range': {'@timestamp': {'to': datetime.datetime(2014, 5, 10, 19, 48, 52), 'from': datetime.datetime(2014, 5, 8, 20, 40, 40)}}, 'term': {'parent_object_id': 2, 'parent_content_type': 2}}, 'query': {'match_all': {}}}}, 'facets': {'content_obj': {'terms': {'fields': ['content_type', 'object_id', 'action'], 'order': 'count'}}}} |
This file contains 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 photoset_as_json(photoset_id): | |
# ... | |
photoset_obj = PhotoSet.objects.get(pk=photoset_id).select_related('owner').prefetch_related('photo') | |
dict_[photos] = [photo_as_json(p) for p in photoset_obj.photo_set.all()] | |
dict_[owner] = user_as_json(photoset_obj.owner) | |
# ... | |
return dict_ |
This file contains 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
# N+1 queries | |
for photoset_obj in PhotoSet.objects.filter(owner=request.user): | |
latest_photo_obj = photoset_obj.photo_set.all().order_by('-created')[0] | |
yield photoset_obj, latest_photo_obj | |
This file contains 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
# Django 1.4 only allowed this | |
episodes = [ | |
rel.episode for rel in series_obj.episode_relations.order_by('episode__title') | |
if rel.episode.showtime_set.filter(start__lte=end_date) | |
] | |
# Django 1.7 allows this | |
episodes = Episode.objects.filter(episoderelation__series=series_obj, | |
showtime__start__lte=end_date).order_by('title').distinct() |
OlderNewer