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
@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:
@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
@rcorreia
rcorreia / drag_and_drop_helper.js
Last active August 19, 2024 05:20
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);
};
@senko
senko / singleton.py
Created February 25, 2013 08:01
Singleton Django Model
# Written by Senko Rasic <[email protected]>
# 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
@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
@Nagyman
Nagyman / workflows-in-django.md
Last active October 19, 2024 22:03
Workflows in Django

Workflows (States) in Django

I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)
@Kartones
Kartones / postgres-cheatsheet.md
Last active November 15, 2024 21:14
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
@benzkji
benzkji / search_indexes.py
Created December 8, 2015 07:15
haystack index for django-filer PDFs
# coding: utf-8
from __future__ import unicode_literals
import os
from pdfminer.pdfdocument import PDFEncryptionError
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
class CustomTask(Task):
def on_failure(self, exc, task_id, args, kwargs, einfo):
info = '[{0}] failed: {1}'.format(task_id, exc)
logger.exception(info, exc_info=exc)
super(CustomTask, self).on_failure(exc, task_id, args, kwargs, einfo)
def on_success(self, retval, task_id, args, kwargs):
global app
if app.is_warm_shutdown:
app.consumer.connection._default_channel.do_restore = False