Skip to content

Instantly share code, notes, and snippets.

@borntyping
borntyping / after.py
Created February 9, 2013 11:24
New PyTentd testing example
def test_create_new_profile(self, entity):
schema = 'https://testprofile.example.com/'
data = {'data': 'test'}
response = PUT('entity.profile', data, secure=True, schema=schema)
profile = entity.profiles.get(schema=schema)
assert response.json() == profile.to_json() == data
@borntyping
borntyping / Makefile
Created February 4, 2013 16:48
Dependency graph for pytentd
# Requires snakefood python module
all: data clusters graph
data:
@echo "Generating data"
@sfood tentd > /tmp/tentd.deps
clusters: data
@echo "Clustering data"
@borntyping
borntyping / nose.py
Last active December 11, 2015 03:48
Runs nosetests using sniffer, but drops much of the output and avoids reloading python modules
#!/usr/bin/env python
from os import getcwd
from sys import argv
from subprocess import Popen
from pynotify import init, Notification
from sniffer.broadcasters import PynotifyEmitter
from sniffer.main import run
from sniffer.runner import Sniffer
@borntyping
borntyping / mongoengine_example.py
Created January 15, 2013 15:52
The result of me trying to get mongoengine deletion rules to work, as the documentation is a little confusing (or even misleading).
from mongoengine import *
class QuerySetProperty(object):
"""A set of documents belonging to an entity from another collection
Basically, provides the functionality a backref would provide."""
def __init__(self, cls):
self.cls = cls
def __get__(self, instance, owner):
@borntyping
borntyping / packaging.sh
Created November 25, 2012 17:36
My python packaging cheatsheet
# Includes commands for multi-version python packages
# Ignore the commands you don't need :)
# Run tests
nosetests
# Create python package
python setup.py sdist upload
sudo python setup.py install
"""
`argumented` provides a way of 'multiplying' functions - usually test cases -
allowing them to be called with multiple argument sets and still appear as
seperate test cases.
In the following example, each of the test cases would be replaced with two test
cases, each of which would call the test case with the given arguments.
`@argument(*args, **kwargs)`
@borntyping
borntyping / parser.py
Created January 31, 2012 02:40
Parser for irc messages
"""
Parses incoming IRC messages, and formats outgoing IRC messages.
"""
def parse_message (string):
""" Parse an IRC message in the form:
[:{source} ]{command}[ parameters][ :{trailing}]
"""
# Default variables for parameters and trailing,
# as it is possible neither will be assigned
import re
class Event (object):
message = re.compile("^(?::(?P<prefix>\S+) )?(?P<command>\w+|\d\d\d) (?P<params>.+)$")
def __new__ (cls, line, **kwargs):
message = cls.message.search(line)
if message:
prefix, command, params = message.groups()
print prefix, command, params
@borntyping
borntyping / design.txt
Created January 15, 2012 16:44
Design for Tactics irc bot
Instructions
- Restricted commands may only be done by admins, on quotes that belong to the user or on quotes about the user
- Gender
- Set gender: Set the users gender in the database
- "(?=I am|My gender is) (male|female|androgynous)", "Refer to me (by name|randomly)", "Refer to me with <list of five pronouns>"
- "{nick}: I am no refering to you with the pronouns <list of five pronouns>"
- Get gender: Ask the bot if the user has get a gender
- "What is my gender?", "What gender is (?P<person>.+)?
- "You are {gender}", "Person is {gender}"
- Aliases
example_arguments = ["arg1 arg2", "arg1 arg2 :Long argument with spaces in", ":Long argument with spaces in"]
if arguments[-1][0] == ':':
message = arguments[-1]
arguments = arguments[:-1]