This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
''' | |
Super dumb example of getting the contents of a web page. | |
''' | |
import urllib2 | |
page_contents = urllib2.urlopen('http://www.python.org/').read() | |
print page_contents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
''' | |
This is more of a personal reference as I use json very often. | |
The httplib2 examples are VERY good, and you should refer to them: | |
http://code.google.com/p/httplib2/wiki/Examples | |
''' | |
from httplib2 import Http | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from simplejson import JSONEncoder | |
class ObjectDictWorks(dict): | |
""" Makes a dictionary behave like an object. """ | |
def __getattr__(self, name): | |
try: | |
return self[name] | |
except KeyError: | |
raise AttributeError(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Pass a time in seconds, and a base directory. | |
I will nuke anything older than now - seconds in that directory. Optionally | |
recursively | |
''' | |
from datetime import datetime | |
import os | |
from optparse import OptionParser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from optparse import OptionParser | |
import sys | |
def example_function(): | |
print "Hello world!" | |
if __name__ == "__main__": | |
parser = OptionParser() | |
parser.add_option( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char stats_sock_usage_msg[] = | |
"Unknown command. Please enter one of the following commands only :\n" | |
" clear counters : clear max statistics counters (add 'all' for all counters)\n" | |
" help : this message\n" | |
" prompt : toggle interactive mode with prompt\n" | |
" quit : disconnect\n" | |
" show info : report information about the running process\n" | |
" show stat : report counters for each proxy and server\n" | |
" show errors : report last request and response errors for each proxy\n" | |
" show sess [id] : report the list of current sessions or dump this session\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Stupid gist by warren runk | |
import os | |
if __name__ == "__main__": | |
full_file_path = os.path.realpath(__file__) | |
print 'Full path to this current file is', full_file_path | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env/python | |
# | |
# More of a reference of using jinaj2 without actual template files. | |
# This is great for a simple output transformation to standard out. | |
# | |
# Of course you will need to "sudo pip install jinja2" first! | |
# | |
# I like to refer to the following to remember how to use jinja2 :) | |
# http://jinja.pocoo.org/docs/templates/ | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------------- # | |
# Standard setup stuff. In general you will want to alter the formatters | |
# | |
[formatters] | |
keys: detailed,simple | |
[handlers] | |
keys: console | |
[formatter_simple] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# The above line will cause this script to be run using the program 'python' | |
# Lines that start with a hash are comments for fun | |
# The interpreter wont read these. | |
def print_function(): | |
print ''' | |
******* * * | |
* * * |