Skip to content

Instantly share code, notes, and snippets.

View mcdonc's full-sized avatar

Chris McDonough mcdonc

View GitHub Profile
@mcdonc
mcdonc / gist:4516284
Created January 12, 2013 05:33
ab results for firstapp
[chrism@thinko ~]$ ab -n1001 http://127.0.0.1:8080/hello/fred
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
@mcdonc
mcdonc / hello.py
Last active December 29, 2015 20:29 — forked from offby1/hello.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from chameleon import PageTemplate
template = PageTemplate("Hello, ${name}.")
for name in ('Fred', u'ἃc', '\xf8'):
print(template(name=name))
@mcdonc
mcdonc / gist:10806434
Created April 16, 2014 04:20
inprogress django to pyramid porting thingy

Porting an Existing Application to Pyramid

Porting an application across platforms is never particularly easy, nor very interesting. In fact, it's usually a terrible idea: in general, if it ain't broke, don't fix it. But sometimes you have to do it. Maybe a new platform has a feature you believe you can't live without, or the project scope is expanding in directions that make you feel like your original platform choice might not have been the best, or maybe it's just necessary to port for political reasons. Whatever.

Porting an Existing Application to Pyramid

Porting an application across platforms is never particularly easy, nor very interesting. In fact, it's usually a terrible idea: in general, if it ain't broke, don't fix it. But sometimes you have to do it. Maybe a new platform has a feature you believe you can't live without, or the project scope is expanding in directions that make you feel like your original platform choice might not have been the best, or maybe it's just necessary to port for political reasons. Whatever.

>>> import pytz
>>> eastern = pytz.timezone('US/Eastern')
>>> import datetime
>>> now = datetime.datetime.now().replace(tzinfo=eastern)
>>> now.strftime('%a, %d %b %Y %H:%M:%S %z')
'Mon, 16 Jun 2014 15:01:02 -0456'
456. 456. What the fuck.
[chrism@thinko env27]$ bin/pcreate -s substanced mything
Creating directory /home/chrism/projects/substanced/env27/mything
Recursing into +package+
Creating /home/chrism/projects/substanced/env27/mything/mything/
Copying __init__.py_tmpl to /home/chrism/projects/substanced/env27/mything/mything/__init__.py
Copying resources.py to /home/chrism/projects/substanced/env27/mything/mything/resources.py
Recursing into retail
Creating /home/chrism/projects/substanced/env27/mything/mything/retail/
Copying __init__.py_tmpl to /home/chrism/projects/substanced/env27/mything/mything/retail/__init__.py
Recursing into templates
[chrism@thinko temp]$ git clone [email protected]:Pylons/substanced.git
Cloning into 'substanced'...
remote: Counting objects: 18768, done.
remote: Total 18768 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (18768/18768), 10.79 MiB | 3.60 MiB/s, done.
Resolving deltas: 100% (9778/9778), done.
[chrism@thinko temp]$ virtualenv -ppython2.7 env27
Running virtualenv with interpreter /home/chrism/bin/python2.7
New python executable in env27/bin/python2.7
Also creating executable in env27/bin/python
# views.py
from pyramid.view import view_config
@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
url = request.route_url('foo')
return {'project': 'myproj', 'url':url}
@mcdonc
mcdonc / gist:187e38a75fe6159c44bb
Created April 21, 2015 16:45
"pyramidpeople"

Porting an Existing Application to Pyramid

Porting an application across platforms is never particularly easy, nor very interesting. In fact, it's usually a terrible idea: in general, if it ain't broke, don't fix it. But sometimes you have to do it. Maybe a new platform has a feature you believe you can't live without, or the project scope is expanding in directions that make you feel like your original platform choice might not have been the best, or maybe it's just necessary to port for political reasons. Whatever.

@mcdonc
mcdonc / gist:7dc2e06045f3df71d12d
Created April 28, 2015 23:06
example of permissions and interface-based view configuration
from wsgiref.simple_server import make_server
from zope.interface import (
Interface,
alsoProvides,
)
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPFound
from pyramid.response import Response