Skip to content

Instantly share code, notes, and snippets.

View doismellburning's full-sized avatar
🔥

Kristian Glass doismellburning

🔥
View GitHub Profile
@doismellburning
doismellburning / README.md
Created December 10, 2014 17:02
Example 12factor settings.py

Notes

  • This is literally copied from code I have in production, with nearly no modification other than trimming the stock settings
  • Yes I use the globals().update() method that d12f recommends against - given I am the author/maintainer, I'm probably qualified to do this
@doismellburning
doismellburning / grrdaemontools.md
Last active August 29, 2015 14:11
Sodding Daemontools
$ svc -t /goat
svc: warning: unable to chdir to /goat: file does not exist
$ echo $?
0

Well ok, maybe I'm missing a command line argument and it's just a crap default?

Django idiolect - Apps and Projects

What Django calls an "app", most people would call a "library" or "plugin".

What most people would call an "app", Django calls a project.

Yes this gets confusing.

Static files in non-templated JS without using STATIC_URL

Potential solutions:

HTML data attributes

Easy, not that grim code-wise, but lots of duplication. You end up "naming" each static file, so you end up with something like:

{% load static from staticfiles %}
from django.conf import settings
class TemplateCheckerMiddleware(object):
def process_template_response(self, request, response):
if settings.DEBUG:
for k,v in response.context.iteritems(): # Probably does the right thing; ymmv
if v == settings.TEMPLATE_STRING_IF_INVALID:
raise SomeSortOfUsefulException(k)
return response
server {
listen {{ proxy_port }};
location / {
proxy_pass https://{{ elasticsearch_host }}/;
proxy_set_header Host {{ elasticsearch_host }};
}
}

Antelope v2 depends on Badger>1,<4 Badger has v1,v2,v3,v4 and no dependencies

If you have nothing installed:

  • pip install Antelope==2 will leave you with Antelope v2, Badger v3
  • pip install --upgrade Antelope==2 will exhibit the same behaviour

If you have Badger v1 installed:

from django.apps import apps
from django.template import Library
register = Library()
_static = None
@register.simple_tag
def static(path):

WSGI is a protocol/interface, that (roughly) describes translation between HTTP requests/responses and Python

This is similar to Java's Servlet specification, or the CGI spec.

uWSGI is a webserver that implements 'the server side of' WSGI, i.e. it takes HTTP requests and turns them into Python request objects, passes them off to whatever code you're running with it, gets a Python response object back, and returns it as an HTTP response.

Do not confuse uWSGI with WSGI. Other WSGI webservers exist, e.g. gunicorn, or apache+mod_wsgi.

#!/bin/bash -x
# Very very hacky, I'm so sorry
TYPE=$1
PROCFILE="./Procfile"
# TODO More getopts
if [ -z $TYPE ]