Skip to content

Instantly share code, notes, and snippets.

Jonathan Vanasco jvanasco

  • NYC
Block or report user

Report or block jvanasco

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jvanasco /
Created Jan 3, 2012
Reflecting in Pyramid/SqlAlchemy
import logging
log = logging.getLogger(__name__)
from sqlalchemy import Table
from sqlalchemy import MetaData
from sqlalchemy.orm import mapper
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension
jvanasco /
Created Jan 15, 2012
quick/dirty/incomplete implementation of php var_dump in python - this is to save a python data structure as a php variable.
def _php_var_dump(data,depth=0):
padding= " "*depth
keypadding= " "*(depth+1)
depth+= 1
if type(data) == types.DictType :
items = []
for i in data :
item = keypadding + "'%s' => %s" % (i,_php_var_dump(data[i],depth=depth))
items = ',\n'.join(items)
jvanasco /
Created Jan 27, 2012
Supporting multiple database connections & Reflecting Tables in pyramid with sqlalchemy .7
sections of code taken from :
- Mike Orr's package 'sqlahelper'
- Mike Bayer's blog post 'Django-style Database Routers in SQLAlchemy'
jvanasco / README.txt
Created Jan 30, 2012
mongodb support in pyramid
View README.txt
Python MonogoDB integration, based on
I'm migrating a few projects to use mongodb, and I found this to be the easiest way to maintain across all projects ( as in, i don't have to change any code outside of .ini files )
1. the main() routin in just needs to call subscribers.mongodb.initialize_mongo_db()
2. subscribers has a single file called mongodb, which initializes
3. environment.ini has its own mongodb space. setting mongodb_use to 'true' will initialize it, setting it to anything else will ignore it.
jvanasco / gist:1734244
Created Feb 4, 2012
View gist:1734244
v 0.0.3
a port of some classic pylons styling, but without much of the cruft that was not used often
This allows for a very particular coding style, which i prefer.
As you can see below, 'methods' are broken into multiple parts:
jvanasco /
Created Feb 6, 2012
pyramid - how to automatically map the version of deform's static components that you're using to a subdir (on startup)
def main(global_config, **settings):
jvanasco / select.html
Created Feb 7, 2012
jquery username availability check - with timeout
View select.html
Choose a username. You can't post until you do!
<form method="post" action="/account/choose-username">
<input type="text" name="username" value="" id="username_selector"/>
<span id="fieldstatus-username"></span>
// on all keyups, set a message that the username is bad or that you're checking
// however, don't actually check until you have a timeout - e.g. .6 seconds
// there's no point on taxing a server to repeatedly check
jvanasco /
Created Feb 8, 2012
Pyramid Event Subscribers to migrate cookie data across redirects
def main(global_config,**settings):
jvanasco /
Created Feb 9, 2012 — forked from ericrasmussen/
FormGenerator to extend Deform functionality
Simple module to ease form handling with ``Deform``. The provided
``FormGenerator`` class handles repetitive tasks like validation,
xhr requests, and recovering from exceptions thrown by the model.
### Begin example scenario: Adding a new user
from myschemas import UserSchema
from formgenerator import (
jvanasco /
Created Feb 14, 2012
akhet init file
from pyramid.config import Configurator
import pyramid_beaker
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
config = Configurator(settings=settings)
# initiate Beaker sessions and caching.
# configuration is in your environment.ini file
You can’t perform that action at this time.