Skip to content

Instantly share code, notes, and snippets.

View shacker's full-sized avatar
💭
Djangonaut, tree hugger

Scot Hacker shacker

💭
Djangonaut, tree hugger
View GitHub Profile
@shacker
shacker / gist:f5b814762f373614653f10a2abbb658a
Created November 21, 2017 18:27
Example gravatar implementation for Python 2 *and* 3, using libgravatar
# For just python:
pip install libgravatar
# libravatar documentation/options at:
# http://libgravatar.readthedocs.io/
# Then:
from libgravatar import Gravatar
@shacker
shacker / test_views.py
Created November 22, 2017 18:41
Convert output of django-extensions' `show_urls` to a python list of "simple" URLs
import re
from django.core.management import call_command
from test_plus.test import TestCase
class SmokeTestAllViews(BaseUserTestCase):
def test_all_view_respones(self):
"""
@shacker
shacker / .gitconfig
Last active May 28, 2018 06:51
shacker .gitconfig aliases
[alias]
alias = config --get-regexp ^alias\\.
br = branch
bra = branch -a -v -v
cm = commit -a
co = checkout
cp = cherry-pick
dev = checkout develop
find = "!f() { git ls-files |grep $@; }; f"
last = log -1 HEAD
# General pattern for a data "chunking" process to prevent a server from hitting memory limits
# when calling .update() or .delete() on large amounts of data. In this example, we enter an
# infinite loop, then keep deleting 1000 records at a time until the records are exhausted,
# then exit the loop. You can't call .update() or .delete() after taking a slice, hence the need
# for two queries rather than one.
t = Territory.objects.get(name="some-territory")
while True:
loc_ids = Location.objects.filter(territory=t)[:1000].values_list("id", flat=True)