Skip to content

Instantly share code, notes, and snippets.

@agriffis
agriffis / gist:1343386
Created November 6, 2011 19:58
isplit
def isplit(patt, s, flags=None):
"""Return a generator that behaves similarly to re.split, with the
following differences:
1. It's a generator, not a list.
2. Zero-width separators work properly
(see http://bugs.python.org/issue3262)
3. The sequence always includes the separators, similar to calling
@agriffis
agriffis / models.py
Created February 23, 2012 19:01
MTI traceback with explicit pk
>>> from bar.models import Bar
>>> b=Bar()
>>> b.pk='abcdef'
>>> b.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/aron/.virtualenvs/pp/lib/python2.7/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/aron/.virtualenvs/pp/lib/python2.7/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
@agriffis
agriffis / pysearch.py
Created March 1, 2012 17:43
pysearch
import operator, os, re, urllib
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
__all__ = ['PySearch']
anchors, lower_anchors = None, None
def get_anchors():
global anchors, lower_anchors
if anchors is None:
@agriffis
agriffis / gist:2206093
Created March 26, 2012 15:48
sitdown (or standup)
#!/bin/bash
hdmi=HDMI-1
dvi=DVI-D-1
case /$0 in
*/sitdown) xrandr --output $hdmi --auto ; xrandr --output $dvi --off ;;
*/standup) xrandr --output $dvi --auto ; xrandr --output $hdmi --off ;;
esac
@agriffis
agriffis / xorg.conf
Created April 1, 2012 20:25
sitdown (or standup) with nvidia proprietary driver
#!/bin/bash
if glxinfo | grep -q 'NVIDIA Corporation'; then
case /$0 in
*/sitdown) xrandr -s 1 ;;
*/standup) xrandr -s 0 ;;
esac
else
hdmi=HDMI-1
dvi=DVI-D-1
@agriffis
agriffis / gist:2481292
Created April 24, 2012 16:37
.bashrc.virtualenvwrapper
# Dynamically load virtualenvwrapper functions to reduce shell startup
# time.
#
# Copyright 2012 Aron Griffis <aron@arongriffis.com>
# Released under the GNU GPL v3
#######################################################################
# Python virtualenvwrapper loads really slowly, so load it on demand.
if [[ $(type -t workon) != function ]]; then
virtualenv_funcs=( workon deactivate mkvirtualenv )
@agriffis
agriffis / reghex.py
Last active March 27, 2018 05:41
reghex checker
#!/usr/bin/env python3
#
# reghex.py -- checker for reghex puzzle
#
# Input on stdin in the following format:
#
# XXXXXXX
# XXXXXXXX
# XXXXXXXXX
# XXXXXXXXXX
@agriffis
agriffis / walk_url_tree.py
Last active December 14, 2015 07:59
URL tree walkers, recursive and non-recursive.
def walk_url_tree(urls):
"""
Generator to walk a tree consisting of RegexURLPattern (with callback)
and RegexURLResolver (with nested url_patterns).
Recursive depth-first.
"""
for u in urls:
if hasattr(u, 'url_patterns'):
for u2 in walk_url_tree(u.url_patterns):
@agriffis
agriffis / urls.py
Created February 28, 2013 13:41
Force django admin to SSL
def walk_url_tree(urls):
"""
Generator to walk a tree consisting of RegexURLPattern (with callback)
and RegexURLResolver (with nested url_patterns).
"""
for u in urls:
if hasattr(u, 'url_patterns'):
for u2 in walk_url_tree(u.url_patterns):
yield u2
else:
#!/bin/bash
#
# gpgsig, a little script to sign your gpg/pgp keys
#
# Copyright 2006,2013 Aron Griffis <agriffis@n01se net>
# Released under the GNU GPL v2
#
# Based loosely on ideas Damien Chrisment's gpgsig, but written from scratch to
# be simpler and just do what I need. Simply:
#