Skip to content

Instantly share code, notes, and snippets.

View timmyomahony's full-sized avatar

Timmy O'Mahony timmyomahony

View GitHub Profile
@timmyomahony
timmyomahony / components.drag-box.js
Last active April 24, 2018 10:58
Draggable Ember Component
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['drag-box'],
attributeBindings: ['draggable'],
draggable: true,
x: 0,
y: 0,
positionChanged: Ember.observer('x', 'y', function(){
this.$().css({
var single_pair_validator = function(hand){
};
var high_card_validation = function(white_numbered_hand, black_numbered_hand){
for(var i=0; i < white_numbered_hand.length; i++){
if(white_numbered_hand[i] > black_numbered_hand[i]){
return "White wins";
}
if(white_numbered_hand[i] < black_numbered_hand[i]){
@timmyomahony
timmyomahony / nginx.conf
Created August 11, 2013 13:31
Digital Ocean 512mb, Debian 7 x64, Default Nginx Configuration.
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@timmyomahony
timmyomahony / extra_cms_tags.py
Last active March 5, 2019 12:33
A template tag for `django-cms` that allows a placeholder to be rendered and placed in a context variable so that the placeholder can be conditionally loaded. This code was originally submitted on the `django-cms` Google Group by Benoit Domingue: https://groups.google.com/forum/#!topic/django-cms/WDUjIpSc23c/discussion
from classytags.arguments import Argument, MultiValueArgument
from classytags.values import StringValue
from cms.templatetags.cms_tags import Placeholder, PlaceholderOptions
from cms.models.placeholdermodel import Placeholder as PlaceholderModel
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@timmyomahony
timmyomahony / models.py
Created December 13, 2012 00:14
Automatically generating admin URLs for your objects
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db import models
class AdminURLMixin(object):
def get_admin_url(self):
content_type = ContentType \
.objects \
.get_for_model(self.__class__)
return reverse("admin:%s_%s_change" % (
@timmyomahony
timmyomahony / twitter.py
Created September 26, 2012 06:48
Template tag to grab latest Twitter status (with tweepy)
import tweepy
import inspect
import re
from django.conf import settings
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@timmyomahony
timmyomahony / file.py
Created July 12, 2012 00:14
Automatic redirects when changing slugs
from django.contrib.redirects.models import Redirect
from django.contrib.sites.models import Site
class BlogPost(models.Model):
...
slug = models.CharField(unique=true, max_length=128)
@models.permalink
def get_absolute_url(def):
return ('blogpost_detail', (), { 'slug' : self.slug })
@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" %}' />
@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 / 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):