Skip to content

Instantly share code, notes, and snippets.

View peterfarrell's full-sized avatar
🏠
Working from home

PJ Farrell peterfarrell

🏠
Working from home
View GitHub Profile
@keningle
keningle / decorator.py
Created July 2, 2013 19:43
Example of how to pass URL parameters to a decorator in Django
from django.utils.functional import wraps
...
def check_company_admin(view):
@wraps(view)
def inner(request, slug, *args, **kwargs):
# Get the company object
company = get_object_or_404(Company, slug=slug)
# Check and see if the logged in user is admin
@senko
senko / singleton.py
Created February 25, 2013 08:01
Singleton Django Model
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
from django.db import models
class SingletonModel(models.Model):
"""Singleton Django Model
Ensures there's always only one entry in the database, and can fix the
@rcorreia
rcorreia / drag_and_drop_helper.js
Last active August 11, 2023 06:41
drag_and_drop_helper.js
(function( $ ) {
$.fn.simulateDragDrop = function(options) {
return this.each(function() {
new $.simulateDragDrop(this, options);
});
};
$.simulateDragDrop = function(elem, options) {
this.options = options;
this.simulateEvent(elem, options);
};
@allanlei
allanlei / Procfile
Created February 9, 2012 02:06
Gunicorn config for Django application on Heroku with SSL
web: python manage.py run_gunicorn -b 0.0.0.0:$PORT -c config/gunicorn.conf --settings $DJANGO_SETTINGS_MODULE
@jeremi
jeremi / test.py
Created February 8, 2012 11:50
Chosen test using selenium web driver in Python
from selenium import webdriver
def select_from_chosen(driver, id, value):
chosen = driver.find_element_by_id(id + '_chzn')
results = chosen.find_elements_by_css_selector(".chzn-results li")
found = False
for result in results:
if result.text == value: