Skip to content

Instantly share code, notes, and snippets.

View abyx's full-sized avatar

Aviv Ben-Yosef abyx

View GitHub Profile
# Happily turned this ugly thing:
class Foo(object):
pass
class Bar(object):
pass
class User(object):
def collect(objects):
foos = [x for x in objects if isinstance(x, Foo)]
from buildbot.process.properties import WithProperties
from buildbot.steps.shell import ShellCommand
from buildbot.interface import LOG_CHANNEL_STDERR as STDERR
class Nose(ShellCommand):
def __init__(self):
self.coverage_path = '/var/www/foo/coverage-%s'
self.coverage_url = 'http://example.com/foo/coverage-%s'
d = WithProperties('--cover-html-dir=' + self.coverage_path,
'buildnumber')
class VerboseCommand(ShellCommand):
def __init__(self, command=None):
ShellCommand.__init__(self, command=command + ['-v'])
class VerboseCommand(ShellCommand):
def __init__(self, command=None, is_factory_call=True):
ShellCommand.__init__(self, command=command)
if is_factory_call:
self.addFactoryArguments(is_factory_call=False)
else:
self.command = self.command + ['-v']
@abyx
abyx / selfish.py
Created May 11, 2010 21:55
never use 'self.' in methods again
def selfish(f):
def wrapper(self, *args, **kwargs):
f.func_globals.update(dict((x, getattr(self, x)) for x in dir(self)))
return f(self, *args, **kwargs)
return wrapper
class Test(object):
def foo(self):
print "foo!"
@selfish
@abyx
abyx / before refactoring
Created June 2, 2010 19:11
before refactoring
class VCR:
function eject:
_rewind
_open_lid
class VCRTest:
function test_rewinds_when_ejecting:
# stuff
function test_opens_lid_to_eject:
@abyx
abyx / mid refactoring
Created June 2, 2010 19:28
mid refactoring
class VCR:
function eject(should_rewind=True):
if should_rewind:
rewind
_open_lid
class VCRTest:
function test_rewinds_when_ejecting:
# stuff
function test_opens_lid_to_eject:
@abyx
abyx / post refatoring
Created June 2, 2010 19:34
post refactoring
class VCR:
function eject:
_open_lid
function rewind:
# stuff
class VCRTest:
function test_opens_lid_to_eject:
# stuff
function test_rewind_actually_spins_tape:
@abyx
abyx / SessionConverter.java
Created August 27, 2010 16:58
Logback converters for username and sessions
public class SessionConverter extends ClassicConverter {
@Override
public String convert(ILoggingEvent event) {
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
if (attrs != null) {
return attrs.getSessionId();
}
return "NO_SESSION";
}
}