Skip to content

Instantly share code, notes, and snippets.

@jimmydo
jimmydo / mocknow.py
Created July 29, 2011 05:02
Python context manager for mocking out datetime.now() in unit tests.
import contextlib
import datetime
@contextlib.contextmanager
def mock_now(dt_value):
"""Context manager for mocking out datetime.now() in unit tests.
Example:
with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):
@jimmydo
jimmydo / buttons.css
Created July 24, 2011 22:37
Reset styling of button-like elements
a,
button,
input[type="button"],
input[type="submit"] {
background-color: #ccc;
line-height: normal; /* since Firefox forces <button> and <input> elements to always have a line height of 'normal', we do the same for all button-like elements for consistency */
padding: 6px 12px;
}
a {
import re
# Some mobile browsers which look like desktop browsers.
RE_MOBILE = re.compile(r"(iphone|ipod|blackberry|android.+mobile|palm|windows\s+ce)", re.I)
RE_DESKTOP = re.compile(r"(windows|linux|os\s+[x9]|solaris|bsd)", re.I)
RE_BOT = re.compile(r"(spider|crawl|slurp|bot)")
def is_desktop(user_agent):
"""
@jimmydo
jimmydo / collapsespacestag.py
Created February 24, 2011 19:29
collapsespaces is a Django template tag that collapses whitespace characters between tags into one space.
"""collapsespaces is a Django template tag that collapses whitespace characters between tags into one space.
It is based on Django's 'spaceless' template tag (spaceless is different in that it completely removes whitespace between tags).
Why is this important?
Given "<span>5</span> <span>bottles</span>", collapsespaces will preserve the space between the two span elements--spaceless will not.
In a web browser:
"<span>5</span> <span>bottles</span>" renders as "5 bottles"
"<span>5</span><span>bottles</span>" renders as "5bottles"
"""
@jimmydo
jimmydo / jquery.textchange.js
Created December 18, 2010 00:22 — forked from mkelly12/jquery.textchange.js
Make val() trigger change event
/*!
* jQuery TextChange Plugin
* http://www.zurb.com/playground/jquery-text-change-custom-event
*
* Copyright 2010, ZURB
* Released under the MIT License
*/
(function ($) {
$.event.special.textchange = {