Skip to content

Instantly share code, notes, and snippets.

View tclancy's full-sized avatar

Tom Clancy tclancy

View GitHub Profile
tclancy / reindent.bat
Created December 10, 2011 16:26
reindent.bat for Python on Windows
@echo off
if [%1]==[] goto USAGE
echo Usage: reindent path\to\
goto END
tclancy / text-enhance-death.js
Created October 9, 2012 21:33
Kill Text-Enhance Links on a Page (requires jQuery)
function killTextEnhance()
$("a[title]").each(function (i, element) {
if (element.title.toLowerCase().indexOf("text-enhance") > -1)
tclancy /
Last active January 3, 2023 22:18
Profiling Django Management Command
from cProfile import Profile
from import BaseCommand
class ProfileEnabledBaseCommand(BaseCommand):
"""Enable profiling a command with --profile.
Requires child class to define _handle instead of handle.
tclancy / Firefox Font Adjustment
Created December 21, 2012 17:35
How to try to bring Firefox inline when using custom fonts.
body {
font: normal 75% Xyz, Arial, Helvetica, sans-serif;
@-moz-document url-prefix() {
body {
font: 70% Xyz, Arial, Helvetica, sans-serif;
def my_decorator(function=None):
def _decorator(view_function):
def _view(request, *args, **kwargs):
if not some_security_check(request.user):
return HttpResponseRedirect(reverse('auth_login'))
return view_function(request, *args, **kwargs)
_view.__name__ = view_function.__name__
_view.__dict__ = view_function.__dict__
_view.__doc__ = view_function.__doc__
_view.__module__ = view_function.__module__
tclancy /
Created February 15, 2013 17:37
Standalone Django SSL Redirection Middleware, stolen from Satchmo. Put USE_SSL = True/ False in your settings and then add {'SSL': settings.USE_SSL} to relevant definitions.
SSL Middleware
Stephen Zabel
This middleware answers the problem of redirecting to (and from) a SSL secured path
by stating what paths should be secured in file. To secure a path, add the
additional view_kwarg 'SSL':True to the view_kwargs.
For example
tclancy / Dover Goodreads Bookmarklet
Last active December 15, 2015 10:39
Search Dover, NH Library by Title from Goodreads Detail Page""+encodeURIComponent(document.getElementById("bookTitle").innerText.replace(/\([^\)]+\)/, '').replace(/^\s\s*/, '').replace(/\s\s*$/, '')));
tclancy / gist:5753154
Last active December 18, 2015 08:19
Really ugly and rough code to sort some content out of Excel
from collections import defaultdict
import operator
import os
from xlrd import open_workbook
starting from the "raw" data, which I'm assuming is the first tab, Sorted by Customer
group everything by part number and get the total sold
then list the items in descending order of popularity
Do you need any other data beyond part and total sold? Looks like I should sum the Extended Price column as well?
tclancy / AWS Backup
Last active December 19, 2015 03:48
Simple, unsubtle hack to back up files matching two patterns to AWS. Designed for a Django project right now, but no real need for the coupling.
#!/usr/bin/env python
import datetime
import os
import time
from zipfile import ZipFile, ZIP_DEFLATED
from django.conf import settings
from django.core.mail import mail_admins
from import BaseCommand
tclancy / gist:5986873
Created July 12, 2013 19:01
Sending Email from Django. Need to have SERVER_EMAIL and DEFAULT_FROM_EMAIL set. If you don't set the latter, no admin mail gets sent.
# for SSL only