This code is a sample for a question on Stackoverflow about making multisite user models with Django 1.7.
Add these lines to your settings file:
AUTH_USER_MODEL='s1.Member'
SITE_ID = 1
AUTHENTICATION_BACKENDS = ( 'MyApp.MyModule.MyModelBackend',)
// transform a list of names into an alphabet-keyed dictionary. | |
// e.g. input is | |
// | |
// var list = ["Elsie Chambers", "Gene Keller", "Glen Hall", "Lawrence Burke", "Lenora Robbins", "Lillian Stone", "Lucy Roberson", "Mario Curry", | |
// "Shawn Matthews", "Terry Joseph"] | |
// | |
// asAlphabetDictionary(list) => | |
// {"A":["Adrian Stanley"],"F":["Fred Houston"],"H":["Hilda Hart"], | |
// "I":["Irene Coleman"],"J":["Jeffery Castillo","Jon Floyd","Jonathan | |
// Conner"],"L":["Leon Higgins"],"N":["Nettie Jensen"],"S":["Sally |
from decimal import Decimal | |
from moneyed.classes import Money | |
from tastypie.fields import CharField, DecimalField | |
from tastypie.resources import ModelResource | |
from djmoney.models.fields import MoneyField as ModelMoneyField | |
class MoneyFieldMixin(object): | |
""" |
This code is a sample for a question on Stackoverflow about making multisite user models with Django 1.7.
Add these lines to your settings file:
AUTH_USER_MODEL='s1.Member'
SITE_ID = 1
AUTHENTICATION_BACKENDS = ( 'MyApp.MyModule.MyModelBackend',)
@task | |
def listlocaldbs(): | |
""" | |
list dbregistry in $HOME/dbregistry.txt | |
""" | |
registryfile = os.path.expanduser('~/dbregistry.txt') | |
with open(registryfile, 'r') as f: | |
print f.read() |
After reading Code Climate's Rails' Insecure Defaults I realized I was guilty of breaking rule 3. Versioned Secret Tokens. Here's how I fixed it.
Use dotenv in development and test environments:
# Gemfile
gem 'dotenv-rails', groups: [:development, :test]
# dokku remote command | |
function dz() { | |
case $1 in | |
push) | |
# top level git directory | |
LOCAL_BRANCH="$(git branch -l 2>/dev/null | grep '\*' | awk '{print $2}')" | |
if [ -d .git ]; then | |
echo "Pushing branch $LOCAL_BRANCH to dz master" | |
git push dz $LOCAL_BRANCH:master | |
else |
> inxi -S
System: Host: MY_HOSTNAME Kernel: 3.5.0-19-generic x86_64 (64 bit) Desktop: Gnome Distro: Linux Mint 14 Nadia
# find the commits you want to remove, e.g. using all commits that added or changed a file
$ git whatchanged -- path/to/file [...] > files.lst
$ git whatadded -- path/to/file [...] >> files.lst
# then do a rebase to get all commits that were added since then, including the ones you want to exclude
$ git rebase -i <commit>
# when rebase stops it will have created .git/rebase-merge/git-rebase-todo
# then do the following. this will take the commit ids from files.lst and
# remove every line in git rebase-todo
$ cat files.lst | cut -b1-7 | xargs -L1 -I {} sed -i '/{}/d' /home/patrick/projects/shrebo-ext/.git/rebase-merge/git-rebase-todo
# -*- coding: utf-8 -*- | |
# (c) 2014 one2seven GmbH, Switzerland | |
import urllib | |
import json | |
import sys | |
def geocode_by_osm(address): | |
""" | |
geocode an address using openstreet map | |
""" |
Currently there seem to be different ways for attached services. Some prefer to attach a service (e.g. rabbitmq) to a single app by default, while the dokku-link plugin allows one service to be linked to multiple apps. Also there are various ways for service plugins to name their environment variables. | |
This is to propose a standard for attached services, as follows. Ammendments, feedback and proposals welcome. | |
1. A service is a dokku-plugin that, upon plugin installation, builds a base image to run the service in its own container. | |
2. A service can be linked to any number of dokku apps, but it can also be created without any app specified (deferred linking). | |
3. When linked, the service is to expose its connection URL to app containers as a single environment variable that follows this dokku-args standard: `-e <SERVICE>_URL=<service>://<user>:<password>@<ip>[/<path>]`, where service is the service name (e.g. MYSQL, RABBITMQ etc.), user/password the access credentials or tokens, ip the linked container's addr |