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
jvanasco / encodings_test.py
Created May 8, 2019
a test harness showing an edge case scenario with bytes and string encoding from a python2 to python3 port.
View encodings_test.py
# -*- 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\xa1.ws/\xe2\x99\xa5'
@jvanasco
jvanasco / amp_img_upgrade.py
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…
View amp_img_upgrade.py
import re
RE_img = re.compile("""<img[^>]+>""", re.I)
def upgrade(
html,
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
jvanasco / wellformed_parser.py
Created Oct 18, 2018
wellformed parser - utility for parsing html tags as fast as possible.
View wellformed_parser.py
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:
<TAG_NAME TAG_ATTRIBUTES>
<TAG_NAME TAG_ATTRIBUTES/>
<TAG_NAME TAG_ATTRIBUTES />
:returns string: the inner part of a tag
@jvanasco
jvanasco / shame.py
Created Jul 3, 2018
shameful python
View shame.py
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
jvanasco / dogpile.py
Created Jun 20, 2018
dogpile and raw redis
View dogpile.py
"""
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
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.
https://www.23andme.com/about/privacy/
We created a Data Protection Center to help explain the European Union's new regulation and provide information about our approach to compliance.
https://www.23andme.com/gdpr/
We added information to our website regarding our security practices and the measures we put in place to protect your data.
@jvanasco
jvanasco / letsencrypt_dns_howto.md
Created Mar 18, 2018
LetsEncrypt DNS Auth HOWTO
View letsencrypt_dns_howto.md

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
jvanasco / model-page.ini
Created Sep 19, 2017
lektor opengraph support
View model-page.ini
[model]
name = Page
label = {{ this.title }}
[fields.title]
label = Title
type = string
[fields.meta_title]
label = MetaData Title
@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.
"""
You can’t perform that action at this time.