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 /
Last active Jan 16, 2020
sqlalchemy invalidation test
from __future__ import print_function
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Use this file to build your own SSCCE
# SSCCE = Short, Self Contained, Correct (Compatible) Example
# see
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
jvanasco /
Created May 8, 2019
a test harness showing an edge case scenario with bytes and string encoding from a python2 to python3 port.
# -*- coding: utf-8 -*-
from __future__ import print_function
This test harness showcases an odd scenario when providing compatibility
with Python2 and Python3 data.
The input to a function is a URL, which in Python2 might have been:
url_unicode = u'http://➡.ws/♥'
url_string = 'http://\xe2\x9e\\xe2\x99\xa5'
jvanasco /
Created Oct 19, 2018
after too much testing - including writing custom html parsers and checking cpython generated bytecode - this is the fastest general-purpose way to upgrade an html doc's images into amp i could come up with. if you expect a lot of images in a document, it would be faster to write a second function which ensure unique `imgs` and eliminates duplic…
import re
RE_img = re.compile("""<img[^>]+>""", re.I)
def upgrade(
img_layout=None, # STRING
img_fallback=None, # STRING
img_noscript=None, # BOOL
img_noloading=None, # BOOL
img_default_height=None, # must be a STRING, never an INT
jvanasco /
Created Oct 18, 2018
wellformed parser - utility for parsing html tags as fast as possible.
def extract_tag_inner(tag):
extracts the inner part of a tag - dropping brackets, tagname, trailing slash
:arg string tag: a html tag of the formats:
:returns string: the inner part of a tag
jvanasco /
Created Jul 3, 2018
shameful python
def foo():
# i am awful for doing this.
# this function has a nested function, which can not accept arguments
# the inner function will be called twice by a 3rd party library
iteration = [0, ] # use a list as a shameful hack to get around scoping issues
def bar():
iteration[0] += 1 # increment the list index, use that for comparison
if iteration[0] > 1:
jvanasco /
Created Jun 20, 2018
dogpile and raw redis
The following are some code snippets on how i optimized a system using Dogpile cache into native Redis, while still leveraging dogpile.
This is not fully functional code, it's just snippets to explain and help the next person:
General Overview:
* The cached data is a computed value of multiple permissions for an A2B relation.
* The Redis key is `'calculated-a|%s' % id_a`.
* The payload is stored in a field, via `id_b`.
jvanasco / email.txt
Created May 26, 2018
23 and me gdpr
View email.txt
It's your data.
It's our responsibility to protect it.
As a new data protection regulation goes into effect in Europe, we are taking the opportunity to make improvements for all 23andMe customers globally. On May 24, 2018, we launched important privacy updates and new tools as part of our ongoing commitment to ensure that you are in control of your data.
We updated our Privacy Statement with additional information about our practices and made it easier to understand.
We created a Data Protection Center to help explain the European Union's new regulation and provide information about our approach to compliance.
We added information to our website regarding our security practices and the measures we put in place to protect your data.
jvanasco /
Created Mar 18, 2018
LetsEncrypt DNS Auth HOWTO

LetsEncrypt DNS Auth HOWTO

This is a quick howto on generating SSL certs via EFF's CertBot using DNS authentication.

This works for domain and wildcard certs.

For security reasons, certbot is run on a local machine.

Wait, Security?

jvanasco / model-page.ini
Created Sep 19, 2017
lektor opengraph support
View model-page.ini
name = Page
label = {{ this.title }}
label = Title
type = string
label = MetaData Title
jvanasco /
Created Jul 29, 2017
this standardizes unicode codepoints to html entities when possible.
# -*- 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.
You can’t perform that action at this time.