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
# post_commit and post_rollback transaction signals for Django with monkey patching | |
# Author Grégoire Cachet <[email protected]> | |
# http://gist.github.com/247844 | |
# | |
# Usage: | |
# You have to make sure to load this before you use signals. | |
# For example, create utils/__init__.py and then utils/transaction.py contening | |
# this gist in you project. Then add "import utils.transaction" in your project | |
# __init__.py file | |
# |
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
# Copied from backbone.js | |
getValue = (object, prop) -> | |
if not (object and object[prop]) | |
return null | |
if _.isFunction(object[prop]) then object[prop]() else object[prop] | |
eventSplitter = /^(\S+)\s*(.*)$/ | |
namedSelectorPattern = /^{(.+)}$/ | |
viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'elements'] |
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 django import template | |
from django.utils.safestring import mark_safe as safe | |
register = template.Library() | |
class PaginationNav(object): | |
def __init__(self, page_number=None, display=None, is_current=False): | |
self.page_number = page_number | |
self.is_current = is_current | |
self.display = display or page_number or '' |
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
''' | |
Stack-based mode managers for mode_(sudo|user|local|remote). | |
''' | |
from fabric.api import env | |
MODE_STACKS = {} | |
env.cuisine_mode_sudo = False | |
env.cuisine_mode_local = False | |
class ModeStackManager(object): |
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
''' | |
Stack-based mode managers for mode_(sudo|user|local|remote). | |
''' | |
from fabric.api import env | |
MODE_STACKS = {} | |
env.cuisine_mode_sudo = False | |
env.cuisine_mode_local = False | |
class ModeStackManager(object): |
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 ssh | |
import subprocess | |
import time | |
from fabric.api import env, settings | |
from fabric.state import output | |
from fabric.operations import (_shell_wrap, _prefix_commands, _prefix_env_vars, | |
_sudo_prefix, _AttributeString) | |
from fabric.io import output_loop | |
from fabric.thread_handling import ThreadHandler |
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
# 1) Add MasqueradeMiddleware to Django's middleware stack (see comment below for placement) | |
class MasqueradeMiddleware(object): | |
''' | |
Looks for a field in the active session specifying a user to masquerade as | |
and sets request.user to that user, storing the real user to the session. | |
This middleware is dependent on the existence of sessions, so it should be | |
deployed after ('inside') Django's session middleware. It should probably | |
be deployed after middleware like the TermsAndConditionsMiddleware which | |
implement one-time intercepts, so that masquerading superusers don't get |
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 ConfigResolver(object): | |
def __init__(self, **kwargs): | |
self.config_templates = kwargs | |
self.config = resolve(copy.copy(kwargs)) | |
def __getattr__(self, attr): | |
return self.config[attr] | |
def __getitem__(self, item): |
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
RETURN_CODE=0 | |
MIGS_PATH="thefundersclub/migrations" | |
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
// Exports to Nesh shell | |
// + Add a shell alias 'alias nesh="nesh --eval {this file}"' to automatically | |
// trick out your shell with these natural code enhancements. | |
__ = _ = require('lodash'); | |
config = require('./common').config(); | |
db = require('./models'); | |
Q = require('q'); | |
mongo = require('monk')(config.db.mongo.url); |
OlderNewer