Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am dcrosta on github.
  • I am dcrosta (https://keybase.io/dcrosta) on keybase.
  • I have a public key ASAQuXx8EHZPizgcpBHawcB0kva5JXCAN-74HvWotp4aJgo

To claim this, I am signing this object:

>>> api.host_tags('my.hostname.com')
['role:base', 'env:prod', 'role:bidder']
>>> api.host_tags('my.hostname.com')
['role:base', 'env:prod']
>>> api.host_tags('my.hostname.com')
['role:base', 'env:prod', 'role:bidder']
>>> api.host_tags('my.hostname.com')
['region:us-east-1', 'role:hdat', 'role:base', 'availability-zone:us-east-1c', 'image:ami-1624987f', 'security-group:sg-a89e60c1', 'instance-type:m1.xlarge', 'name:[redacted]', 'kernel:aki-88aa75e1', 'env:qa', 'security-group:sg-71968219']
>>> api.host_tags('my.hostname.com')
['role:base', 'env:prod', 'role:bidder']
init_config:
instances:
- host: localhost
port: 10101
name: master
conf:
- include:
domain: hadoop
bean: hadoop:name=MasterStatistics,service=Master
init_config:
instances:
- host: localhost
port: 10101
name: regionserver
conf:
- include:
domain: hadoop
bean: name=RegionServerStatistics,service=RegionServer
-----> Heroku receiving push
-----> Python app detected
-----> Preparing Python interpreter (2.7.2)
-----> Creating Virtualenv version 1.7.2
New python executable in .heroku/venv/bin/python2.7
Not overwriting existing python script .heroku/venv/bin/python (you must use .heroku/venv/bin/python2.7)
Installing distribute..................................................................................................................................................................................................done.
Installing pip................done.
Overwriting .heroku/venv/bin/activate with new content
Overwriting .heroku/venv/bin/activate.fish with new content
@dcrosta
dcrosta / fakemodule.py
Created August 4, 2012 03:14
Use a Python class as a fake module
import sys
class TheModule(object):
def __getattr__(self, name):
# you can do whatever you want with `name` here
print (self, name)
sys.modules[__name__] = TheModule()
@dcrosta
dcrosta / gist:2562350
Created April 30, 2012 20:17
A Python Mystery
Guess the output:
>>> def exec_code_object_and_return_x(codeobj, x):
... exec codeobj
... return x
...
>>> co1 = compile("""x = x + 1""", '<string>', 'exec')
>>> co2 = compile("""del x""", '<string>', 'exec')
>>> exec_code_object_and_return_x(co1, 1)
# What do you get here?
@dcrosta
dcrosta / puny.py
Created March 8, 2012 17:50
declarative, readable python testing
from functools import wraps
class Equalizer(object):
def __init__(self, rv):
self._rv = rv
def __eq__(self, other):
assert self._rv == other
class Puny(object):
@dcrosta
dcrosta / gist:1578946
Created January 8, 2012 16:47
multiple-file context manager
class openFiles(object):
def __init__(self, *args):
if not all(isinstance(arg, tuple) for arg in args):
raise TypeError('arguments to openFiles must all be 2-tuples')
if not all(len(arg) in (1, 2) for arg in args):
raise TypeError('arguments to openFiles must all be 2-tuples')
self.args = args
def __enter__(self):
self.fhs = [file(*arg) for arg in self.args]
>>> def adder(amt):
... def inner(start):
... return start + amt
... return inner
...
>>> plusone = adder(1)
>>> plusone(4)
5