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
#!/bin/sh | |
set -e | |
touch /tmp/linked | |
ln -s /tmp/linked . || true | |
cat <<EOF > Dockerfile | |
FROM busybox:ubuntu-14.04 | |
ADD . /data |
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
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"and": [ | |
{ | |
"term": { | |
"deleted": false | |
} | |
}, |
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
(function() { | |
// Inspired by http://informationandvisualization.de/blog/box-plot | |
d3.box = function() { | |
var width = 1, | |
height = 1, | |
duration = 0, | |
domain = null, | |
value = Number; | |
showLabels = true, // whether or not to show text labels |
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
import functools | |
class memoize_method: | |
""" | |
A decorator to memoize a method. The cache is stored as a dictionary | |
inside the object. | |
This functionality is similar to stdlib's :func:`functools.lru_cache`. | |
When using lru_cache on a method, the object will be used as part of the |