Skip to content

Instantly share code, notes, and snippets.

View pjz's full-sized avatar

Paul Jimenez pjz

View GitHub Profile
@pjz
pjz / gist:3821862
Created October 2, 2012 18:08
Set prompt to fqdn - domain.toplevel
# This will change your prompt and screen/tmux tab title based on how many
# fields there are in the FQDN. For a normal 3 field FQDN, it will use $HOSTNAME
# like normal. For 4+ fields it will set it to field1.field2.
# Rename screen window
function rename_screen_tab () { echo -ne "\x1bk$@\x1b\\"; return 0; }
MYHOST=`echo $HOSTNAME | sed 's/[.][^.]*[.][^.]*$//'`
[[ $TERM == "screen" ]] && PROMPT_COMMAND='rename_screen_tab ${MYHOST}'
PS1="\d \A \w\n\u@$MYHOST > "
@pjz
pjz / filters.py addendum
Created June 27, 2012 03:37
filter files by tags
TAGGED_FILES = {}
def tag(filename, taglist):
for tag in taglist:
TAGGED_FILES[tag] = TAGGED_FILES.get(tag, frozenset([])).union(frozenset([filename]))
def by_tag(hook, tag):
"""A filter for hooks. tag is the tag that must be present for the file if it's to match.
@pjz
pjz / filters.py
Created June 1, 2012 01:33
aspen auth filters
import re
def by_regex(hook, regex_tuples, default=True):
"""A filter for hooks. regex_tuples is a list of (regex, filter?) where if the regex matches
the requested URI, then the hook is applied or not based on if filter? is True or False.
"""
regex_res = [ (re.compile(regex), disposition) for regex, disposition in regex_tuples.iteritems() ]
def filtered_hook(request):
for regex, disposition in regex_res:
@pjz
pjz / httpbasic.py
Created May 22, 2012 04:37
aspen basic auth modle
import base64
from aspen import Response
def inbound_responder(*args, **kwargs):
""" see BasicAuth object for args; they're passed through """
auth = BasicAuth(*args, **kwargs)
def _(request):
request.auth = BAWrapper(auth, request)
@pjz
pjz / testdoc
Created March 14, 2012 01:21
golang docstring access
#!/usr/bin/gorun
package main
import "os"
import "fmt"
import "strings"
import "go/doc"
import "go/token"
import "go/parser"
@pjz
pjz / gist:2009714
Created March 10, 2012 02:06
Kivy StringListView box v2
import kivy
kivy.require('1.0.9')
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty, NumericProperty, ListProperty, ObjectProperty
Builder.load_string('''
[StringListViewItem@BoxLayout]: