Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Vanasco jvanasco

View GitHub Profile
@jvanasco
jvanasco / standardize_unicode.py
Created Jul 29, 2017
this standardizes unicode codepoints to html entities when possible.
View standardize_unicode.py
# -*- coding: utf-8 -*-
"""
this translates unicode codepoints in the input into *NAMED* html entities
a future version may do the html spec supported entities as well
this does not escape unsafe html into entities, as lots of libraries do that and
this function is likely to be used in a pipeline that does that too.
this simply standardizes unicode points into html entities.
"""
@jvanasco
jvanasco / standardize_unicode.py
Created Jul 29, 2017
this standardizes unicode codepoints to html entities when possible.
View standardize_unicode.py
# -*- coding: utf-8 -*-
"""
this translates unicode codepoints in the input into *NAMED* html entities
a future version may do the html spec supported entities as well
this does not escape unsafe html into entities, as lots of libraries do that and
this function is likely to be used in a pipeline that does that too.
this simply standardizes unicode points into html entities.
"""
@jvanasco
jvanasco / sqla_injection_test.py
Last active Jul 6, 2017
sqlalchemy injection test
View sqla_injection_test.py
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Use this file to build your own SSCCE
# SSCCE = Short, Self Contained, Correct (Compatible) Example
# see http://sscce.org/
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@jvanasco
jvanasco / import_logger.py
Created Oct 24, 2016
Use the `import_logger.py` to "decorate" cPython's `import` statement, and log the actual memory grown to a file. `transformer.py` will do some quick/lightweight transformations on the logger's output, creating a spreadsheet's readable csv. this is far from perfect, but can be very helpful.
View import_logger.py
if True:
print("===> installing import_logger_orverride")
import os
import psutil
import pdb
import pprint
import __builtin__
import logging
import sys
@jvanasco
jvanasco / import_logger.py
Created Oct 24, 2016
Use the `import_logger.py` to "decorate" cPython's `import` statement, and log the actual memory grown to a file.
View import_logger.py
if True:
print("===> installing import_logger_orverride")
import os
import psutil
import pdb
import pprint
import __builtin__
import logging
import sys
View pyramid_response_caching-v2.py
"""
After a bit of thought, I rewrote our response caching.
I stripped it into this gist in case anyone needs a starting point in the future. it's still rather specialized and hacky... but a bit cleaner than the earlier approach
The general overiew is this:
* We needed to cache responses AND perform some light operations. 99% of a rendered page is cachable as-is.
* We wanted to consolidate where the configuration is, perferalbly with the route_name declaration - but in this case it was better off with the caching code.
* The cached output should be rendered, which mades the `decorators` egress perfect... however some setup code happens in the __init__ phase of view-based classes and the 'decorators' ingress happens too soon.
@jvanasco
jvanasco / app_celery.py
Created Jun 18, 2016
cache with temporary values.
View app_celery.py
@task
def get_ExpensiveCalculator_foo():
expensive_foo = app_shared.ExpensiveCalculator().expensive_foo()
app_pyramid.CheapCalculator().set_foo(expensive_foo)
@jvanasco
jvanasco / app_celery.py
Created Jun 18, 2016
cache with temporary values.
View app_celery.py
@task
def get_ExpensiveCalculator_foo():
expensive_foo = app_shared.ExpensiveCalculator().expensive_foo()
app_pyramid.CheapCalculator().set_foo(expensive_foo)
@jvanasco
jvanasco / deploy.py
Last active May 9, 2016
Automated (mostly) Trac Installation for Dreamhost
View deploy.py
import os
username = 'johndoe'
svndomain = 'svn.example.com'
www_root = "/home/%(username)s/webroot/%(svndomain)s/" % {'username': username, 'svndomain': svndomain}
trac_root = "/home/%(username)s/svn_trac/" % {'username': username}
svn_root = "/home/%(username)s/svn" % {'username': username}
shared_chrome_dir = "/home/%(username)s/svn_trac/trac-deploy/htdocs" % {'username': username}
sites = [i.strip() for i in open('trac_sites.txt').readlines()]
@jvanasco
jvanasco / client.py
Last active Apr 20, 2016
statsd max connections
View client.py
class StatsClient(StatsClientBase):
"""A client for statsd."""
def __init__(self, host='localhost', port=8125, prefix=None,
maxudpsize=512, ipv6=False):
"""Create a new client."""
fam = socket.AF_INET6 if ipv6 else socket.AF_INET
family, _, _, _, addr = socket.getaddrinfo(
host, port, fam, socket.SOCK_DGRAM)[0]
self._addr = addr
You can’t perform that action at this time.