Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Djangonaut, tree hugger

Scot Hacker shacker

💭
Djangonaut, tree hugger
View GitHub Profile
@shacker
shacker / debug_loader.py
Created Feb 27, 2014
Template name overlays for Django
View debug_loader.py
from django.template.loader import BaseLoader
from django.template.loader import find_template_loader
from django.template.loader import make_origin
from django.template.base import TemplateDoesNotExist
from django.template.base import Template
'''
Deubug template loader visually shows which templates are being invoked in the
process of rendering an entire page. To use, wrap your your existing loaders
@shacker
shacker / pg_backup
Created Mar 5, 2014
Get list of all dbs on remote server, dump each to its own dir on this server
View pg_backup
#!/bin/bash
# Get list of all dbs on remote server, dump each to its own dir on this server
export PGPASSWORD="secret"
HOST='example.com'
DBUSER='someuser'
BASEDIR='/var/backups/postgres/'
temp1='/tmp/dbdata_tmp1.txt'
temp2='/tmp/dbdata_tmp2.txt'
@shacker
shacker / keybase.md
Created Nov 14, 2014
keybase.io identity proof
View keybase.md

Keybase proof

I hereby claim:

  • I am shacker on github.
  • I am shacker (https://keybase.io/shacker) on keybase.
  • I have a public key whose fingerprint is D28A CA5D AE23 7727 D8EB 8F92 3844 B708 0026 C9C3

To claim this, I am signing this object:

@shacker
shacker / add_members-nomail
Created Oct 20, 2012
Provides an -e flag to Mailmans' 2.x add_members script for nomail delivery option
View add_members-nomail
54a55,58
> --enable-mail=<y|n>
> -e <y|n>
> Enable user mail deilvery options.
79a84
> from Mailman import MemberAdaptor
127c132
< def addall(mlist, members, digest, ack, outfp):
---
> def addall(mlist, members, digest, ack, outfp, enable):
@shacker
shacker / gift-circle.py
Created Dec 5, 2010
Replace "drawing names from a hat" gift exchanges with a quick script
View gift-circle.py
#!/usr/bin/python
'''
Python-based gift exchange randomizer.
Step through a list of people and, for each member of that list,
select someone else to be a recipient of their gift. That recipient:
A) Must not be themselves (no self-gifting)
B) Must not already have been assigned as a recipient
@shacker
shacker / stream_blocks.py
Last active Nov 26, 2016
BlockQuoteBlock for use with Wagtail Streamfields
View stream_blocks.py
from django import forms
from django.utils.encoding import force_text
from django.utils.html import format_html
from wagtail.wagtailcore.blocks import FieldBlock
class BlockQuoteBlock(FieldBlock):
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs):
self.field = forms.CharField(
@shacker
shacker / admin.py
Last active Apr 11, 2017
ORM Logging boilerplate
View admin.py
from dirapp.models import Log
from django.contrib import admin
class LogAdmin(admin.ModelAdmin):
search_fields = ['user__username', 'action']
list_display = ('user', 'anon_username', 'action', 'target', 'status', 'ip_addr', 'timestamp',)
list_filter = ['target', 'status']
admin.site.register(Log, LogAdmin)
@shacker
shacker / gist:2fdf105f2d51bebedc8c3ecd99176677
Last active Nov 8, 2017
Blog: github version template tag 1
View gist:2fdf105f2d51bebedc8c3ecd99176677
@register.simple_tag
def git_ver():
'''
Retrieve and return the latest git commit hash ID and tag as a dict.
'''
git_dir = os.path.dirname(settings.BASE_DIR)
try:
# Date and hash ID
@shacker
shacker / gist:f5b814762f373614653f10a2abbb658a
Created Nov 21, 2017
Example gravatar implementation for Python 2 *and* 3, using libgravatar
View gist:f5b814762f373614653f10a2abbb658a
# 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 Nov 22, 2017
Convert output of django-extensions' `show_urls` to a python list of "simple" URLs
View test_views.py
import re
from django.core.management import call_command
from test_plus.test import TestCase
class SmokeTestAllViews(BaseUserTestCase):
def test_all_view_respones(self):
"""