Skip to content

Instantly share code, notes, and snippets.

View schmichael's full-sized avatar

Michael Schurter schmichael

View GitHub Profile
@schmichael
schmichael / memorymap.py
Created September 6, 2011 05:44
WIP Convenience wrapper around Python's mmap.mmap class
"""Public domain"""
import mmap
import os
PAGESIZE = mmap.PAGESIZE
def fileno_to_filename(fd):
"""Attempt to resolve fd to a filename or return None"""
@schmichael
schmichael / example.py
Created September 13, 2011 19:17
mmstats example
import os
import mmstats
import libgettid
class MyStats(mmstats.BaseMmStats):
pid = mmstats.StaticUIntField(label="sys.pid", value=os.getpid)
tid = mmstats.StaticInt64Field(label="sys.tid", value=libgettid.gettid)
uid = mmstats.StaticUInt64Field(label="sys.uid", value=os.getuid)
gid = mmstats.StaticUInt64Field(label="sys.gid", value=os.getgid)
errors = mmstats.UIntStat(label="com.urbanairship.app.errors")
@schmichael
schmichael / gist:1215033
Created September 13, 2011 20:21
slurpstats
$ python slurpstats.py . | sort -r
==> /tmp/mmstats-test-mystats
sys.uid 1000
sys.tid 6273
sys.pid 6273
sys.gid 1000
com.urbanairship.app.warnings 0
com.urbanairship.app.queries 0
com.urbanairship.app.errors 1
com.urbanairship.app.degraded True
from collections import namedtuple
def read_shifty_csv(f):
cols = None
for line in f:
line = line.strip()
if line.startswith('#'):
cols = namedtuple('cols', line[1:].split(','))
else:
yield cols(*line.split(','))
@schmichael
schmichael / runningavg.py
Created October 20, 2011 00:41
Handy script for calculating averages streamed via stdin
#!/usr/bin/env python
import sys
CHUNK = 100
if len(sys.argv) > 1:
CHUNK = int(sys.argv[1])
vals = []
i = 1
Host *
Protocol 2
GSSAPIAuthentication no
01:02 -!- jamwt [~jamwt@c-98-248-33-0.hsd1.ca.comcast.net] has quit [Quit: Computer has gone to sleep.]
09:11 < schmichael> you guys use 0mq?
09:12 < schmichael> i toyed with it for a bit, but just didn't feel comfortable with some of the high water mark buffering behavior
09:12 < schmichael> but i may not have been using the right socket types or just using 0mq for an inappropriate use case
09:14 < schmichael> ooh http-parser, nice
09:16 < schmichael> doh, no jamwt
import itertools
import sys
import mmstats
import mmstats.reader
class FastStats(mmstats.BaseMmStats):
a = mmstats.UInt64Field()
.PHONY: compile palm
PALMC = bin/palmc
PIP = bin/pip
compile:
mvn clean compile
$(PIP):
# This is one way to install pip :|
schmichael@git:master:~/src/mmstats$ python setup.py bdist_rpm --help
Common commands: (see '--help-commands' for more)
setup.py build will build the package underneath 'build/'
setup.py install will install the package
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything