Skip to content

Instantly share code, notes, and snippets.

@rpq
rpq / sm.sh
Created April 26, 2012 13:27
django south migration bash script
1 #!/bin/bash
2
3 APP_NAME=$1
4
5 echo ""
6 echo "Run python manage.py schemamigration --auto ${APP_NAME}?"
7 echo ""
8 select yn in "Yes" "No"; do
9 case $yn in
10 Yes ) python manage.py schemamigration --auto ${APP_NAME}; break;;
@rpq
rpq / white_space_check_git
Created May 2, 2012 13:48
git pre-commit hook: white space check
52 WHITESPACE_CHECK=`git status | grep modified | awk -F" " '{print $3}' | xargs -I '{}' grep -nPH "^[ ]+$" '{}'`
53 WHITESPACE_CHECK_COUNT=`echo "$WHITESPACE_CHECK" | wc -w`
54 if [ "$WHITESPACE_CHECK_COUNT" != "0" ]; then
55 echo "$WHITESPACE_CHECK" | xargs -I '{}' echo ">> git pre-commit hook: white space in {}"
56 exit 1
57 fi
@rpq
rpq / windows_character_check_git
Created May 3, 2012 13:42
git pre-commit hook: windows character (^M - ctrl-v ctrl-m) check
59 CTRL_M=`git status | grep modified | awk -F" " '{print $3}' | xargs -I '{}' grep -nPH "^M$" {}`
60 CTRL_M_COUNT=`echo "$CTRL_M" | wc -w`
61 if [ "$CTRL_M_COUNT" != "0" ]; then
62 echo "$CTRL_M" | xargs -I '{}' echo ">> git pre-commit hook: CTRL-M in {}"
63 exit 1
64 fi
@rpq
rpq / vim_delete_python_print
Created May 29, 2012 14:35
vim delete lines having print: beginning with space and followed by print (python print)
:g/^\s\+print/d
@rpq
rpq / django_staticfiles.markdown
Last active November 29, 2018 14:45
django static files briefer

##The django static files (how I understand them):

I will refer to the staticfiles app as 'staticfiles' in this document... ie, staticfiles gets installed as an app in django when django.contrib.staticfiles is in settings.py's INSTALLED_APPS variable.

I think the confusion with staticfiles is based on the fact that the documentation mashes a bunch of different things together, specifically whether or not staticfiles is used to serve files in 1. development mode and/or 2. production mode. Additionally, its 3. capabilities outside of serving static files, the staticfiles app could also through the use of the python manage.py collectstatic command collect your static files from all sorts of different locations (local file system, cloud, etc) and download them to what's specified in STATIC_ROOT. You could setup your production http server to serve the files out of STATIC_ROOT for STATIC_URL after they've been collected there.

1. Development Mode.

If your project is in development mode (

@rpq
rpq / django_settings_url_prefix.md
Last active December 12, 2015 07:59
needed a quick and easy way to prefix all urls in a django application for development

###in settings.py:

URL_PREFIX = "^prefixstring/"

###in the urls.py:

if settings.URL_PREFIX:
@rpq
rpq / gist:4986546
Created February 19, 2013 14:50
broken symbolic links and delete
#cred: http://www.trilithium.com/johan/2011/09/delete-broken-symlinks/
find -L ~/.local/bin/ -type l -delete
@rpq
rpq / gist:5646615
Created May 24, 2013 21:24
crazy errors
# Yes, this makes perfect sense.
TypeError: unbound method get_content_object() must be called with Item instance as first argument (got Item instance instead)
@rpq
rpq / gist:6939503
Created October 11, 2013 18:16
ajax spinner and django header
3 /** setup spinner on ajax calls **/
4 $.ajaxSetup({
5 headers: { "HTTP_X_REQUESTED_WITH": "XMLHttpRequest" },
6 cache: false,
7 error: function() {
8 alert('There was an error reaching the server!');
9 },
10 timeout: 10000,
11 beforeSend: function() {
12 $('#loading-status').show();
@rpq
rpq / gist:7282181
Created November 2, 2013 18:52
ruby 2.0 build fail
compiling pack.c
compiling parse.c
gcc: Internal error: Killed (program cc1)
Please submit a full bug report.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [parse.o] Error 1
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -ansi -std=iso9899:199409