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
numEndPoints := (higher.End() - higherFirstOffset) / pointSize | |
numBeginPoints := (higherLastOffset - higher.Offset) / pointSize | |
points = make([]Point, numBeginPoints+numEndPoints) |
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
POST /api/store HTTP/1.1 | |
Host: localhost:1234 | |
User-Agent: Go http package | |
Content-Length: 158 | |
X-Sentry-Auth: Sentry sentry_version=2.0, sentry_client=raven-go/0.1, sentry_timestamp=1338356142, sentry_key=475bdfd79add40ee97cedf2aec17a3a2 | |
Accept-Encoding: gzip | |
{"event_id":"db36eeac40060548806454c4cfbab6e5","project":"default","message":"Hello world","timestamp":"2012-05-30T05:35:42","level":"error","logger":"root"} |
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
def error_url(dsn, error_id): | |
import urlparse | |
search_base = urlparse.urlsplit(dsn) | |
search_url = search_base._replace(netloc=search_base.netloc.split('@')[1], | |
query='q={0}'.format(error_id), | |
path=search_base.path + '/search') | |
return search_url.geturl() |
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
def omg(): | |
def inner(foo): | |
# Works fine, purely by accident... | |
return f | |
# ...because the list comprehension leaks its variable in to the outer scope | |
return [inner(f) for f in range(5)] | |
def broken(): |
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 tornado.web | |
import tornado.httpserver | |
import tornado.ioloop | |
class DefaultHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Nothing to see here\n") | |
if __name__ == "__main__": | |
app = tornado.web.Application([ |
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 signal, os | |
def handler(signum, frame): | |
print "Signal!" | |
raise Exception() | |
signal.signal(signal.SIGABRT, handler) | |
os.abort() |
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
#!/usr/bin/env python | |
"""Script to set node h_vmem resource to be equal to the node's actual physical | |
memory. | |
Usage: | |
qhost -xml | ./node_hvmem.py | |
""" | |
import sys | |
import shlex |
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 string import Formatter | |
class PartialFormatter(Formatter): | |
def format(self, format_string, *args, **kwargs): | |
self.fields = kwargs.keys() | |
def parse(self, format_string): | |
for parsed in super(PartialFormatter, self).parse(format_string): | |
if parsed[1] and parsed[1] not in self.fields: | |
literal_text = parsed[0] + "{" + parsed[1] |
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 Data.List | |
normalizedScore :: String -> String -> Float | |
normalizedScore a b = fromIntegral (numSimilar a b) / fromIntegral (length a) | |
numSimilar :: String -> String -> Int | |
numSimilar a b = sum $ map fromEnum $ zipWith (==) a b | |
slice :: Int -> Int -> [a] -> [a] | |
slice from to xs = take (to - from + 1) (drop from xs) |
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
type Charge = Double | |
type Distance = Double | |
type Force = Double | |
type Coord = Double | |
type Mass = Double | |
data Element = H | O | C deriving (Eq, Show, Read) | |
data Position = Position { xPos :: Coord | |
, yPos :: Coord |