Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Vanasco jvanasco

View GitHub Profile
@jvanasco
jvanasco / unicodedata_test.py
Created Feb 17, 2012
drop accented chars (unicode) to ascii equivalents
View unicodedata_test.py
import unicodedata
accented= {
'czech' : u'ťúůýžšřóňíěéďčá',
'french' : u"ùûüÿàâæçéèêëïîôœ",
'finnish' : u'äåö',
'danish' : u'åæéø',
'german' : u'äöüß',
'hungarian': u'áéíöóőüúű',
'icelandic': u'áæðéíóöþúý',
@jvanasco
jvanasco / errors.py
Created Feb 19, 2012
useful python errors
View errors.py
class Error(Exception):
"""Base class for exceptions in this module."""
def __init__(self, value=''):
self.value = value
def __str__(self):
return repr(self.value)
class HereIAm(Error):
@jvanasco
jvanasco / api_internal.py
Created Feb 24, 2012
making an api in pyramid, example a
View api_internal.py
import logging
log = logging.getLogger(__name__)
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render_to_response
from pyramid.view import view_config
# all that's necessary to know is that _base sets self.request
from ..lib import handlers as _base
@jvanasco
jvanasco / __init__.py
Created Mar 6, 2012
creating a session_https request attribute ( and session ) with pyramid beaker [monkeypatch]
View __init__.py
def main(global_config, **settings):
...
...
...
import pyramid
from pyramid_beaker import BeakerSessionFactoryConfig
from beaker.util import coerce_session_params
from pyramid.interfaces import ISessionFactory
from pyramid.decorator import reify
@jvanasco
jvanasco / blocklist.txt
Created Mar 15, 2012
blocklist of social / analytics / profiling
View blocklist.txt
# google services
# heavy js + tracking
google-analytics.com
googleadservices.com
doubleclick.net
gstatic.com
plusone.google.com
# social services
# heavy js + tracking
@jvanasco
jvanasco / pyramid_httpfound.py
Created Sep 17, 2012
httpfound tests for pyramid
View pyramid_httpfound.py
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.httpexceptions import HTTPFound
urls_debug = ('/raise','/return')
def _parse_cookies(items):
return [ (k,v) for (k,v) in items.iteritems() if k.lower() == 'set-cookie']
@jvanasco
jvanasco / defaults.py
Created Oct 9, 2012
default argument
View defaults.py
def f(a,L=[]):
L.append(a)
return L
for i in range(0,3):
print f(i)
for i in range(3,6):
print f(i)
View recurse.py
def recurse(number):
as_int = int(number)
if as_int >= 10 :
as_string = str(number)
value = sum(int(i) for i in as_string)
as_int = recurse( value )
return as_int
print recurse(2012)
@jvanasco
jvanasco / pyramid-config-settings.py
Last active Dec 15, 2015
Idea for passing in arguments to mako templating
View pyramid-config-settings.py
class SettingsSection(Settings):
def __init__(self, settings=None, section_prefix=None, **kw):
if settings is None:
settings = {}
section_prefix_len = len(section_prefix)
section = dict([ (k[section_prefix_len:],v) for k,v in settings.items() if k[:section_prefix_len] == section_prefix ])
for (k,v) in kw.items():
if k not in section:
section[k] = v
dict.__init__(self, **section)
@jvanasco
jvanasco / pyramid_mailer.response.diff
Created May 1, 2013
Diff of patch to pyramid_mailer
View pyramid_mailer.response.diff
--- a/pyramid_mailer/response.py
+++ b/pyramid_mailer/response.py
@@ -38,6 +38,7 @@ import quopri
import sys
import mimetypes
import string
+import types
from email.mime.base import MIMEBase
try:
You can’t perform that action at this time.