Skip to content

Instantly share code, notes, and snippets.

@rob-b
rob-b / gist:1250750
Created September 29, 2011 13:45
SIGHUP
>>> gunicorn_django --bind 0.0.0.0:8000 --name gunicorn_gauge_stage --workers 3 --preload --pid=/tmp/gunicorn_gauge_stage
/home/rob/.virtualenvs/gauge/lib/python2.6/site-packages/S3.py:16: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
import sha
2011-09-27 02:16:18 [22707] [INFO] Starting gunicorn 0.12.0
2011-09-27 02:16:18 [22707] [INFO] Listening at: http://0.0.0.0:8000 (22707)
2011-09-27 02:16:18 [22708] [INFO] Booting worker with pid: 22708
2011-09-27 02:16:18 [22709] [INFO] Booting worker with pid: 22709
2011-09-27 02:16:18 [22710] [INFO] Booting worker with pid: 22710
2011-09-27 02:16:33 [22707] [INFO] Handling signal: hup
2011-09-27 02:16:33 [22707] [INFO] Hang up: Master
@rob-b
rob-b / gist:1254947
Created September 30, 2011 20:53 — forked from munhitsu/gist:1034876
python 2.7 install on OSX (10.6.7) using brew (pip, easy_install, virtualenv, virtualenvwrapper)
#NOTE: .pydistutils.cfg seems to be not compatible with brew install python
#areas I needed to clean before installation
#clean up ~/Library/Python
#clean up .local
brew install python --framework
easy_install pip
pip install virtualenv
pip install virtualenvwrapper
mkdir $HOME/.virtualenvs
@rob-b
rob-b / mkappenginevenv.sh
Created October 12, 2011 20:31 — forked from rmyers/mkappenginevenv.sh
Setup virtual env for appengine
#!/bin/bash
#
# Build a virtual environment suitable for running appengine.
# This uses virtualenvwrapper to make the virtual environment
# and modifies the postactivate/postdeactivate scripts to make
# the appengine code happy.
#
# Usage:
# $ curl -s https://raw.github.com/gist/1282442 | bash
#
@rob-b
rob-b / gist:1704237
Created January 30, 2012 12:49
pretty print xml files
python -c "from lxml import etree; import sys; print(etree.tostring(etree.parse(sys.argv[1], etree.XMLParser(remove_blank_text=True)), pretty_print=True, encoding=unicode))" /path/to/some/xml/file.xml
#!/usr/bin/env python
import xml.dom.minidom as md
import codecs
import sys
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
pretty_print = lambda f: u'\n'.join([line for line in md.parse(open(f)).toprettyxml(indent=' '*2).split('\n') if line.strip()])
if __name__ == "__main__":
@rob-b
rob-b / gist:2490320
Created April 25, 2012 14:51
How to test django form file validation
def test_image_validation_fails_with_incorrect_filetype(self):
from django.core.files.uploadedfile import SimpleUploadedFile
from StringIO import StringIO
imgfile = StringIO('GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00ccc,\x00'
'\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;')
test_file = SimpleUploadedFile('TESTFILE', imgfile.read())
data = {'logo': test_file}
form = self.get_form()({}, data)
self.assertTrue(form.is_valid(), repr(form._errors))
> cat base.html
{% block breadcrumb %}
<a href="{% url homepage %}">Home</a>
{% endblock %}
> cat country_detail.html
{% extends "base.html" %}
{% block breadcrumb %}
{{ block.super }}
notice: /Stage[main]/Apache/File[/etc/apache2/sites-enabled/playdoh.conf]/ensure: defined content as '{md5}f452663cff74e79040145c034b87f224'
notice: /Stage[main]/Apache/Package[libapache2-mod-wsgi]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Apache/Service[apache2]: Triggered 'refresh' from 2 events
notice: /Stage[main]/Playdoh/Exec[create_mysql_database]/returns: executed successfully
notice: /Stage[main]/Playdoh/Exec[grant_mysql_database]/returns: executed successfully
err: /Stage[main]/Playdoh/Exec[syncdb]/returns: change from notrun to 0 failed: python manage.py syncdb --noinput returned 1 instead of one of [0] at /tmp/vagrant-puppet/manifests/classes/playdoh.pp:27
notice: /Stage[main]/Playdoh/Exec[migrations]: Dependency Exec[syncdb] has failures: true
@rob-b
rob-b / gist:3249309
Created August 3, 2012 16:35 — forked from alfredo/gist:3205967
Mock a Django Model
# Based on https://github.com/dcramer/mock-django
import mock
from django.utils.unittest import TestCase
from project.app.models import Category
class ModelMock(mock.MagicMock):
@rob-b
rob-b / post-checkout
Last active October 8, 2015 03:48 — forked from codysoyland/post-checkout
place in .git/hooks/post-checkout to delete empty directories and pyc files
#! /bin/sh
echo "Purging pyc files and empty directories..."
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find . -name "*.pyc" -delete > /dev/null 2>&1 &
find . -type d -empty -delete > /dev/null 2>&1 &