Skip to content

Instantly share code, notes, and snippets.

@bobhancockgist
bobhancockgist / gist:5725397
Created June 6, 2013 22:08
Get log handle for log that rotates on size.
import logging
def setup_log_size_rotating(log_filename,
logname='defaultlog',
max_size_in_bytes=(1024 * 1000000),
debug=False,
backups = 32):
""" The file will rollover when it approaches maxBytes.
Our default size is 1MB
"""
"""
Injection of optimzation data into Packrat via the REST API.
https://corpwiki.appnexus.com/display/adserver/Packrat
"""
__author__ = "Bob Hancock (rhancock@appnexus.com)"
if __name__ == "__main__":
main()
@bobhancockgist
bobhancockgist / docstringfunction.sublime-snippet
Created April 30, 2013 20:33
Python: Docstring function
<snippet>
<content><![CDATA[
def $1($2):
""" ${3:Description}
Args:
${2/, ?/:\n\t/g}:
Returns:
$4
@bobhancockgist
bobhancockgist / docstringclass.sublime-snippet
Created April 30, 2013 20:33
Python: Docstring class
<snippet>
<content><![CDATA[
Class $1(object):
""" ${2:A comprehensible explanation of the purpose of the class
that a non-programmer can understand along with advice on sub-classing.""}
Attributes:
${3/, ?/:\n\t/g}:
"""
def __init__(self, $3):
<snippet>
<content><![CDATA[
"""
${1:Description of why the classes and functions in this file are bundled together.}
"""
__author__ = "$2"
]]></content>
@bobhancockgist
bobhancockgist / docstringmodule.sublime-snippet
Created April 30, 2013 20:32
Python: Docstring module
<snippet>
<content><![CDATA[
"""
Module: $1
Description: $2
Minimum Python Required: $3
Changelog:
@bobhancockgist
bobhancockgist / gist:5490527
Created April 30, 2013 17:55
Pythons: all files in a tree
import os
# Assign your top level directory to home
home = "/Users/rhancock"
for dirpath, dirs, files in os.walk(home, topdown=True):
for dr in dirs:
fullpath_d = os.path.join(dirpath, dr)
for fname in os.listdir(fullpath_d):
@bobhancockgist
bobhancockgist / gist:5374660
Created April 12, 2013 19:55
Python: files in dir
import os
import sys
def main():
if len(sys.argv) < 2:
sys.stderr.write("usage: scriptname source_dir")
sys.exit(1)
source_dir = sys.argv[1]
try:
@bobhancockgist
bobhancockgist / gist:5286561
Created April 1, 2013 18:05
Python: Current procedure name
<snippet>
<content><![CDATA[
myname = inspect.currentframe().f_code.co_name
]]></content>
<tabTrigger>curprocname</tabTrigger>
<scope>source.python</scope>
<description>Name of current procedure</description>
</snippet>
@bobhancockgist
bobhancockgist / SublimeBlockCursor.py
Created March 24, 2013 17:49 — forked from kellishaver/SublimeBlockCursor.py
Pythons: SublimeBlockCursor
import sublime
import sublime_plugin
class SublimeBlockCursor(sublime_plugin.EventListener):
def view_is_widget(view):
settings = view.settings()
return bool(settings.get('is_widget'))
def show_block_cursor(self, view):
validRegions = []