Skip to content

Instantly share code, notes, and snippets.

View dcramer's full-sized avatar
💭
I may be slow to respond.

David Cramer dcramer

💭
I may be slow to respond.
View GitHub Profile
def missing_access(request, perm_name, *args):
resp = plugins.first('missing_access_response', request, perm_name, *args)
if resp:
return resp
return HttpResponseRedirect(reverse('sentry'))
@csrf_protect
@has_access(MEMBER_OWNER)
def create_new_team_project(request, team):
<style type="text/css">
* {
font-family: 'Open Sans', Helvetica, 'Bitstream Vera Sans', Arial, Verdana, sans-serif;
}
.container {
width: 600px;
border: 1px solid rgb(182, 201, 212);
}
h1 {
font-weight: bold;
@task
def test():
execute(test_parallel)
execute(test_serial)
@parallel()
@task
def test_parallel():
puts("parallel")
def in_role(host, role):
return host in env.roledefs.get(role, '')
def only_roles(*role_names):
"""
Guarantee a task is only run on the host if its a member of one of the
given roles.
"""
def decorator(func):
@hosts('one', 'two')
def foo():
puts 'bar'
def test():
execute(foo)
$ fab test -P
[one] bar
[two] bar
roles/queue.rb
roles/worker.rb
roles/web.rb
# vagrant / local (composite roles)
# runs with chef-solo
roles/development.rb
role[web]
role[queue]
role[worker]
$ py.test -x
======================================================== test session starts ========================================================
platform darwin -- Python 2.7.2 -- pytest-2.3.4
plugins: django
collected 3 items
tests/djnydus/db/base/tests.py E
============================================================== ERRORS ===============================================================
________________________________________ ERROR at setup of DjangoConnectionsTest.test_simple ________________________________________
@dcramer
dcramer / create_or_update.py
Created March 13, 2013 20:25
MySQL create_or_update for Django ORM
from __future__ import unicode_literals, division
import operator
from django.db import connections, transaction, DEFAULT_DB_ALIAS
from django.db.models.expressions import ExpressionNode, F
def create_or_update(model, using=DEFAULT_DB_ALIAS, **kwargs):
"""
Similar to get_or_create, either creates a row or updates it.
@dcramer
dcramer / gist:5146800
Last active December 14, 2015 20:49
Code Review Quality/Performance Indicators

Questions to answer:

  • Is it a productivity hit?
  • What happens when only new hires are required to do code review?
  • How bad at large patches?
  • What about lack of automated tests?
  • Does a lot of back and forth (e.g. comments) indicate problems?
  • Does assigning more people (or less) to reviews improve anything?
  • How does a person spending more time committing (vs reviewing) affect the team?
@dcramer
dcramer / args.py
Last active June 1, 2021 14:28
Python Standards (that I would change and enforce if I could)
# dont do this
this_function_name(foo, bar
baz)
# do this
cramers_version(
foo, bar, baz)
# allow this
cramers_version(foo, bar,