Skip to content

Instantly share code, notes, and snippets.

@joncotton
joncotton / gist:1695938
Created January 28, 2012 22:07
A horror of non-semantic markup
<!--
From "The Minimalist" Tumblr Theme
http://www.tumblr.com/theme/12051
In addition to having no semantic meaning whatsoever,
the tag structure of this headline makes it very difficult
to select for copy/pasting.
That said, I do like the theme.
-->
@joncotton
joncotton / gist:2255481
Last active October 2, 2015 14:08
render_model with
"""
A working `render_model with` that works like Django's include templatetag. It's a gist because it's not official enough to fork&commit. There are no tests and `with` isn't implemented on the other `render` tags.
"""
from django.conf import settings
from django.template.loader_tags import BaseIncludeNode
from django.template.defaulttags import token_kwargs
# class RenderObjectNode(template.Node):
@joncotton
joncotton / clippify.bookmarklet.js
Created May 29, 2012 21:46
Add Microsoft Clippy to any webpage
/**
* A bookmarklet to Clippify any webpage.
*
* All possible by: http://www.smore.com/clippy-js
*/
javascript:(function(){function c(a,b){console.log("dynamically loading-",a);if(a.readyState){a.onreadystatechange=function(){if(a.readyState=="loaded"||a.readyState=="complete"){a.onreadystatechange=null;if(b){b()}}}}else{a.onload=function(){if(b){b()}}}}function d(){console.log("launching clippy");clippy.load("Clippy",function(a){$(".clippy").css("position","fixed");$(".clippy").css("z-index",1e3);a.show();a.moveTo(100,100)})}function e(){b=document.createElement("script");b.src="https://raw.github.com/smore-inc/clippy.js/master/build/clippy.js";document.body.appendChild(b);var a=document.createElement("link");a.rel="stylesheet";a.type="text/css";a.media="all";a.href="https://raw.github.com/smore-inc/clippy.js/master/build/clippy.css";document.getElementsByTagName("head")[0].appendChild(a)}var a;var b;if(typeof jQuery=="undefined"||jQuery.fn.jquery<"1.7"){a=document.createElement("script");var f=/^https:/
@joncotton
joncotton / no_mini_header.js
Last active October 5, 2015 23:07
Remove the scrolling mini-header from new TBC site
javascript:(function(){html=document.getElementsByTagName('html')[0];html.classList.add('is-tablet');document.getElementsByClassName('family-branding')[0].style.position='absolute';})()
@joncotton
joncotton / post-checkout
Last active January 30, 2018 05:52
Git hook to remove *.pyc files and empty directories. Put in `.git/hooks/post-checkout` and chmod +x to make it run.
#! /bin/sh
echo "Purging pyc files and empty directories..."
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files, empty directories and MacOS cruft
find . -name '*.pyc' -delete 2>&1 > /dev/null &
find . -type d -empty -delete 2>&1 > /dev/null &
find . -type f -name '.DS_Store' -delete 2>&1 > /dev/null &
@joncotton
joncotton / local_settings_snippet.py
Created February 6, 2013 00:39
I specify my Django database settings in `local_settings.py` and I use this to yell at me if I switch to the production database.
# actual database config
DATABASES = {
'default': local
# 'default': PRODUCTION
}
if DATABASES['default'] == PRODUCTION:
import warnings
@joncotton
joncotton / gitignore
Created October 7, 2013 20:24
.gitignore file for ArmSections. Nothing official, just WIP for now.
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported Python/Django versions.
# To use it, "pip install tox" and then run "tox".
[tox]
envlist = py27_django13, py27_django14, py27_django15, py27_django16
downloadcache = {toxworkdir}/.cache
[testenv]
@joncotton
joncotton / gist:6874663
Created October 7, 2013 20:46
WIP for using Django 1.6's new `get_queryset()` that replaces `get_query_set()`. https://docs.djangoproject.com/en/1.6/releases/1.6/#get-query-set-and-similar-methods-renamed-to-get-queryset
def get_queryset(self):
"""Use the same ordering as TreeManager"""
args = (self.model._mptt_meta.tree_id_attr,
self.model._mptt_meta.left_attr)
method = 'get_query_set' if django.VERSION < (1, 6) else 'get_queryset'
return getattr(super(SectionManager, self), method)().order_by(*args)
if django.VERSION < (1, 6):
def get_query_set(self):
@joncotton
joncotton / keybase.md
Created February 28, 2014 18:26
keybase.md

Keybase proof

I hereby claim:

  • I am joncotton on github.
  • I am joncotton (https://keybase.io/joncotton) on keybase.
  • I have a public key whose fingerprint is 0FED 542A 1506 2BB8 5294 A498 B347 4256 CC96 C254

To claim this, I am signing this object: