Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
@diafygi
diafygi / slow_query_log_dump.py
Created December 16, 2011 04:38 — forked from memonic/cronjob.sh
Script to transform Amazon RDS slow log table into the MySQL slow query log format
"""
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")
@ryanmark
ryanmark / responsive-screens.js
Created March 5, 2012 15:59
Easy responsive screenshots with Phantom.js
/*
* 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(),
@acdha
acdha / compiler-jshint.vim
Created June 1, 2012 22:18
Use JSHint as the VIM compiler for error checking
CompilerSet makeprg=jshint\ \"%\"
CompilerSet errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m
" vim: set sts=4 sw=4 expandtab ff=unix fdm=syntax :
@acdha
acdha / solr_grouping_backend.py
Last active December 14, 2017 13:45
Experimental django-haystack 2 backend which adds support for Solr's grouping / field collapsing
# 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

Where people struggle learning Django

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

@impressiver
impressiver / raven-config.html
Last active February 27, 2024 14:27
Raven.js configuration for logging JavaScript exceptions to Sentry (https://getsentry.com/). Without the added ignore options, you'll quickly find yourself swamped with unactionable exceptions due to shoddy browser plugins and 3rd party script errors.
<!-- 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',
@willurd
willurd / web-servers.md
Last active April 28, 2024 21:38
Big list of http static server one-liners

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.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@acdha
acdha / pre-commit
Last active April 18, 2024 02:22
Git pre-commit hook which runs various code linters. Install this to .git/hooks/pre-commit inside your favorite repos
#!/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
@jmcnamara
jmcnamara / bench_excel_writers.py
Last active August 4, 2022 21:06
Benchmark of several Python Excel writing modules
##############################################################################
#
# Simple Python program to benchmark several Python Excel writing modules.
#
# python bench_excel_writers.py [num_rows] [num_cols]
#
#
import sys
from time import clock
@phill-tornroth
phill-tornroth / elasticsearch_backend.py
Last active November 11, 2015 23:05
A Django-Haystack backend for ElasticSearch 1.x that incorporates the best things I found in the recent master and pull requests, and fixes issues with each
"""
This is the basis for an elasticsearch 1.x backend I've cobbled together and am continuing
to refine and test for use. It's based on haystack master's version as of:
- https://github.com/toastdriven/django-haystack/blob/cbb72b3253404ba21e20860f620774f7b7b691d0/haystack/backends/elasticsearch_backend.py
But with @HonzaKral and @davedash's work to make the backend behave more like an ES user would expect with regard to doc types:
- https://github.com/toastdriven/django-haystack/pull/921
I also made a number of changes:
- I fixed bugs that I found in #921 (mostly related to mapping synchronization issues),
all of which I wrote up as comments on #921