Skip to content

Instantly share code, notes, and snippets.

View pjz's full-sized avatar

Paul Jimenez pjz

View GitHub Profile
@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]:
@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 / 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 / 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 / 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 / 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 / gist:4159060
Created November 28, 2012 04:44
spec work re: content pipelines
from subprocess import Popen, PIPE
def cat(*files):
result = []
for f in files:
result.extend(open(f).readlines())
return result
def pipe(cmd, text=None,filename=None):
@pjz
pjz / gist:4737190
Created February 8, 2013 07:02
auto-css-compressing simplate for gittip
from fabricate import run
raw_css = os.path.join(website.www_root, '..', 'templates', 'gittip.css')
class Cache(object):
data = None
cache = Cache()
^L
@pjz
pjz / fakemoduletest.py
Created May 11, 2013 03:47
make something show up as a module to some supplied code you're going to exec
src = """
from fakemodule import fakefunc
fakefunc()
print dir()
"""
def call_with_fakemodule(usersrc):
class fmod(object):
@staticmethod
@pjz
pjz / docker-start-huginn
Last active February 12, 2021 03:17
An idempotent start script for huginn under docker
#!/bin/bash
## these need to be set
# initial account credentials
SEED_USER=admin
SEED_PASS=password
# required for new users to be able to sign up ; default to something random
INVITATION_CODE=`dd if=/dev/urandom bs=1024 count=1 | md5sum -`