View dict.js
Object.defineProperty(Object.prototype, "setdefault", { | |
value: function(key, value) { | |
if (!this.hasOwnProperty(key)) { | |
if (typeof value === 'undefined') value = null; | |
this[key] = value; | |
return value; | |
} | |
return this[key]; | |
} | |
}); |
View html_diff.py
import difflib | |
import re | |
def html_diff(list1, list2, title='', left='', right=''): | |
"""Returns HTML as string representing a visual diff for the given lists.""" | |
diff_html = difflib.HtmlDiff().make_file(list1, list2, left, right) | |
diff_html = re.sub(r'<title>.*</title>', '<title>%s</title>' % title, diff_html) | |
diff_html = diff_html.replace('content="text/html; charset=ISO-8859-1"', | |
'content="text/html; charset=UTF-8"') | |
diff_html = diff_html.encode('ascii', 'xmlcharrefreplace') |
View setqueue.py
from collections import MutableSet as _MutableSet, OrderedDict as _OrderedDict | |
from itertools import chain as _chain | |
class SetQueue(_MutableSet): | |
def __init__(self, iterable=(), maxlen=None): | |
self._queue = _OrderedDict() | |
self._maxlen = maxlen | |
self.update(iterable) |
View listdict_setitem_subclass.py
from collections import OrderedDict as _OrderedDict | |
try: | |
from thread import get_ident as _get_ident | |
except ImportError: | |
from dummy_thread import get_ident as _get_ident | |
class ListDict(_OrderedDict): | |
def __init__(self, *args, **kwds): | |
try: |