Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
#!/usr/bin/env PYTHONIOENCODING=utf-8 python | |
# encoding: utf-8 | |
"""Git pre-commit hook which lints Python, JavaScript, SASS and CSS""" | |
from __future__ import absolute_import, print_function, unicode_literals | |
import os | |
import subprocess | |
import sys |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
<!-- Raven.js Config --> | |
<script src="{{ JS_PATH }}/lib/raven.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
// Ignore list based off: https://gist.github.com/1878283 | |
var ravenOptions = { | |
// Will cause a deprecation warning, but the demise of `ignoreErrors` is still under discussion. | |
// See: https://github.com/getsentry/raven-js/issues/73 | |
ignoreErrors: [ | |
// Random plugins/extensions | |
'top.GLOBALS', |
Over the last 3 years or so I've helped a bunch of companies, small and large, switch to Django. As part of that, I've done a lot of teaching Django (and Python) to people new to the platform (and language). I'd estimate I've trained something around 200-250 people so far. These aren't people new to programming — indeed, almost all of them are were currently employed as software developers — but they were new to Python, or to Django, or to web development, or all three.
In doing so, I've observed some patterns about what works and what doesn't. Many (most) of the failings have been my own pedagogical failings, but as I've honed my coursework and my skill I'm seeing, time and again, certain ways that Django makes itself difficult to certain groups of users.
This document is my attempt at organizing some notes around what ways different groups struggle. It's not particularly actionable — I'm not making any arguments about what Django should or shouldn't do (at least
# encoding: utf-8 | |
"""Experimental Solr Grouping / Field Collapsing backend for Haystack 2.0""" | |
# NOTE: You must be running the latest Pysolr master - no PyPI release yet! | |
# See https://gist.github.com/3750774 for the current version of this code | |
# See http://wiki.apache.org/solr/FieldCollapsing for the Solr feature documentation | |
from __future__ import absolute_import | |
import logging | |
from django.db.models.loading import get_model |
CompilerSet makeprg=jshint\ \"%\" | |
CompilerSet errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m | |
" vim: set sts=4 sw=4 expandtab ff=unix fdm=syntax : |
/* | |
* Take a set of full height screenshots for a range of screensizes. | |
* phantomjs responsive-screens.js http://www.cnn.com/ png | |
* | |
* This will create a directory tree in your current directory which | |
* mirrors the URL. All files will be named with the current time. | |
* You can run this on a cron to build an archive of screenshots. | |
**/ | |
var page = new WebPage(), |
""" | |
Queries the slowlog database table maintained by Amazon RDS and outputs it in | |
the normal MySQL slow log text format. Modified version of the script by | |
memonic (Thanks!) at https://gist.github.com/1481025 | |
Things to change in this script for your own setup: | |
<root_user> to your mysql root user (e.g. "root") | |
<root_pass> to your mysql root password (e.g. "hunter2") | |
<host_domain> to your mysql root password (e.g. "prod-01.w3rfs2.us-east-1.rds.amazonaws.com") |
""" | |
An alternative Django ``TEST_RUNNER`` which uses unittest2 test discovery from | |
a base path specified in settings, rather than requiring all tests to be in | |
``tests`` module of an app. | |
If you just run ``./manage.py test``, it'll discover and run all tests | |
underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run | |
``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in | |
that module (you can also pass multiple modules). |
from itertools import count | |
def chunked_iterator(iterable, chunk_size): | |
"""Given a slice-able yield individual items but consume them in chunk_size | |
batches so we can e.g. retrieve records from Solr in 50-100 batches | |
rather than the default 10 | |
Note that unlike the itertools grouper example we must use slice notation | |
to trigger things like Haystack's sliced __getitem__ to set our own batch | |
size |