Skip to content

Instantly share code, notes, and snippets.


Jonathan Vanasco jvanasco

View GitHub Profile
import unittest
import pprint
import re
test_text = {
'test_1' : {
'description' : "no change",
jvanasco /
Last active Aug 29, 2015
example of collisions in metaclass
class Meta(type):
def __new__(cls, clsname, bases, dct):
print "__new__"
print cls
print clsname
print bases
print dct
attrs = dct.pop('_pairs')
for v, k in attrs:
setattr(cls, k, v)
jvanasco /
Created Mar 25, 2014
quick functions for dealing with zipfiles, which might be zipped with or without a leading prefix.
def filenames_has_directory(filenames, directory):
"""if this appears to be a directory, great
treat directories as / instead of os.path, because we write with '/'
if directory[-1] != '/':
directory = directory + '/'
directory_len = len(directory)
for fname in filenames:
if fname[:directory_len] == directory:
return True
jvanasco /
Created Apr 4, 2014
pyramid_debugtoolbar - SqlAlchemy as CSV
def make_application(settings, parent_registry):
""" WSGI application for rendering the debug toolbar."""
config.add_route('debugtoolbar.request.sql_csv', '/{request_id}/sql.csv')
jvanasco /
Created May 1, 2014
eventless pyramid render
import logging
log = logging.getLogger(__name__)
import pyramid.renderers
from pyramid.path import caller_package
from ... import lib
def render(renderer_name, value, request=None, package=None):
View dev.ini
session.framework = beaker
session.key = SessionID
session.type = file
session.data_dir = %(here)s/data/ssessions/data
session.lock_dir = %(here)s/data/ssessions/lock
session.secret = 123
jvanasco / bootstrap_tabs.mako
Created May 14, 2014
bootstrap tabs in mako templates
View bootstrap_tabs.mako
## a list of available tabs
tabs_available = ['one', 'two', 'three']
## create an 'empty' dict
tab_panes = dict([(i,'') for i in tabs_available])
## what should be our selected tab
if request.tab_active and request.tab_active in tabs_available :
tab_selected = request.tab_active
jvanasco /
Created Jun 10, 2014
issue with html5lib
import bleach
sample_text = """<button class="navbar-toggle collapsed" data-target=".navbar-collapse" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
tags_ok = [ 'button', 'span', ]
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy.exc
import base64
Base = declarative_base()
jvanasco /
Created Jul 14, 2014
sqlalchemy event timing
import time
from sqlalchemy import event
from sqlalchemy.engine import Engine as SaEngine
from sqlalchemy.orm import Session as SaSession
logger = logging.getLogger("sqlalchemy.engine.base.Engine")
@event.listens_for(SaEngine, "before_cursor_execute")
def before_cursor_execute(conn, cursor, statement,
You can’t perform that action at this time.