Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Vanasco jvanasco

View GitHub Profile
View test_markdown_cleanup.py
import unittest
import pprint
import re
test_text = {
'test_1' : {
'description' : "no change",
@jvanasco
jvanasco / collisions.py
Last active Aug 29, 2015
example of collisions in metaclass
View collisions.py
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
jvanasco / zipfun.py
Created Mar 25, 2014
quick functions for dealing with zipfiles, which might be zipped with or without a leading prefix.
View zipfun.py
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
jvanasco / __init__.py
Created Apr 4, 2014
pyramid_debugtoolbar - SqlAlchemy as CSV
View __init__.py
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
jvanasco / render_eventless.py
Created May 1, 2014
eventless pyramid render
View render_eventless.py
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
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
jvanasco / test.py
Created Jun 10, 2014
issue with html5lib
View test.py
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>
</button>"""
tags_ok = [ 'button', 'span', ]
View test.py
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy.exc
import base64
Base = declarative_base()
@jvanasco
jvanasco / model.py
Created Jul 14, 2014
sqlalchemy event timing
View model.py
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.