Skip to content

Instantly share code, notes, and snippets.

View mcdonc's full-sized avatar

Chris McDonough mcdonc

View GitHub Profile
-- day 1 --
The Cynical Introduction
All Code Is Terrible
Avoid Shame, Test Everything
Proving It Works Isn't The Goal
But It Makes Me So Slow!?
Don't Be Afraid to Throw It Away
# sameroute.py
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello %(name)s!' % request.matchdict)
if __name__ == '__main__':
@mcdonc
mcdonc / gist:15096411bf36a71718f7
Created April 28, 2015 23:08
example of security plus interface-based view lookup
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
@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
@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.

# 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}
[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
[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
>>> 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.

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.