Skip to content

Instantly share code, notes, and snippets.

<!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>
<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);
@johnboxall
johnboxall / config.rb
Created March 2, 2013 20:05
Compass `asset_cache_buster` based on file MD5 content hash rather than mtime.
# 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
@johnboxall
johnboxall / gunzip.js
Created November 8, 2011 01:30
nodejs: gunzip httpclientresponse w/ zlib
var http = require('http');
var zlib = require('zlib');
var request = http.get({
host: 'www.bonobos.com',
port: 80,
path: '/',
headers: {'accept-encoding': 'gzip'}
});
@johnboxall
johnboxall / jquery.type.js
Created September 4, 2011 02:40
For when you _really_ wanna change the type of a input with jQuery
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';
@johnboxall
johnboxall / dns.py
Created August 15, 2011 21:57
Twisted DNS server!
# http://notmysock.org/blog/hacks/a-twisted-dns-story.html
# http://blog.inneoin.org/2009/11/i-used-twisted-to-create-dns-server.html
# twistd -y dns.py
import socket
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server
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:
def view(request, template_name):
def obj_iterator():
for obj in Objs.objects.iterator():
obj.do_something()
yield obj
ctx = {
'objs': obj_iterator
}
@johnboxall
johnboxall / fastcgi.py
Created November 7, 2010 22:36
Override BaseFCGIServer.error to use Django error handling.
# 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)
// BlackBerry Geolocation. Tested w/ 4.6.0.297.
// http://docs.blackberry.com/en/developers/deliverables/1143/browser_devguide.pdf
if (window.blackberry && blackberry.location && blackberry.location.GPSSupported) {
var AUTONOMOUS_AID_MODE = 2;
function win() {
clearTimeout(failTimeoutId);
blackberry.location.removeLocationUpdate(win);
alert(blackberry.location.latitude + " : " + blackberry.location.longitude);
}