Skip to content

Instantly share code, notes, and snippets.

@jab3z
jab3z / gist:d098986ecc116dd2d6f5
Last active December 17, 2015 08:35
Handle form submissions via Ajax
function AjaxHandler() {
this.init = function(config) {
this.config = config;
this.bindEvents();
};
this.hideFormErrors = function($form) {
$.each($form.find(':input.required.error'), function(index, field) {
$form.find(field)
.removeClass('required error')
@jab3z
jab3z / django CMS placeholder content
Last active December 3, 2016 10:55
Get content from django cms placeholder
from HTMLParser import HTMLParser
from django.core.exceptions import ObjectDoesNotExist
from django.template import Context
from django.test import RequestFactory
from cms.models import Title
class MLStripper(HTMLParser):
@jab3z
jab3z / snake_case.txt
Last active March 13, 2017 16:33
snake case
import re
from django.utils.text import force_text
from django.utils.safestring import mark_safe
from django.utils.functional import allow_lazy
def snake_case(value):
"""
Converts spaces to underscore. Removes characters that
aren't alphanumerics, underscores, or hyphens. Converts to lowercase.
@jab3z
jab3z / log_io.py
Last active October 9, 2022 07:29
Python decorator for logging the input and output of a class method
import inspect
import logging
from functools import wraps
from typing import Callable
def log_io(log_input=False, log_output=False) -> Callable:
"""
Logs the input/output of the decorated method.
Must be explicitly called with input=True and/or output=True