Public snipts »
TomL's
snipts
showing 1-3 of 3 snipts
-
∞ Paste to paste2.org
""" Posts a file to paste2.org. Can post multiple files at once. paste2.py [options] [files] -h, --help : Print this help -l, --lang : Specify the language for the paste -p, --parent : Sprecify parent paste """ import urllib import urllib2 import sys import getopt DEFAULT_LANG = 'python' PASTE2_URL = 'http://paste2.org/new-paste' def post_to_paste2(code, lang=DEFAULT_LANG, parent=0): """ Post to paste2, return url of new paste """ url = PASTE2_URL values = { 'lang': lang, 'description': '', 'code': code, 'parent': 0, } data = urllib.urlencode(values) req = urllib2.Request(url, data) paste_url = urllib2.urlopen(req).geturl() return paste_url def usage(): print "paste2.py [options] [files]" print " -h, --help : Print this help" print " -l, --lang : Specify the language for the paste" print " -p, --parent : Sprecify parent paste" def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "hl:p:v", ["help", "lang=", "parent="]) except getopt.GetoptError, err: # print help information and exit: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) lang = DEFAULT_LANG parent = None for o, a in opts: if o in ("-l", "--lang"): language = a elif o in ("-p", "--parent"): parent = a elif o in ("-h", "--help"): usage() sys.exit() else: assert False, "unhandled option" #loop through all files passed for file_name in args: file = open(file_name, 'r') paste_url = post_to_paste2(file.read(), lang=lang, parent=parent) print "%s -> %s" % (file_name, paste_url) if __name__ == "__main__": main()
-
∞ Revoke all mysql priveleges
REVOKE ALL PRIVILEGES, GRANT OPTION ON *.* FROM jimmy@localhost; REVOKE ALL PRIVILEGES, GRANT OPTION ON *.* FROM jimmy@localhost.localdomain; FLUSH PRIVILEGES;
-
∞ Validate email address (based on example from django source)
import re if re.match(r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"'r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', email_address, re.IGNORECASE): print "valid email" else: print "invalid email"



Programming PHP