Skip to content

Instantly share code, notes, and snippets.

@igniteflow
igniteflow / gist:1422656
Created December 2, 2011 10:10
Super simple redirect for a Django app
'''
A quick and dirty redirect, preserving params and path info
'''
# urls.py
urlpatterns = patterns('',
(r'', 'tce.views.redirect_req'),
)
# views.py
@igniteflow
igniteflow / fizzbuzz.py
Created December 13, 2011 10:06
Python: Fizz buzz
num = range(1,101)
for n in num:
if n % 15 == 0:
print 'FizzBuzz'
elif n % 5 == 0:
print 'Buzz'
elif n % 3 == 0:
print 'Fizz'
else:
@igniteflow
igniteflow / remove_none.py
Created January 18, 2012 12:32
Remove None elements from a list in Python
def remove_none_elements_from_list(list):
return [e for e in list if e != None]
@igniteflow
igniteflow / broken_pipe_32_fix.py
Created January 24, 2012 10:51
Fix for Django runserver: [Errno 32] Broken pipe
"""
The problem is caused by the client terminating the call before the job is processed. To fix, add in the ThreadingMixIn as recommended here by Edward Samson (for a different, but related problem) here https://bitbucket.org/edu/woof/issue/1/errno-32-broken-pipe-upon-accessing-woof
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 41598)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
@igniteflow
igniteflow / DJANGO_SETTINGS_MODULE.sh
Created February 6, 2012 12:57
Python/Django environment settings
# if your getting errors about DJANGO_SETTINGS_MODULE not being set make sure you have the following two variables set
export PYTHONPATH=/some/path:/another/path:$PYTHONPATH
export DJANGO_SETTINGS_MODULE=www.settings
@igniteflow
igniteflow / git_python_current_branch.py
Created February 7, 2012 17:33
GitPython get current active branch
"""
Gets the name of the active Git branch as a string.
Depends on GitPython
pip install GitPython
"""
from git import Repo
repo = Repo('/path/to/your/repo')
branch = repo.active_branch
@igniteflow
igniteflow / django-email-testing.sh
Created February 15, 2012 15:13
Testing email in Django
python -m smtpd -n -c DebuggingServer localhost:1025
# then add the following to your Django settings
# EMAIL_HOST = 'localhost'
# EMAIL_PORT = 1025
@igniteflow
igniteflow / redis-producer-consumer.py
Created February 20, 2012 16:37
A very simple implementation of a Redis producer-consumer messaging queue in Python
import redis
import time
import sys
def producer():
r = redis.Redis()
i = 0
while True:
r.rpush('queue', 'Message %d' % i)
@igniteflow
igniteflow / gist:1877718
Created February 21, 2012 17:55
Add a new rule to iptables and apply
# add your rules
/etc/iptables.rules
# update the rules
iptables-restore < /etc/iptables.rules
@igniteflow
igniteflow / gist:1877752
Created February 21, 2012 17:56
rabbitmq commands
# see the queue
rabbitmqctl list_queues