Skip to content

Instantly share code, notes, and snippets.

View claystreet's full-sized avatar

claystreet

  • Clay Street Online LLC
View GitHub Profile
@claystreet
claystreet / dynamic_property.py
Last active January 3, 2017 21:45
Google App Engine (GAE) helper for python.... create dynamic properties of any basic type (except ndb.StructuredProperty). Include as a mixin in any ndb.Expando or ndb.Model derived class. class MyModel(ndb.Model, DynamicPropertyMixin): pass Then... at any point where you have a MyModel entity you can create a dynamic property: my = MyModel() my…
from google.appengine.ext import ndb
class DynamicPropertyMixin(object):
""" Facilitates creating dynamic properties on ndb.Expando entities.
Also works on ndb.Model derived classes!
Note: keyword args are passed on to the underlying ndb.XxxProperty() class
"""
def is_prop(self, name):
@claystreet
claystreet / escape-html.js
Created June 24, 2013 22:49
An HTML escape function for JavaScript with three regex choices based on your need. 1. simple regex but recursively escapes "&" (similar to many html escape functions available today) 2. moderate regex won't double escape "&" 3. more complex regex won't double escape "&" on any char ref Uncomment the regex you want to use and comment out the…
var escapeHtml = (function() {
var entityMap = {
"&": '&',
"<": '&lt;',
">": '&gt;',
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
},
// simple but will recursively/blindly escape "&"