This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
import requests | |
import unittest | |
def get(): | |
# Retrieves data from an external service eg. Twitter, Google | |
try: | |
return requests.get('http://external-service.com/') | |
except requests.RequestException: | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
"net/http" | |
"net/http/httptest" | |
) | |
func TestMergeSlashes(t *testing.T) { | |
req, _ := http.NewRequest("GET", "http://foo.com/", nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="http://httpbin.org/delay/10"></script> | |
<script>document.write("<plaintext>");</script> | |
<script src="preparsed.js"></script> | |
<title>Pre-Parser Test</title> | |
</head> | |
<body> | |
<p>Check the wire level requests generated by this page.<p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
/** | |
* In 1s, `onError` will be called to 'recover' the original document. | |
*/ | |
onError = function() { | |
var s; | |
while (s = document.scripts[0]) s.parentNode.removeChild(s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate cache busters using the MD5 digest of files rather than the default | |
# `mtime`. | |
asset_cache_buster do |_, file| | |
Digest::MD5.hexdigest(File.read(file.path)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var zlib = require('zlib'); | |
var request = http.get({ | |
host: 'www.bonobos.com', | |
port: 80, | |
path: '/', | |
headers: {'accept-encoding': 'gzip'} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rtype = /^(?:button|input)$/i; | |
jQuery.attrHooks.type.set = function(elem, value) { | |
// We can't allow the type property to be changed (since it causes problems in IE) | |
if (rtype.test(elem.nodeName) && elem.parentNode) { | |
// jQuery.error( "type property can't be changed" ); | |
// JB: Or ... can it!? | |
var $el = $(elem); | |
var insertionFn = 'after'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.exceptions import ObjectDoesNotExist | |
class InfoMiddleware(object): | |
''' | |
Record refer and user-agent info about this dude. | |
''' | |
def process_request(self, request): | |
if request.user.is_anonymous(): | |
if 'referer' not in request.session: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def view(request, template_name): | |
def obj_iterator(): | |
for obj in Objs.objects.iterator(): | |
obj.do_something() | |
yield obj | |
ctx = { | |
'objs': obj_iterator | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override BaseFCGIServer.error to use Django error handling. | |
# http://trac.saddi.com/flup/browser/flup/server/fcgi_base.py#L1210 | |
def patch_error(self, req): | |
import sys | |
from django.conf import settings | |
from django.core import urlresolvers | |
from django.core.handlers.wsgi import WSGIRequest | |
urlconf = settings.ROOT_URLCONF | |
urlresolvers.set_urlconf(urlconf) |