Skip to content

Instantly share code, notes, and snippets.

View alexander-ae's full-sized avatar

Alexander alexander-ae

View GitHub Profile
== Development Approaches
Asshole Driven development (ADD) - Any team where the biggest jerk makes all the big decisions is asshole driven development. All wisdom, logic or process goes out the window when Mr. Asshole is in the room, doing whatever idiotic, selfish thing he thinks is best. There may rules and processes, but Mr. A breaks them and people follow anyway.
Cognitive Dissonance development (CDD) - In any organization where there are two or more divergent beliefs on how software should be made. The tension between those beliefs, as it's fought out in various meetings and individual decisions by players on both sides, defines the project more than any individual belief itself.
Cover Your Ass Engineering (CYAE) - The driving force behind most individual efforts is to make sure than when the shit hits the fan, they are not to blame.
Development By Denial (DBD) - Everybody pretends there is a method for what's being done, and that things are going ok, when in reality, things are a mess and th
import re
class ReDict(dict):
def __setitem__(self, key, value):
dict.__setitem__(self, re.compile(key), value)
def __getitem__(self, key):
return [v for k,v in self.items() if k.match(key)]
@vicalejuri
vicalejuri / django-crossdomainxhr-middleware.py
Created June 5, 2010 17:47
Middlware to allow's your django server to respond appropriately to cross domain XHR (postMessage html5 API).
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
@inky
inky / convert_nfo.py
Created July 11, 2010 13:01
Convert a file from UTF-8 to CP437.
#!/usr/bin/env python
import codecs, sys
try:
infile, outfile = sys.argv[1], sys.argv[2]
except IndexError:
sys.stderr.write('usage: %s input_file output_file\n' % sys.argv[0])
sys.exit(1)
nfo = codecs.open(infile, encoding='utf-8').read()
codecs.open(outfile, 'w', encoding='cp437').write(nfo)
@vsajip
vsajip / ansistrm.py
Created December 29, 2010 11:14
Python logging: colourising terminal output
#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
import ctypes
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
@dokterbob
dokterbob / fields.py
Created March 18, 2011 19:07
Email field with domain existence validation for Django.
import logging
logger = logging.getLogger(__name__)
# Note: we need dnspython for this to work
# Install with `pip install dnspython`
import dns.resolver, dns.exception
from django import forms
from django.utils.translation import ugettext as _
@remcoder
remcoder / build_less.py
Created July 24, 2011 13:06
Compile LESS to CSS automatically whenever a file is modified
#!/usr/bin/env python
# determines filename and extension, then delegates compiling the LESS files to lessc via a shell command
import sys, os.path
from subprocess import call
src = sys.argv[1]
base,ext = os.path.splitext(src)
@vstoykov
vstoykov / force_default_language_middleware.py
Last active June 6, 2024 10:51
Force Django to use settings.LANGUAGE_CODE for default language instead of request.META['HTTP_ACCEPT_LANGUAGE']
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
class ForceDefaultLanguageMiddleware(MiddlewareMixin):
"""
Ignore Accept-Language HTTP headers
@strogonoff
strogonoff / middleware.py
Created November 16, 2011 08:56
Django middleware for cross-domain XHR. WARNING: Defaults are unsafe here. Make sure to set proper restrictions in production!
from django import http
try:
from django.conf import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS = settings.XS_SHARING_ALLOWED_METHODS
XS_SHARING_ALLOWED_HEADERS = settings.XS_SHARING_ALLOWED_HEADERS
XS_SHARING_ALLOWED_CREDENTIALS = settings.XS_SHARING_ALLOWED_CREDENTIALS
except AttributeError:
XS_SHARING_ALLOWED_ORIGINS = '*'
@ejamesc
ejamesc / gist:1450495
Created December 9, 2011 06:38
Supervisord conf to daemonize Mongodb
[program:mongodb]
directory=/home/username/webapps/appname
command=/home/username/webapps/mongodb-appname/mongodb-linux-i686-2.0.1/bin/mongod --dbpath /home/username/webapps/mongodb-appname/data --logpath /home/username/webapps/mongodb-appname/log/corsdb.log --logappend --port 34006