Skip to content

Instantly share code, notes, and snippets.

wc = subprocess.Popen(['wc', '-l', 'animes.txt'], stdout=subprocess.PIPE)
res = wc.communicate()[0]
@avidal
avidal / wotmudinfo.py
Created December 18, 2010 03:58
weechat plugin to pull player counts from wotmud.org
import datetime
import re
import time
import urllib2
import weechat
weechat.register("wotmud_playerinfo", "Alex Vidal", "1.0", "MIT", "Fetches WoTMUD Player Info", "", "")
ungettext = lambda single, plural, n: single if n == 1 else plural
@avidal
avidal / get_permissions.py
Created January 14, 2011 21:26
This snippet will get all permission objects for a specific model.
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from myapp.models import MyModel
content_type = ContentType.objects.get_for_model(MyModel)
permissions = Permission.objects.filter(content_type=content_type)

I've been thinking more and more about a mud engine that is version control aware. Throughout this ramble, I'll talk using git terminology, since that is what I'm most familiar with. The concepts should be applicable to most modern version control systems however.

My idea is that there are two methods to the vcs integration, playerfile saving, and world instancing.

Playerfile Saving

In this ideal world, every (configurable) 10 minutes, a worker would sync all players to disk, then commit the changes with a generated commit message (ex: [autosave] 153 player files). The integration would know exactly which playerfiles have changed, and would be able to add those to the index, and commit that index. (in git, you first add changes to an index, then commit those changes. for hg/bzr, you'd most likely run the commit command and pass in all of the changes files)

World Saving

# this is an alias you can drop in your .bashrc (or .profile or .bash_profile or .zshrc or whatever) that'll let
# you use the command `cdp` to cd to the root of your project.
alias cdp='git rev-parse --show-toplevel 2&> /dev/null && cd $(git rev-parse --show-toplevel 2&> /dev/null) || echo "Not a git repository." && test'
# basically, when the parser reaches a [network] block, everything up to the next [network] block or EOF are considered options for that network
# the [channel] blocks are only required if you want to enable options for a specific channel on the network
[core]
logging = on
logfile = logs/%(network)/%(year)/%(channel)-%(month)-%(day).log
nickname = mongbot
plugins = * # by default, enable all plugins. any network/channel that has a plugins setting overrides this list
[network synirc]
import commands as cmd
"""
cmd.register(syntax=None, command=None)
syntax can be a list/tuple of strings, or a string. if it's a list of strings, each string is registered as a valid syntax. if no syntax is specified, it's assumed to not have a syntax (eg: exits has nothing but the actual command name)
command can be a list/tuple of strings, or a string. if it's a list of strings, each string is registered as a valid name for the command. if no commands are specified, it's inferred from the name of the function (eg: def exits registers as 'exits' the command)
"""
@cmd.validators.register('container')
/\b[\w.%+!]+@(?:[^\s`!()\[\]{};:'",<>?«»“”‘’]+[.])+(?:AC|AD|AE|AERO|AF|AG|AI|AL|AM|AN|AO|AQ|AR|ARPA|AS|ASIA|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BIZ|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CAT|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|COM|COOP|CR|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EDU|EE|EG|ER|ES|ET|EU|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GOV|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|INFO|INT|IO|IQ|IR|IS|IT|JE|JM|JO|JOBS|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MG|MH|MIL|MK|ML|MM|MN|MO|MOBI|MP|MQ|MR|MS|MT|MU|MUSEUM|MV|MW|MX|MY|MZ|NA|NAME|NC|NE|NET|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|ORG|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PRO|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SU|SV|SY|SZ|TC|TD|TEL|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TP|TR|TRAVEL|TT|TV|TW|TZ|UA|UG|UK|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|XN--0ZWM56D|XN--11B5BS3A9AJ6G|XN--3E0B707E|XN--45BRJ9C|XN--80AKHBYKNJ4F|XN--9T4B11YI5A|XN--CLCHC0EA0B2G2A9GCD|XN--DEBA0AD|XN--FIQS8S|XN--FIQZ9S|XN--F
/*
Example that utilizes FileSystem API and Web Workers.
Creates a lib.js and worker.js in a temporary file system, then creates a web worker for worker.js that imports lib.js from the local filesystem.
The start of something beautiful?
*/
var fs, liburl, worker = null;
import subprocess
from StringIO import StringIO
class XmpFile(object):
def __init__(self, path, flags, *mode):
# Store the path as an instance property for later
self.path = "." + path
self.file = os.fdopen(open(self.path, flags, *mode),
flag2mode(flags))