Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@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 / clear_cache.py
Created July 1, 2012 15:53
Clear cache in django
from django.core.cache import cache
cache.clear()
@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>
# 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 / 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");
@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 / 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 / bulksms_send_message.py
Created September 6, 2013 12:28
Send an SMS using BulkSMS and python's requests library
import requests
url = "http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0"
phone_number = 27123456678
data = {'username' : 'xxxx', 'password' : 'xxxx', 'message' : 'Testing SMS', 'msisdn' : phone_number}
response = requests.post(url,data)
@toast38coza
toast38coza / common.py
Created October 7, 2013 13:55
Nice dynamic upload_to method for Django FileField or ImageField
from django.contrib.sites.models import Site
import uuid
def upload_to(instance, filename):
current_site = Site.objects.get_current()
extension = filename.split(".")[-1]
instance_slug = getattr(instance,"slug",False)
if not instance_slug:
@toast38coza
toast38coza / ansible_stdout.yml
Created February 25, 2014 08:46
Get the stdout response from an ansible task. From: https://gist.github.com/toast38coza/6bdd151eae2ee9d751a7
- name: print to stdout
command: echo "hello"
register: hello
- debug: msg="{{ hello.stdout }}"
- debug: msg="{{ hello.stderr }}"