Skip to content

Instantly share code, notes, and snippets.

View timmyomahony's full-sized avatar

Timmy O'Mahony timmyomahony

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / 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 / extra_fandjango_middleware.py
Created March 14, 2012 19:56
Extra middleware for a canvas app with fandjango to make sure ALL requests are authorized
from django.http import HttpResponseRedirect
from django.conf import settings
from fandjango.decorators import facebook_authorization_required
class ExtraFacebookMiddleware:
"""An extra layer of middleware on top of Fandjango to
enforce facebook authentication on every request.
This avoids having to decorate every view"""
def process_view(self, request, view_func, view_args, view_kwargs):
@timmyomahony
timmyomahony / templatetags.py
Created March 16, 2012 12:46
Template tag to check to check is a particular URL is active
class NavSelectedNode(template.Node):
def __init__(self, obj, var):
self.obj = obj
self.var = var
def render(self, context):
value = template.Variable(self.obj).resolve(context)
context[self.var] = False
path = context['request'].path
# Here we can do some more complicated parsing of the current URL against our passed URL
@timmyomahony
timmyomahony / somefile.html
Created May 31, 2012 12:36
sorl.thumbnail and easy_thumbnails together
{% load smart_load %}
{% load thumbnail from sorl.thumbnail as sorl_thumbnail %}
{% load thumbnail from easy_thumnails as easy_thumbnail %}
{% sorl_thumbnail image.image "100x100" as im %}
<img src='{{ im.url }}' />
{% endthumbnail %}
<img src='{% easy_thumbnail image.image "100x100" %}' />