Skip to content

Instantly share code, notes, and snippets.

View amcgregor's full-sized avatar
🏢
I died! …well, I got better…

Alice Zoë Bevan–McGregor amcgregor

🏢
I died! …well, I got better…
View GitHub Profile
@amcgregor
amcgregor / mock-http-server.py
Created November 29, 2010 12:15
A simple mock HTTP server useful for HTTP client testing.
#!/usr/bin/env python
# encoding: utf-8
from __future__ import unicode_literals
import logging
from functools import partial
from marrow.script import execute
@amcgregor
amcgregor / master.py
Created December 4, 2010 18:36
Master / theme template, included by inner page templates.
# encoding: utf-8
from __future__ import unicode_literals
from alacarte.template.simplithe.html5 import *
__all__ = ['theme']
@amcgregor
amcgregor / trivial-async-example.py
Created December 14, 2010 08:48
A trivial example of a chunked response.
#!/usr/bin/env python
# encoding: utf-8
import logging
from marrow.server.http import HTTPServer
def hello(request):
def transcode_video(request):
# p-code ahoy!
@amcgregor
amcgregor / application.yaml
Created December 14, 2010 09:50
marrow.configuration example multi-part configuration.
extensions:
- [!!python marrow.mail:DeliveryExtension, *mail]
- !!python marrow.mail.logger:LoggerExtension
mail: &mail
server: localhost
user: user
password: xyzzy
administrator: [email protected]
@amcgregor
amcgregor / conversion-benchmark.py
Created December 25, 2010 13:14
A comparison of two methods to canonicalize (to byte strings) a list of 2-tuples containing byte strings and unicode strings.
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
"""Compare two algorithms that canonicalize a list of tuples.
Python 2.7.0:
Good headers:
List creation and iteration: 2.98474693298
@amcgregor
amcgregor / async-wsgi-1.py
Created January 8, 2011 10:40
Some example p-code illustrating an async application, how middleware handles this, and the inner part of a server reactor loop.
# This is the initial idea based on a callback-based async framework.
# This assumes yield syntax is mandatory; applications and middleware
# must be generators.
# This idea should be usable as-is and a fork of m.s.http should be
# utilized to explore the concept within the context of a real server.
# Combine futures with the dubious (and much-argued) yield reactor
# syntax. Yield allows the application to return to the reactor in such
# a way as to be able to be resumed.
@amcgregor
amcgregor / non-threaded.txt
Created January 8, 2011 14:48
Comparison between non-threaded and threaded execution of marrow.server.http. Note the "interrupted system call" logged exception; need to look into that.
INFO:marrow.server.base:Starting up.
INFO:marrow.server.base:Server running with PID 8639, serving on 127.0.0.1:8888.
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
@amcgregor
amcgregor / 1-absolute-minimal.py
Created January 9, 2011 03:38
Examples of minimal PEP 444 / WSGI 2 async-capable middleware, helpers, etc.
def null_middleware(app):
def middleware(environ):
generator = app(environ)
result = None
while True:
result = generator.send(result)
try: result = (yield result)
except: generator.throw(*sys.exc_info())
@amcgregor
amcgregor / dynamic-lookup.py
Created January 15, 2011 08:00
An example of dynamic dispatch.
class User(Controller):
def __init__(self, id):
self.id = id
def index(self):
return 'mypkg.views.user', dict(id=self.id)
def method(self):
return 'mypkg.views.method', dict(id=self.id)
@amcgregor
amcgregor / caching-proxy.py
Created January 21, 2011 03:21
A transparent caching proxy server built using WSGI.
#!/usr/bin/env python
"""A transparent caching proxy.
To use, simply create a directory and run this script a la:
./caching-proxy.py cache
Then point your browser's HTTP proxy at localhost:8888.