Skip to content

Instantly share code, notes, and snippets.

View gregplaysguitar's full-sized avatar

Greg Brown gregplaysguitar

View GitHub Profile
@gregplaysguitar
gregplaysguitar / jinja_cms.py
Last active August 29, 2015 14:14
Djangocms2000 template tag file for Coffin & Jinja2 compatibility
# -*- coding: utf-8 -*-
from django.conf import settings
from coffin import template
from jinja2 import contextfunction, Markup
from cms.application import get_rendered_block, get_rendered_image
from cms.templatetags.cms_editor import cms_editor
from cms.utils import is_editing
pkgver=1.2.19
mkdir -p $VIRTUAL_ENV/src && cd $VIRTUAL_ENV/src
curl -O http://oligarchy.co.uk/xapian/$pkgver/xapian-core-$pkgver.tar.xz && tar xf xapian-core-$pkgver.tar.xz
curl -O http://oligarchy.co.uk/xapian/$pkgver/xapian-bindings-$pkgver.tar.xz && tar xf xapian-bindings-$pkgver.tar.xz
cd $VIRTUAL_ENV/src/xapian-core-$pkgver
./configure --prefix=$VIRTUAL_ENV && make && make install
export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib
@gregplaysguitar
gregplaysguitar / placeholder.scss
Created August 29, 2012 02:43 — forked from antsa/placeholder.scss
Placeholder mixin for Sass
// Placeholder @mixin for Sass
//
// A mixin to style placeholders in HTML5 form elements.
// Includes also a .placeholder class to be used with a polyfill e.g.
// https://github.com/mathiasbynens/jquery-placeholder
// Requires Sass 3.2.
//
// Example usage (.scss):
//
// input {
@gregplaysguitar
gregplaysguitar / fields.py
Created June 27, 2012 00:48
Memory-safe ImageField for Django - checks filesize and dimensions before loading the uploaded file into memory.
try:
from PIL import Image
except ImportError:
import Image
from django import forms
from django.template.defaultfilters import filesizeformat
from django.core.exceptions import ValidationError
@gregplaysguitar
gregplaysguitar / folding_whoosh_backend.py
Last active May 14, 2022 15:09
Django-haystack Whoosh backend with character folding
# -*- coding: utf-8 -*-
"""
Whoosh backend for haystack that implements character folding, as per
http://packages.python.org/Whoosh/stemming.html#character-folding .
Tested with Haystack 2.4.0 and Whooch 2.7.0
To use, put this file on your path and add it to your haystack settings, eg.
@gregplaysguitar
gregplaysguitar / jquery.fancydropdown.js
Created January 27, 2012 01:56
Create dropdown menus with jquery
/*
Example usage:
$('ul.dropdown').fancydropdown();
(elements must have a 'title' attribute in order to populate the prompt)
*/
$.fn.fancydropdown = (function(options){
@gregplaysguitar
gregplaysguitar / slash_middleware.py
Last active August 21, 2023 12:47
Append OR remove slash in django - like APPEND_SLASH but smarter.
from django import http
from django.utils.http import urlquote
from django import urls
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
class AppendOrRemoveSlashMiddleware(MiddlewareMixin):
"""Like django's built in APPEND_SLASH functionality, but also works in
reverse. Eg. will remove the slash if a slash-appended url won't resolve,
/*
jquery.aggregate.js by Greg Brown 2011. See
http://gregbrown.co.nz/code/jquery-aggregate/ for details.
License information: http://gregbrown.co.nz/code/license/
*/
/*
@gregplaysguitar
gregplaysguitar / upgrade_user_admin.py
Last active December 4, 2021 13:37
Enhance the django user admin with enforced unique emails, better filters and list items, and user profiles editable inline.
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.forms.models import inlineformset_factory
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
def upgrade_user_admin(UserProfile=None, unique_email=False,
list_display=None):
#!/usr/bin/python
from sorl.thumbnail.conf import settings
from sorl.thumbnail.base import ThumbnailBackend
FORMAT_DICT = {
'png': 'PNG',
'jpeg': 'JPEG',
'jpg': 'JPEG',