Skip to content

Instantly share code, notes, and snippets.

View gist:1343386
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 Feb 23, 2012
MTI traceback with explicit pk
View models.py
>>> 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)
View pysearch.py
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 Mar 26, 2012
sitdown (or standup)
View gist:2206093
#!/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 Apr 1, 2012
sitdown (or standup) with nvidia proprietary driver
View xorg.conf
#!/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 Apr 24, 2012
.bashrc.virtualenvwrapper
View gist:2481292
# 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 Mar 27, 2018
reghex checker
View reghex.py
#!/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 Dec 14, 2015
URL tree walkers, recursive and non-recursive.
View walk_url_tree.py
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 Feb 28, 2013
Force django admin to SSL
View urls.py
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:
View gpgsig
#!/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:
#