Skip to content

Instantly share code, notes, and snippets.

View almet's full-sized avatar
🗺️

Alexis Métaireau almet

🗺️
View GitHub Profile
@almet
almet / nginxextract.py
Created August 19, 2011 01:02
Experimentations about nginx stats in python
from collections import namedtuple
from datetime import datetime
from itertools import groupby
from operator import attrgetter
import re
import sys
import pylab as pl
Log = namedtuple("Log", ("url", "date", "ip", "code", "verb"))
from collections import namedtuple
from datetime import datetime
from itertools import groupby
from operator import attrgetter
import re
import sys
import pylab as pl
Log = namedtuple("Log", ("url", "date", "ip", "status", "verb"))
>>> from Crypto import Hash
>>> Hash.MD5
Traceback (most recent call last):
File "<ipython-input-3-cffbba359383>", line 1, in <module>
Hash.MD5
AttributeError: 'module' object has no attribute 'MD5'
>>> from Crypto.Hash import MD5
>>> MD5
<module 'Crypto.Hash.MD5' from '/home/alexis/dev/python/venv/crypto/local/lib/python2.7/site-packages/Crypto/Hash/MD5.pyc'>
@almet
almet / test.py
Created March 28, 2012 13:47
Python methods and functools
# This doesn't work (self isn't passed when calling obj.bar or obj.baz
class MyClass(object):
def foo(self, foo=None):
# do something with foo
bar = functools.partial(foo="bar")
baz = functools.partial(foo="baz")
# This works
class Assertions(object):
"""Custom class to deal with assertions. it provides some hight level
methods that you can call to get valid or invalid assertions.
If many assertions are contained, then it will loop on them.
"""
def __init__(self, assertions):
self._assertions = assertions
try:
cache['foo']
except KeyError:
pass
else:
self.assertTrue(False, "KeyError hadn't been thrown")
import time
import sys
from tokenserver.tests.support import (MockCryptoWorker, PurePythonRunner,
sign_data)
def timed(msg):
def _timed(func):
def __timed(*args, **kw):
sys.stdout.write(msg + '...')
[powerhose]
backend = tokenserver.crypto.master.PowerHoseRunner
endpoint = ipc:///tmp/powerhose-front.ipc
pint(self.conf_get('main', 'vusers'))
@almet
almet / gist:2402333
Created April 16, 2012 23:36
tilemill error
./index.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module './_mapnik.node'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)