Skip to content

Instantly share code, notes, and snippets.

View miraculixx's full-sized avatar
💭
working on https://github.com/omegaml

miraculixx

💭
working on https://github.com/omegaml
  • Switzerland
View GitHub Profile
@miraculixx
miraculixx / README.md
Last active August 29, 2015 14:10 — forked from muratcorlu/README.md

This code is a sample for a question on Stackoverflow about making multisite user models with Django 1.7.

Usage:

Add these lines to your settings file:

AUTH_USER_MODEL='s1.Member'
SITE_ID = 1
AUTHENTICATION_BACKENDS = ( 'MyApp.MyModule.MyModelBackend',)
@miraculixx
miraculixx / fabfile.util
Last active August 29, 2015 14:11
with inputfile for temporary file content
@task
def listlocaldbs():
"""
list dbregistry in $HOME/dbregistry.txt
"""
registryfile = os.path.expanduser('~/dbregistry.txt')
with open(registryfile, 'r') as f:
print f.read()
@miraculixx
miraculixx / README.md
Last active August 29, 2015 14:11 — forked from cjolly/README.md

Stop Versioning Rails Secret Tokens

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]
@miraculixx
miraculixx / dz
Created December 19, 2014 18:38
dockrzone client command
# 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
@miraculixx
miraculixx / README.md
Created December 20, 2014 00:53
useful bash commands
  • Which version of Mint am I running?
> inxi -S
System:    Host: MY_HOSTNAME Kernel: 3.5.0-19-generic x86_64 (64 bit) Desktop: Gnome Distro: Linux Mint 14 Nadia
@miraculixx
miraculixx / README.md
Created December 27, 2014 14:42
find and remove specific git commits using rebase
# 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
@miraculixx
miraculixx / geocode.py
Last active August 29, 2015 14:12
get lat, long of an address from the command line or in Python. Returns a JSON encoded string.
# -*- 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
"""
@miraculixx
miraculixx / gist:7558712cb442e1b85a6c
Last active August 29, 2015 14:12
Draft dokku service spec
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
@miraculixx
miraculixx / clienttrace.py
Last active August 29, 2015 14:12
Print Django test Client and Tastypie ApiClient traces
class ClientRequestTracer(object):
"""
Trace api calls to a test client
Usage:
self.client = ClientRequestTracer(self.client)
self.api_client = ClientRequestTracer(self.api_client)
Limit the traces by giving parameter traces=[...] list of
strings 'get', 'post', 'put'
@miraculixx
miraculixx / cachereq.py
Created January 10, 2015 01:14
Cacheable URL retriever for Django
"""
(c) 2015 github.com/miraculixx
MIT License
Cacheable URL getter for Django
Uses Django's cache framework to cache responses with the same URL.
Usage:
url = 'http://www.domain.com/static/content'