This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(object): | |
def setter(var): | |
def set(self, value): | |
setattr(self, var, value+' unicorn') | |
return set | |
def getter(var): | |
def get(self): | |
return getattr(self, var)+' sasquatch' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> [ range(x*5, x*5+5) for x in range(5) ] | |
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Taken from http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html | |
def pdf(x): | |
"""Normal probably distribution function.""" | |
return exp(-x**2/2)/sqrt(2*pi) | |
#Taken from http://stackoverflow.com/a/809402/600247 | |
def erfcc(x): | |
"""Complementary error function.""" | |
z = abs(x) | |
t = 1. / (1. + 0.5*z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sqlalchemy.create_engine(settings['db_url'], pool_recycle=14400) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@reify | |
def db(self): | |
def cleanup(self): | |
self.db.close() | |
self.add_finished_callback(cleanup) | |
return self.registry.settings['sessionmaker']() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Table(Base): | |
id = Column(Integer, primary_key=True) | |
_name = Column('name', String(24)) | |
@property | |
def name(self): | |
return self._name; | |
@name.setter | |
def name(self, value): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array = [1, 2, 3, 4] | |
array.collect! do |n| | |
n ** 2 | |
end | |
puts array.inspect # => [1, 4, 9, 16] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.python.failure import Failure | |
from autobahn.wamp import WampServerProtocol | |
class WampException(Exception): | |
"""A base class for an application exception. Can be subclass and | |
define a unique msg.""" | |
msg = None | |
def __init__(self, *args): | |
if len(args) == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request.response.set_cookie('my_cookie', None) | |
# OR | |
request.response.unset_cookie('my_cookie') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: haproxy | |
# Required-Start: $local_fs $network $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: fast and reliable load balancing reverse proxy | |
# Description: This file should be used to start and stop haproxy. | |
### END INIT INFO |
OlderNewer