Skip to content

Instantly share code, notes, and snippets.

@mx-moth
mx-moth / m2m.py
Last active August 3, 2016 00:22 — forked from alexgleason/m2m.py
Many to many relationships in Wagtail
from django.db import models
from wagtail.wagtailsnippets.models import register_snippet
from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.edit_handlers import InlinePanel
@register_snippet
class Category(models.Model):
"""
@mx-moth
mx-moth / update-prs.sh
Created December 12, 2015 02:02
Automatically rebase a collection of branches on upstream/master, run the tests, and push to origin if the tests pass
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
upstream='upstream/master'
if ! ( git diff --exit-code && git diff --cached --exit-code ) ; then
echo "Working tree is dirty, aborting"
exit 1
#!/bin/bash
# A dodgy ripoff of rsync for my music files
#
# Usage: To copy the contents of "Zechs Marquise/Getting Paid/" and "Grails/"
# from your music library to your mounted phone:
#
# syncdir --source $HOME/Music \
# --destination /mnt/phone/Music \
# "Zechs Marquise/Getting Paid/" \
# "Grails/"
@mx-moth
mx-moth / blog_post.html
Created October 14, 2015 09:54
Thoughts on Wagtail image resizing
<h2>{{ page.title }}</h2>
{# As 'header' is in 'sizes' for BlogPost.feature_image, this rendition will be already present #}
{% image page.feature_image header %}
{# Can also use any old filter here, does not need to be one of 'sizes', or a nickname #}
{% image page.feature_image height-200 %}
{{ page.body }}
from django.template import Node, TemplateSyntaxError
from django.template.library import parse_bits, Library
from django.shortcuts import render_to_string
register = Library()
class Button(Node):
"""
Usage::
@mx-moth
mx-moth / shell.log
Last active August 29, 2015 14:21
nvim and git add --patch do not play nice
Script started on Wed 27 May 2015 12:44:03 AEST
test@nightjar:~$ export EDITOR=nvim
test@nightjar:~$ export VISUAL=nvim
test@nightjar:~$ env
XDG_VTNR=1
XDG_SESSION_ID=3
COMP_WORDBREAKS=
"'><;|&(:
SHELL=/bin/bash
TERM=screen-256~color
@mx-moth
mx-moth / models.py
Created February 16, 2015 23:15
Wagtail view proxy
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin
from wagtail.wagtailcore.models import Page
from .viewproxy import ViewModuleProxy
views = ViewModuleProxy('myapp.views')
class MyPage(Page):
serve = views.mypage
class MyRoutablePage(RoutablePageMixin, Page):
@mx-moth
mx-moth / notes.rst
Last active March 29, 2018 09:50
Wagtail setup thoughts

Initial setup for Wagtail

Similar to the Wordpress install, adapted for Wagtail. Runs for superusers when they log in to the admin.

Things that need setting up

Keybase proof

I hereby claim:

  • I am mx-moth on github.
  • I am tim_heap (https://keybase.io/tim_heap) on keybase.
  • I have a public key whose fingerprint is DEDD 4853 A4B8 C769 239E 093F EA85 6746 0ACC B8C2

To claim this, I am signing this object:

@mx-moth
mx-moth / rev-sax.js
Created May 8, 2014 05:05
Reverse sax parser
"use strict";
function processNodeList(list, target) {
list.forEach(function(node) {
processNode(node, target);
});
}
function processNode(node, target) {
switch (node._type) {