Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / forms.py
Created August 14, 2013 08:05
Return all results from a Django-Haystack search even if there is no query provided
from haystack.forms import FacetedSearchForm
class ShowResultsSearchForm(FacetedSearchForm):
"""
This example extends the FacetedSearchForm - you could just as easily extend SearchForm
"""
def __init__(self, *args, **kwargs):
super(BrowseFilterSearchForm, self).__init__(*args, **kwargs)
@toast38coza
toast38coza / connect-to-rackspace-LON
Created June 20, 2013 14:19
Rackspace LON region, authenticate with RackSpace pyrax python lib
import pyrax
RACK_USER = "..."
RACK_API_KEY = "..."
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credentials(RACK_USER, RACK_API_KEY, region="LON" )
@toast38coza
toast38coza / expose-element.js
Created January 11, 2013 14:35
Expose an element in a Twitter bootsrap site: Will create a bootstrap overlay (as used by Bootstrap modal), and bring the desired element in front of the overlay
/*
/* CSS */
.expose{
position:'relative';
background-color:'#fff';
z-index:1050;
}
*/
function expose(el) {
el.addClass("exposed");
# from : http://stackoverflow.com/questions/785519/how-do-i-remove-all-pyc-files-from-a-project
http://stackoverflow.com/questions/785519/how-do-i-remove-all-pyc-files-from-a-project
@toast38coza
toast38coza / play_sound.html
Created October 25, 2012 15:32
Play a sound with JavaScript (html5)
//via: http://www.catswhocode.com/blog/mastering-the-html5-audio-property
<audio id="player" src="http://www.sounddogs.com/sound-effects/104/mp3/490284_SOUNDDOGS__ch.mp3"></audio>
<a onclick="document.getElementById('player').play()" >Cheer</a>
@toast38coza
toast38coza / clear_cache.py
Created July 1, 2012 15:53
Clear cache in django
from django.core.cache import cache
cache.clear()
@toast38coza
toast38coza / django_newrelic_upstart.conf
Created June 23, 2012 09:50
Ununtu upstart script to start django_gunicorn with New Relic
description "launch django app with gunicorn and new relic monitoring"
start on net-device-up
stop on shutdown
respawn
# this cd's into your app's base dir
chdir /var/www/<appname>/
# this sets the path to your newrelic.ini file
@toast38coza
toast38coza / recursive_file_find.py
Created June 21, 2012 11:22
Recursively find all files that end with a certain extension with subdirectories
# hat-tip: Sven Marnach
# http://stackoverflow.com/questions/5817209/browse-files-and-subfolders-in-python
htmlfiles = [os.path.join(root, name)
for root, dirs, files in os.walk(path)
for name in files
if name.endswith((".html", ".htm"))]
@toast38coza
toast38coza / sort_by_dict_key.py
Created October 18, 2011 05:35
Sort a list of dicts by a key value in the dict
# given a list such as:
# list = [{'title':title, 'date': x.created_on}, ...]
# you can sort on a dict key like such
list.sort(key=lambda item:item['date'], reverse=True)
#source: http://stackoverflow.com/questions/652291/sorting-a-list-of-dictionary-values-by-date-in-python
@toast38coza
toast38coza / jquery-dialog-css
Created July 4, 2011 08:30
Simple JQuery dialog over-ride CSS
/*
It makes sense to use the built-in jquery dialog. But (IMO), the styling on them looks like it was done back a systems administrator. Here are a few lines of css to make them look a little less clunky
*/
/**
Main colors:
dark: #545454
light: #ccc
*/
.ui-dialog {border: solid 4px #545454;border-radius:0px;padding:0px;-moz-box-shadow: 3px 3px 4px #545454;-webkit-box-shadow: 3px 3px 4px #545454;box-shadow: 3px 3px 4px #545454;
/* For IE 8 */