Skip to content

Instantly share code, notes, and snippets.

View stefanfoulis's full-sized avatar

Stefan Foulis stefanfoulis

View GitHub Profile
[tool.poetry]
name = "app"
version = "0.1.0"
description = ""
authors = ["None"]
[tool.poetry.dependencies]
python = "3.6"
hyper = "^0.7.0"
cryptography = "^2.3"
@stefanfoulis
stefanfoulis / how_it_work.rst
Created July 19, 2011 07:06
An example nginx conf for mogilefs and gunicorn

Private media

Browser accesses URL of Application:

http://www.example.com/private_media/my_file.pdf

The Permissions are checked by the application backend. If Access is denied the application backend returns a 403 and thats the end of it.

@stefanfoulis
stefanfoulis / key_requirements_compare.py
Created November 7, 2017 10:40
Helpers to compare settings and requirements when migrating from a regular project to a divio cloud project
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pip
import pip.req
import uuid
# from pprint import pprint as pp; import key_requirements_compare; reload(key_requirements_compare); compared=key_requirements_compare.tst(); print(len(compared['old']))
test_basic (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_basic_quoting (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_path_normalization (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_percent_encode_non_s3 (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_percent_encode_s3 (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_querystring (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_basic (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_multiple_params (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_quoting (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_space (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
@stefanfoulis
stefanfoulis / README.md
Created September 13, 2016 10:06
Snippets for an eventual better django-dbcache app

django-dbcache

A django cache backend that treats the db cache as a first class citizen.

The cache backend in django.core.cache.backends.db only works on the default database connection. Using the same connection as for regular model access can cause weird transaction related deadlocks and similar

@stefanfoulis
stefanfoulis / 0001_old_migration.py
Last active June 13, 2016 08:38
reliably upgrading my plugins to the new django-cms 3.0 table names
"""
Do not rename the table for plugins in the first "create" migration.
OR: if you do... make the create table statement only run if the table does not already exist.
"""
class Migration():
def forwards(self, orm):
# ...
# -*- coding: utf-8 -*-
from waffle import TEST_COOKIE_NAME, flag_is_active
from waffle.middleware import WaffleMiddleware
# FIXME: only works if TEST_COOKIE_NAME ends with the flag name
TEST_COOKIE_PREFIX = TEST_COOKIE_NAME.split('%s')[0]
class AlwaysWaffleMiddleware(WaffleMiddleware):
# -*- coding: utf-8 -*-
"""Refactor South migrations to use settings.AUTH_USER_MODEL.
Inserts a backwards-compatible code-snippet in all
your schema migration files and uses a possibly customized user
model as introduced in Django 1.5.
Please note that this has nothing to do with changing
settings.AUTH_USER_MODEL to a new model. If you do this, stuff
will very likely break in reusable apps that have their own
migration trees.
@stefanfoulis
stefanfoulis / gist:5464012
Created April 25, 2013 23:13
super simple hacky multilingual
# -*- coding: utf-8 -*-
from django.utils.translation import get_language, activate, deactivate_all, deactivate
class LanguageFieldProxy(object):
def contribute_to_class(self, cls, name):
self.name = name
setattr(cls, self.name, self)
def __get__(self, instance, instance_type=None):
@stefanfoulis
stefanfoulis / gist:5218064
Created March 22, 2013 00:34
Ugly as hell quick and dirty script to automatically add github notifications for a list of projects to hipchat and to create a room per project based on a naming convention.
# -*- coding: utf-8 -*-
import requests
import json
import pprint
from secrets import hipchat_api_key # the hipchat API key with admin rights
from secrets import github_credentials # a tuple for github access (github_username, password),
from secrets import hipchat_notification_api_key # the hipchat API key to use for the notification hooks on github
hipchat_apps_room_name = 'Divio Application Suite'