Skip to content

Instantly share code, notes, and snippets.

View gregglind's full-sized avatar

Gregg Lind gregglind

View GitHub Profile
@gregglind
gregglind / gist:940863
Created April 25, 2011 17:34
centralized logging
"""use get_logger:
from this_logging import get_logger; logger = get_logger(__name__)
# then you can:
logger.debug("foo")
# and if you want to change the logging level:
import logging
logger.parent.setLevel(logging.DEBUG)
"""
from os.path import dirname, join, exists
import logging
@gregglind
gregglind / gist:970871
Created May 13, 2011 16:51
some broken threadpool stuff
from paste.httpserver import ThreadPool
pool = ThreadPool(5)
import random
import time
def do_work(t):
print 'about to sleep for %s sec' % (t,)
time.sleep(t)
print 'slept for %s' %(t)
@gregglind
gregglind / flaskboil.sh
Created August 15, 2011 13:42
A 'Boilerplate' for Flask Application Layouts
#!/bin/bash
# tested on osx, mostly
# tested on ubuntu
#
# to use: /bin/bash -xc "$( curl -fsSL 'https://raw.github.com/gist/1146774' )"
#
#
set -o errexit
class RoleHostsGenerator(object):
""" generator for the env.hosts dictionary"""
def __init__(self,hostfile=HOSTS_FILE):
self.hostfile=HOSTS_FILE
def __getitem__(self,key):
print self.hostfile
print key
l = list(_gethosts(key,open(self.hostfile)))
print l
class RoleHostsGenerator(object):
""" generator for the env.hosts dictionary"""
def __init__(self,hostfile=HOSTS_FILE):
self.hostfile=HOSTS_FILE
def __getitem__(self,key):
print self.hostfile
print key
l = list(_gethosts(key,open(self.hostfile)))
print l
@gregglind
gregglind / fabfile.py
Created August 29, 2011 18:37
'ignore_abort' for twiedenbein
"""
$ fab -f blah.py -H web03 somefun
[web03] Executing task 'somefun'
[web03] sudo: uname -a
Fatal error: Name lookup failed for web03
Aborting.
would have aborted, but env.ignore_abort 1
@gregglind
gregglind / fabfile.py
Created September 9, 2011 16:59
Fabfile for PyMNtos September 2011 Meeting
#!/usr/bin/env python
"""
Example fabfile for PyMNtos September 2011 meeting.
some examples of usage:
$ fab -H somehost -- uname -a
$ fab -H somehost run:'uname -a'
$ fab -d example
@gregglind
gregglind / meetings.rst
Created October 4, 2011 21:01
Guidelines for Efficient Moderated Meetings

Guidelines for Efficient Moderated Meetings

Purpose

  • have short, efficient meetings that honor the contributions of all members

  • prevent many failure modes that derail meetings, including:

    • going too long
@gregglind
gregglind / each_one.py
Created October 16, 2011 22:11
new iterators in python and ruby
# from discussion of bring the block to the iterator at
# http://mettadore.com/ruby/ruby-blocks-seeking-closure/
## Ruby Version
'''
class Kids < Array
def each_one
self.each_with_index do |n, i|
yield(n)
@gregglind
gregglind / dataframe_list_of_dicts.py
Created December 22, 2011 19:45
Proposed handling for 'list of dicts' in pandas.DataFrame
"""
Sketch of proposed behaviour... make 'list of dicts'
create a (potentially) 'ragged' array, with autoguessed column names,
and sensible default values, where the keys don't match.
Current behaviour
In [215]: pandas.DataFrame([dict(a=1),dict(a=2)],columns=['a'])
Out[215]:
a