Mercurial > hg > config
changeset 109:e83b7dd50461
merge commit
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 29 Nov 2010 08:34:29 -0800 |
parents | e7948549afa1 (diff) 6463a7e37c45 (current diff) |
children | bf567a0e8fef |
files | |
diffstat | 3 files changed, 80 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.fluxbox/keys Fri Nov 26 11:30:47 2010 -0800 +++ b/.fluxbox/keys Mon Nov 29 08:34:29 2010 -0800 @@ -59,7 +59,7 @@ Control Mod1 l :ExecCommand echo http://letmegooglethatforyou.com/?q=$(xclip -o) | xclip -i Control Mod1 m :ExecCommand xterm -e alsamixer # mixer Control Mod1 o :ExecCommand xclip -o | /home/jhammel/python/onelineit.py | xclip -i # put the clipboard contents on one line -Control Mod1 p :ExecCommand xclip -o | /home/jhammel/python/pastebin.py | xclip -i # send the clipboard contents to pastebin and replace with the URL +Control Mod1 p :ExecCommand xclip -o | /home/jhammel/python/pastebin.py | xclip -i Control Mod1 q :ExecCommand xclip -o | sed 's/^/> /' | xclip -i # quote using >'s Control Mod1 s :ExecCommand /home/jhammel/bin/smartopen "$(xclip -o)" # smartopen Control Mod1 t :ExecCommand gnome-terminal # terminal
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/cli.py Mon Nov 29 08:34:29 2010 -0800 @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +program illustrating command line in the form of +``--option foo`` or ``--option=foo`` goes to a (key,value) paid +and ``-tag`` gets appended to a list. Further options go to a further list:: + + >>> main(['-foo', '--bar=fleem', 'baz']) + (['foo'], {'bar': 'fleem'}, ['baz']) +""" + +import sys + +class ParserError(Exception): + """error for exceptions while parsing the command line""" + +def main(_args=sys.argv[1:]): + + # return values + _dict = {} + tags = [] + args = [] + + # parse the arguments + key = None + for arg in _args: + if arg.startswith('---'): + raise ParserError("arguments should start with '-' or '--' only") + elif arg.startswith('--'): + if key: + raise ParserError("Key %s still open" % key) + key = arg[2:] + if '=' in key: + key, value = key.split('=', 1) + _dict[key] = value + key = None + continue + elif arg.startswith('-'): + if key: + raise ParserError("Key %s still open" % key) + tags.append(arg[1:]) + continue + else: + if key: + _dict[key] = arg + continue + args.append(arg) + + # return values + return (_dict, tags, args) + +if __name__ == '__main__': + try: + _dict, tags, args = main() + except ParserError, e: + import pdb; pdb.set_trace() # for debugging + print _dict + print tags + print args
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/urlhash.py Mon Nov 29 08:34:29 2010 -0800 @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +""" +return a random URL hash +""" + +import random +import urllib + +chars = [ chr(i) for i in range(0,255) ] +allowed = [ urllib.quote_plus(i) for i in chars + if urllib.quote_plus(i) in chars ] + +def urlhash(len=10): + chars = random.sample(allowed, len) + string = ''.join(chars) + return urllib.quote_plus(string) + +if __name__ == '__main__': + print urlhash()