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 QuerySetDoubleIteration(Exception): | |
"A QuerySet was iterated over twice, you probably want to list() it." | |
pass | |
# "Skinny" here means we use iterator by default, rather than | |
# ballooning in memory. | |
class SkinnyManager(Manager): | |
def get_query_set(self): | |
return SkinnyQuerySet(self.model, using=self._db) |
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 attach_foreignkey(objects, field, select_related=None): | |
""" | |
Shortcut method which handles a pythonic LEFT OUTER JOIN. | |
``attach_foreignkey(posts, Post.thread)`` | |
""" | |
field = field.field | |
qs = field.rel.to.objects.filter(pk__in=distinct(getattr(o, field.column) for o in objects)) | |
if select_related: | |
qs = qs.select_related(*select_related) |
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 SQLDebugCommand(object): | |
def __init__(self): | |
from devserver.modules.sql import SQLSummaryModule, SQLRealTimeModule | |
from devserver.logger import GenericLogger | |
from mock import Mock | |
self.modules = [ | |
#SQLRealTimeModule(GenericLogger(SQLRealTimeModule)), | |
SQLSummaryModule(GenericLogger(SQLSummaryModule)), | |
] | |
self.mock_request = Mock() |
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
#!/bin/sh | |
file="Sublime Text 2 Build ${1} x64.tar.bz2" | |
# Uncomment line below for 32 bit. | |
#file="Sublime Text 2 Build ${1}.tar.bz2" | |
url="http://www.sublimetext.com/${file}" | |
first=0 | |
if [ $(id -u) -ne 0 ] | |
then |
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
# ~/.gitconfig | |
[branch] | |
autosetupmerge = true | |
[push] | |
default = current | |
[core] | |
excludesfile = .gitignore |
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
""" | |
Script for automated analysis of profiling data in MongoDB, | |
gathered by Mongo with db.setProfilingLevel(1). | |
See <http://www.mongodb.org/display/DOCS/Database+Profiler> | |
TODO: pass collection and database with profiling data in arguments | |
TODO: make thread-safe | |
TODO: handle map-reduce operations | |
""" |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
It appears that Apple somehow broke Python in Mountain Lion, so even with the latest Command Line Tools and Xcode 4.4 virtualenv won't properly work. During virtual environment creation it will try to install easy_install inside /Library hierarchy. So let's give it a quick workaround. Let's install custom python into your $HOME-directory using pythonbrew!
Without the Apple Mac Developer account you won't even see the proper download link for the latest CL Tools and the old one won't work on ML. So here's the link: http://goo.gl/iBTXh. It points towards the Apple website so don't worry.
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
# Elasticsearch Cheatsheet - an overview of commonly used Elasticsearch API commands | |
# cat paths | |
/_cat/allocation | |
/_cat/shards | |
/_cat/shards/{index} | |
/_cat/master | |
/_cat/nodes | |
/_cat/indices | |
/_cat/indices/{index} |
OlderNewer