Skip to content

Instantly share code, notes, and snippets.

View jdunck's full-sized avatar

Jeremy Dunck jdunck

View GitHub Profile
I'm here to help you succeed. It's not about me, it's about you. If I ever make you feel less than, or someone makes you feel that way, tell me. I'm happy to be corrected when I screw up. My entire purpose in working with Hackbright is to do something concrete to improve the field and the future that we're building together. You are a part of that future.
@jdunck
jdunck / gist:9414127
Created March 7, 2014 15:54
Find gendered language in code
find . -not \( -path '*node_module*' -o -path '*.git*' -o -path '*jasmine*' -o -path '*assets*' -o -type d \) | xargs grep -in -E '(\bhe\b)|(\bhis\b)|(\bher\b)|(\b\she\b)'
@jdunck
jdunck / force_html_middleware.py
Last active August 29, 2015 14:02 — forked from leetrout/force_html_middleware.py
A hack to wrap API responses in HTML so that django debug toolbar can be used on API requests.
def uncompress_string(c):
from io import BytesIO
from gzip import GzipFile
zbuf = BytesIO(c)
with GzipFile(mode='rb', compresslevel=6, fileobj=zbuf) as zfile:
return zfile.read()
class ForceDebugJSONMiddleware(object):
def process_response(self, request, response):
"""Add html, head, and body tags so debug toolbar will activate."""
@jdunck
jdunck / Example output
Last active August 29, 2015 14:02
Generate south depends_on based on the current django project tree
depends_on = (
('about', '0004_fake_user_fk'),
('accounts', '0029_auto__del_registration'),
('activity_feed', '0002_fake_user_fk'),
('analytics', '0006_add_labels'),
('art', '0036_auto__chg_field_packpurchase_royalty_millicents_per_credit__chg_field_'),
('bots', '0002_fake_user_fk'),
('comments', '0002_fake_user_fk'),
('core', '0012_auto__del_field_creatorprofile_points_balance__add_field_creatorprofil'),
('creator', '0002_fake_user_fk'),
@jdunck
jdunck / gist:c5f6ba4fc130f2a20c12
Created July 22, 2014 21:35
Django to raw SQL to streaming dicts
from psycopg2.extras import DictCursor
from django.db import connections
def get_cursor(alias='default', cursor_factory=None):
# map from django's ORM layer to the raw DB cursor.
wrapped_conn = connections[alias]
# hack to ensure connection is immediately opened:
if wrapped_conn.connection is None:
@jdunck
jdunck / gist:a98f4d22f33cacc0f83a
Created October 1, 2014 01:26
Django - force debug toolbar on JSON responses
def uncompress_string(c):
from io import BytesIO
from gzip import GzipFile
zbuf = BytesIO(c)
with GzipFile(mode='rb', compresslevel=6, fileobj=zbuf) as zfile:
return zfile.read()
class ForceDebugJSONMiddleware(object):
def process_response(self, request, response):
"""Add html, head, and body tags so debug toolbar will activate."""
@jdunck
jdunck / gist:625ede423016d7d0e277
Created November 20, 2014 02:01
most used base templates
$ find . -name '*.html' | xargs grep -h '{% extends' | sed -e "s/'/\"/g" | sort | uniq -c | sort -n
1 <!DOCTYPE html>{% extends "common/templates/responsive_base.html" %}
1 {% extends "admin/change_form.html" %}
1 {% extends "admin/index.html" %}
1 {% extends "base.html" %}
1 {% extends "common/templates/blank.html" %}
1 {% extends "common/templates/donut-base.html" %}
1 {% extends "messaging/templates/email/base_ss_email_to_user.html" %}
1 {% extends "provider/templates/preview_base.html" %}
1 {% extends "rate-appointment-form-base.html" %}
@jdunck
jdunck / gist:db81a1adbfd7c5428ffd
Created November 20, 2014 20:10
As efficient a QuerySet.__contains__ as can be mustered.
def instance_in_qs(instance_or_pk, qs):
if qs._result_cache is None:
if qs.query.can_filter():
pk = getattr(instance_or_pk, 'pk', instance_or_pk)
return qs.filter(pk=pk).exists()
else:
objs = list(qs)
else:
objs = qs._result_cache
@jdunck
jdunck / Find old-style (pre django 1.5) {% url %} tags
Last active August 29, 2015 14:10
Find old-style (pre django 1.5) {% url %} tags
Find: "\{\%\W*url +([-_a-zA-Z:0-9]+)\W"
Replace: "{% url '\1' "
(Don't forget you'll also need
{% load url from future %} if on 1.5.
----
If you'd like to whittle the tree down to just files that could possibly have old-style urls:
Find files in tree that have the {% url tag in them at all:

Keybase proof

I hereby claim:

  • I am jdunck on github.
  • I am jdunck (https://keybase.io/jdunck) on keybase.
  • I have a public key whose fingerprint is 8801 066B D85C 57BA 0D02 8BF9 A4EA DF1F 0080 A663

To claim this, I am signing this object: