# HG changeset patch # User Jeff Hammel # Date 1291048469 28800 # Node ID e83b7dd50461c668cd85f46c6de4b7b96046ee69 # Parent e7948549afa125992f17fdd2136bfdbb515274b5# Parent 6463a7e37c45de22829c70922cd3868cb4afaf4a merge commit diff -r 6463a7e37c45 -r e83b7dd50461 .fluxbox/keys --- 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 diff -r 6463a7e37c45 -r e83b7dd50461 python/cli.py --- /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 diff -r 6463a7e37c45 -r e83b7dd50461 python/urlhash.py --- /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()