Skip to content

Instantly share code, notes, and snippets.

View timmyomahony's full-sized avatar

Timmy O'Mahony timmyomahony

View GitHub Profile
@timmyomahony
timmyomahony / semantic_editor_layouts.py
Created January 27, 2012 12:11
django-semantic-editor layout to use the Zurb Foundation CSS
import re
from semanticeditor.layout import LayoutDetailsBase
def num_to_word(num):
return ('', 'one', 'two', 'three', 'four',)[num]
class FoundationLayoutDetails(LayoutDetailsBase):
"""
A custom layout to use the Zurb Foundation grid. At the moment it only works for up
to 4 columns to avoid messy calculations.
@timmyomahony
timmyomahony / menu.py
Created January 26, 2012 00:40
cmsplugin-blog menu for use with breadcrumb navigation
import itertools
from time import strftime
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from menus.menu_pool import menu_pool
from menus.base import NavigationNode
from cms.menu_bases import CMSAttachMenu
@timmyomahony
timmyomahony / index.html
Created January 21, 2012 09:12
An example of two inline, absolutely positioned dropdown menus that assume the width of their first element but expand in-place on hover to take the width of the largest element : http://jsfiddle.net/timmyomahony/tGn6m/
<div class="before">
An example of two inline, absolutely positioned dropdown menus that assume the width of their first element but expand in-place on hover to take the width of the largest element.
</div>
<div class="wrapper">
<div>Two lists: </div>
<div class="dropdown first">
<ul>
<li>Short 1st element</li>
<li>A bit longer 2nd element</li>
</ul>
@timmyomahony
timmyomahony / cropping_pil.engine.py
Last active September 29, 2015 18:37
Custom sorl.thumbnail engine to perform specific crops
from sorl.thumbnail.engines import pil_engine
from sorl.thumbnail import parsers
class CropperEngine(pil_engine.Engine):
"""
A custom sorl.thumbnail engine (using PIL) that first crops an image according to 4 pixel/percentage
values in the source image, then scales that crop down to the size specified in the geometry. This is
in contrast to sorl.thumbnails default engine which first scales the image down to the specified geometry
and applies the crop afterward.
"""
@timmyomahony
timmyomahony / postprocess_sekizai.py
Created October 25, 2011 01:11
django-sekizai postprocessor for enabling django-compressor compatibility
"""
Get django-sekizai, django-compessor (and django-cms) playing nicely together
re: https://github.com/ojii/django-sekizai/issues/4
using: https://github.com/jezdez/django_compressor.git
and: https://github.com/ojii/[email protected]
"""
from compressor.templatetags.compress import CompressorNode
from django.template.base import *
def compress(data, name):
@timmyomahony
timmyomahony / nginx.conf
Created June 26, 2011 13:29
Python, UWSGI, Supervisor & Nginx
upstream uwsgi {
ip_hash;
server 127.0.0.1:40000;
}
server {
listen 80;
server_name www.domain.com;
root /sites/mysite/;
access_log /sites/mysite/log/nginx/access.log;
@timmyomahony
timmyomahony / twittify.py
Created June 13, 2011 16:42
twittify: django template filter to replace metions (@'s) and hashtags (#'s) with links to twitter
@register.filter(name='twittify')
def twittify(value):
""" Replace @ and #'s with links to twitter"""
return mark_safe(
re.sub(r"#(?P<ht>([a-zA-Z0-9_])+)", r"#<a href='http://twitter.com/#!/search?q=\g<ht>' target='_blank'>\g<ht></a>",
re.sub(r"@(?P<un>([a-zA-Z0-9_]){1,15})", r"@<a href='http://twitter.com/\g<un>' target='_blank'>\g<un></a>", value))
)
twittify.mark_safe=True