Skip to content

Instantly share code, notes, and snippets.

Neal Todd nealtodd

Block or report user

Report or block nealtodd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nealtodd
nealtodd / wagtail-on-zappa.md
Last active May 29, 2019 — forked from tomdyson/wagtail-on-zappa.md
Wagtail on AWS Lambda, with Zappa
View wagtail-on-zappa.md

Wagtail on AWS Lambda, with Zappa

Aim

A demonstration of Wagtail running on AWS Lambda + API Gateway using Zappa for deployment.

This is not a Production solution, it is an insecure setup focusing solely on getting Wagtail to run on Lambda in the simplest way possible (and at zero cost if it is not used beyond this demonstration (or close to zero depending on how much you exercise the S3 bucket)).

caveat emptor!

@nealtodd
nealtodd / decorator.py
Created Apr 25, 2012
Python profiling decorator
View decorator.py
from cProfile import Profile
import pstats
def profile(sort_args=['cumulative'], print_args=[10]):
profiler = Profile()
def decorator(fn):
def inner(*args, **kwargs):
result = None
@nealtodd
nealtodd / gist:a8f87b0d95e73eb482c5
Created Jun 10, 2015
Django management command to detect missing migration files.
View gist:a8f87b0d95e73eb482c5
import sys
from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import ProjectState
from django.db.utils import OperationalError
@nealtodd
nealtodd / deletable_objects_snippet.py
Last active Nov 20, 2018
Django helper for showing related objects that would be cascade deleted on deletion of an object.
View deletable_objects_snippet.py
from django.conf import settings
from django.db.models.deletion import Collector
from django.db.utils import ConnectionRouter
def deletable_objects(obj):
"""
Return a generator that yields (model, instance) tuples
of instances related to obj (including obj itself).
Essentially, programmatic access to the data Django Admin
@nealtodd
nealtodd / settings_test_snippet.py
Last active Oct 26, 2016
Skip migrations for a Django 1.7 test run
View settings_test_snippet.py
# If your test settings file doesn't import any other settings file
# then you can use the function directly:
def prevent_tests_migrate(db):
import django
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
django.setup()
ma = MigrationExecutor(connections[db]).loader.migrated_apps
return dict(zip(ma, ['{a}.notmigrations'.format(a=a) for a in ma]))
@nealtodd
nealtodd / package_dev.sh
Last active Jul 6, 2016
Debugging / testing a third party package without hacking the pip installed version
View package_dev.sh
cd somewhere
git clone https://github.com/[OWNER]/[REPO].git --branch [SPECIFIC BRANCH] --single-branch
cd [REPO]
python setup.py develop
# Usually, restart dev server to prevent it using already loaded site-packages modules.
# Hack away on code in [REPO], python will use this one rather than the one in site-packages.
# When done, to switch back:
python setup.py develop --uninstall
cd ..
rm -rf [REPO]
View gist:6883345

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@nealtodd
nealtodd / u2v.py
Last active Dec 23, 2015
Django management command: Take a fully qualified URL and show the resolved view (accounting for decorators on the view).
View u2v.py
from textwrap import dedent
from urlparse import urlparse
from django.core.management.base import BaseCommand
from django.core.urlresolvers import resolve, Resolver404
class Command(BaseCommand):
"""
Take a fully qualified URL and show the resolved view
@nealtodd
nealtodd / minimumrequiredformset.py
Created Jul 2, 2013
Django formset for validating a minimum number of filled out forms.
View minimumrequiredformset.py
from django import forms
class MinimumRequiredFormSet(forms.models.BaseInlineFormSet):
"""
Inline formset that enforces a minimum number of non-deleted forms
that are not empty
"""
default_minimum_forms_message = "At least %s set%s of data is required"
@nealtodd
nealtodd / wiibot.py
Last active Dec 17, 2015
Subclass of WiimoteConnect for controlling a real Pi-driven Lego-based forklift truck.
View wiibot.py
import piface.pfio as pfio
from wiimote import WiimoteConnect
class WiiBot(WiimoteConnect):
"""
Use Wiimote to control robot
Basic usage:
from wiibot import WiiBot
You can’t perform that action at this time.