Skip to content

Instantly share code, notes, and snippets.

@nubela
nubela / form-generation-parsley
Last active December 15, 2015 05:49
Generating HTML forms with built-in client-side and backend validators.
def generate_login_form():
"""
Generates a traditional login form, bootstrap-styled.
DEV USE: Look at this function to figure out how to generate
forms
:return form_skeleton_obj:
"""
form = [
@nubela
nubela / caching-with-mutable-default-args
Created March 14, 2013 11:12
Python: Exploiting gotchas for caching
def get_mongo(db=[]):
"""
This function employs a good ol` gotcha with using mutable objects as a default value for an argument to cache
the database object.
If the `db` arg is an empty list, populate it with the object.
Every other call to this function will skip the if clause and return the cached `db` object.
Win.
"""
if db == []: