Skip to content

Instantly share code, notes, and snippets.

View crccheck's full-sized avatar

Chris Chang crccheck

View GitHub Profile
@crccheck
crccheck / djtoolbar-sort.js
Created November 9, 2010 01:09
Sort Django Debug Toolbar SQL by execution time
jQuery.fn.sort = function() { return this.pushStack( [].sort.apply( this, arguments ), []); };
$('.djDebugSql').closest('tr').each(function(i) { this.setAttribute('rel',i); });
function dtsql(o){
switch (o) {
case 'clean' : $('.djDebugSql').each(function(){ $(this).contents()[1].nodeValue = ' '; }); break;
case 'time' : tbody = $('.djDebugSql:eq(0)').closest('tbody'); tbody.children('tr').sort(function(a,b){ return $(b).children('td:eq(0)').html() - $(a).children('td:eq(0)').html() }).appendTo(tbody);
break;
}
}
dtsql('time');
@crccheck
crccheck / View html output of a django url.py
Created November 10, 2010 16:30
Use Django Test Client to curl a url
from django.test.client import Client
def render_url(url):
c = Client()
return c.get(url).content
@crccheck
crccheck / django resolve url_to_view.py
Last active September 24, 2015 05:17
Too lazy to figure out what view goes with what url? Me too
# based on http://stackoverflow.com/questions/797773/django-caching-can-it-be-done-pre-emptively
# run this from `manage.py shell`
# if you have ipython, you can do `what_view /some/silly/url/` and remember the leading and trailing slash
from django.core.urlresolvers import resolve
def what_view(url):
try:
(v, foo, params) = resolve(url)
print "View Name: %s Line: %s of %s" % (v.__name__, v.__code__.co_firstlineno, v.__code__.co_filename)
return v, foo, params
except:
@crccheck
crccheck / add jquery bookmarklet.js
Created November 19, 2010 18:05
Add the latest jquery to the page for you to play with
javascript:(function(){var script=document.createElement('script');script.type='text/javascript';script.src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';document.documentElement.childNodes[0].appendChild(script)})()
@crccheck
crccheck / remove css style bookmarklet.js
Created December 6, 2010 17:33
Remove all CSS styles bookmarklet
javascript:(function(){$('[style]').removeAttr('style'); $('link[type="text/css"]').remove(); $('style').remove();})();
@crccheck
crccheck / swap_env_bookmarklet.js
Last active January 26, 2022 17:03
Bookmarklet to swap from the live site to my local dev site
javascript:(function(){var a=location.href.split('/');a[0]='http:';a[2]=location.port?'www.texastribune.org':'localhost:8000';window.open(a.join('/'))})();
$('*').hover(function(){ var t = $(this); t.css('outline',t.parents().length + 'px solid red'); }, function(){ $(this).css('outline','0 none'); })
jQuery.fn.simulateClick = function() {
// simulate a mouse click, only acts on the first element of a set
if (this.length) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this[0].dispatchEvent(evt);
}
return this;
}
function _(l){return l+(_+l)[11-((_._=(_._?_._:!_)+1)%(1+1)?!1:1+1+1+1+1)]}_(_(_('')))
@crccheck
crccheck / gist:1213138
Created September 13, 2011 04:53
Useful csslint rules
csslint --rules=empty-rules,zero-units,display-property-grouping,vendor-prefix,regex-selectors,import,duplicate-properties