Skip to content

Instantly share code, notes, and snippets.

@jimr
jimr / count_the_hours.py
Created December 6, 2013 11:38
Tally up records from httpd access logs by hour of day. Usage: python count_the_hours.py /path/to/access.log.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import re
import sys
from datetime import datetime as dt
pattern = re.compile(r'.* \[([^]]*) \+[0-9]+\] .*')

Keybase proof

I hereby claim:

  • I am jimr on github.
  • I am jimr (https://keybase.io/jimr) on keybase.
  • I have a public key whose fingerprint is 788D 1F2D A813 72EA 42A5 350A C19F 559A 4045 40D7

To claim this, I am signing this object:

@jimr
jimr / fake_request.py
Last active July 4, 2022 09:40
Generate fake WSGIRequest objects for use in Django views
def fake_request(method=None, fake_user=False):
'''Returns a fake `WSGIRequest` object that can be passed to viewss.
If `fake_user` is `True`, we attach a random staff member to the request.
Even if not set, you can still do this manually by setting the `user`
attribute on the returned object.
The `GET` and `POST` `QueryDict` objects are mutable::
req = fake_request(mutable=True)