Skip to content

Instantly share code, notes, and snippets.

View gregplaysguitar's full-sized avatar

Greg Brown gregplaysguitar

View GitHub Profile
@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 / 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 / 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 / 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 {
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 / 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
@gregplaysguitar
gregplaysguitar / LICENSE.txt
Last active June 23, 2023 21:46
Auto-generate srcset and sizes attributes for an <img> with Django & sorl-thumbnail
Copyright (c) 2015 Greg Brown
[gregbrown.co.nz](http://gregbrown.co.nz)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@gregplaysguitar
gregplaysguitar / simple_search.py
Last active April 19, 2017 05:05
Django simple search
# Deprecated - see https://github.com/gregplaysguitar/django-simple-search/
@gregplaysguitar
gregplaysguitar / postgres_ft.py
Last active January 29, 2018 07:54
Postgres full-text search utils for django
# -*- coding: utf-8 -*-
"""
To enable (and test) the unaccent function, as a superuser:
\connect DATABASE
CREATE EXTENSION unaccent;
SELECT unaccent('èéêë');
Example
@gregplaysguitar
gregplaysguitar / admin_raw_id.py
Last active October 19, 2022 05:52
Show object description and a link next to django's raw_id_fields, for ForeignKey and ManyToMany fields
"""
Show customisable str representation of the linked objects next to each raw id
field in a django admin change form. Works for ForeignKey, OneToOneField, and
ManyToManyField fields.
Example:
from django.contrib import admin
from admin_raw_id import ImprovedRawIdFieldsAdmin
from .models import MyModel