Skip to content

Instantly share code, notes, and snippets.

Avatar

Aviv Ben-Yosef abyx

View GitHub Profile
View visitor_goodness.py
# 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)]
View buildbot_nose_coverage.py
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')
View buildbot_wrong_verbose.py
class VerboseCommand(ShellCommand):
def __init__(self, command=None):
ShellCommand.__init__(self, command=command + ['-v'])
View buildbot_right_verbose.py
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
never use 'self.' in methods again
View selfish.py
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 Jun 2, 2010
before refactoring
View before refactoring
class VCR:
function eject:
_rewind
_open_lid
class VCRTest:
function test_rewinds_when_ejecting:
# stuff
function test_opens_lid_to_eject:
View 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 Jun 2, 2010
post refactoring
View post refatoring
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 Aug 27, 2010
Logback converters for username and sessions
View SessionConverter.java
public class SessionConverter extends ClassicConverter {
@Override
public String convert(ILoggingEvent event) {
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
if (attrs != null) {
return attrs.getSessionId();
}
return "NO_SESSION";
}
}