Skip to content

Instantly share code, notes, and snippets.

View kisielk's full-sized avatar
🔈

Kamil Kisiel kisielk

🔈
View GitHub Profile
numEndPoints := (higher.End() - higherFirstOffset) / pointSize
numBeginPoints := (higherLastOffset - higher.Offset) / pointSize
points = make([]Point, numBeginPoints+numEndPoints)
@kisielk
kisielk / gist:2833995
Created May 30, 2012 05:54
Example request from raven-go
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"}
@kisielk
kisielk / gist:2778374
Created May 23, 2012 23:00
Function for returning a URL to access an error sent to sentry via raven
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()
@kisielk
kisielk / omg.py
Created May 8, 2012 18:30
Python scoping rules can sometimes result in code working purely by accident.
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():
@kisielk
kisielk / https_test.py
Created September 18, 2011 01:32
Testing SSL functionality in tornado
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([
@kisielk
kisielk / sigabrt.py
Created June 27, 2011 17:24
Trying to catch SIGABRT
import signal, os
def handler(signum, frame):
print "Signal!"
raise Exception()
signal.signal(signal.SIGABRT, handler)
os.abort()
@kisielk
kisielk / node_hvmem.py
Created June 8, 2011 20:34
Sets the h_vmem complex value on hosts in gridengine based on mem_free
#!/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
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]
@kisielk
kisielk / hamming.hs
Created March 15, 2011 07:10
Our candidate programming problem, implemented in Haskell
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)
@kisielk
kisielk / coulomb.hs
Created March 12, 2011 20:33
The beginnings...
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