Skip to content

Instantly share code, notes, and snippets.

@bregenspan
bregenspan / gist:5061480
Created March 1, 2013 00:39
Quick little script to test an XCode expression against an HTML file, using Scrapy's XPath selector. This is by no means the best or most direct way to test an XPath expression.
from scrapy.http import TextResponse
from scrapy.selector import HtmlXPathSelector
XPATH_TO_TEST = "//img/@src"
FILE_TO_TEST_AGAINST = "pathtest.html"
f = open(FILE_TO_TEST_AGAINST, 'r')
test_html = f.read()
response = TextResponse('http://www.example.com', status=200, headers=[], body=test_html)
@bregenspan
bregenspan / gist:2504141
Created April 26, 2012 23:28
Add support for combination of manual and automatic bindings to Backbone ModelBinder
diff --git a/static/js/lib/Backbone.ModelBinder.js b/static/js/lib/Backbone.ModelBinder.js
index b321c37..53881b1 100644
--- a/static/js/lib/Backbone.ModelBinder.js
+++ b/static/js/lib/Backbone.ModelBinder.js
@@ -25,6 +25,10 @@
this._model = model;
this._rootEl = rootEl;
+ this._attributeBindings = {};
+ this._options = { // TODO: set this properly
@bregenspan
bregenspan / gist:2161338
Created March 22, 2012 18:25
Mixin to supply Tastypie resource with support for X-HTTP-Method-Override headers, using jacobian's patch from https://github.com/toastdriven/django-tastypie/pull/351
class XHMOMixin(object):
"""
Use to supply a Tastypie resource with support for X-HTTP-Method-Override
headers, e.g.:
`class HomeResource(XHMOMixin, ModelResource):`
"""
def method_check(self, request, allowed=None):
"""