Skip to content

Instantly share code, notes, and snippets.

Luke Plant spookylukey

Block or report user

Report or block spookylukey

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
spookylukey / ast.diff
Created Jan 25, 2019
Beginnings of a patch to use Python AST for compiling
View ast.diff
diff --git a/fluent.runtime/fluent/runtime/ b/fluent.runtime/fluent/runtime/
index f00f750..b76b147 100644
--- a/fluent.runtime/fluent/runtime/
+++ b/fluent.runtime/fluent/runtime/
@@ -3,6 +3,7 @@ Utilities for doing Python code generation
from __future__ import absolute_import, unicode_literals
+import ast
import keyword
spookylukey / Confirm.js
Created Sep 19, 2018
Elm 0.18 confirm Task
View Confirm.js
// Native/Confirm.js
var _user$project$Native_Confirm = function () {
var scheduler = _elm_lang$core$Native_Scheduler;
function confirmTask(prompt, successValue, failValue) {
return scheduler.nativeBinding(function (callback) {
if (window.confirm(prompt)) {
} else {
spookylukey /
Created Sep 27, 2017
Hollerith constant parsing in pyparsing
import pyparsing as pp
def hollerith():
intExpr = pp.Word(pp.nums).setParseAction(lambda t: int(t[0]))
stringExpr = pp.Forward()
def countedParseAction(toks):
n = toks[0]
contents = pp.CharsNotIn('', exact=n)
stringExpr << (pp.Suppress(pp.CaselessLiteral('H')) + contents)
spookylukey / convert_leading_spaces_to_en
Created Jun 22, 2017
Make source code readable on forums that have poor support
View convert_leading_spaces_to_en
#!/usr/bin/env python3
import sys
def fix_line(l):
if not l:
return l
if l[0] == " ":
# Non breaking: "\u00a0" - but munged by some browsers
# EM space: "\u2003" - not munged by browsers
# If it's complex, Django's Generic CBVs will probably
# make your life harder. And if it's simple, they probably
# will too.
# Before:
from django.views import generic
class ReportPDFDetailView(generic.DetailView):
model = DesignerReport
spookylukey / stackoverflow_docs_no_thanks.rst
Last active Jan 31, 2017
Stackoverflow docs no thanks (at least for Django)
View stackoverflow_docs_no_thanks.rst

I'm talking about this:

Compared to well written documentation, this kind of documentation is pretty bad. Yes, many projects have terrible documentation, and for them it might be an improvement, but for many that have good docs, this is a major step backwards.

Good documentation requires serious effort and organisation. It can't be achieved by throwing together lots of examples.

View two_forms_one_view.txt
# Views
def two_form_view(request):
context = {}
if request.method == "POST":
question_form = QuestionForm(request.POST)
answer_form = AnswerForm(request.POST)
success = False
if 'q_button' in request.POST and question_form.is_valid()
spookylukey / gist:fc9fa268de67fd19a567
Last active Aug 29, 2015
How to post code snippets (especially Python) into comment systems that don't preserve whitespace
View gist:fc9fa268de67fd19a567
#!/usr/bin/env python
# How to post code snippets (especially Python) into comment systems
# that don't preserve whitespace.
# Save this as a script called 'convert_leading_spaces_to_nonbreaking'
# in your PATH and do "chmod +x" on it.
# In Linux, you can then use it by installing xsel and doing:
spookylukey / gist:36acb563acd54fc3ddf0
Created Dec 11, 2014
Bug with Django migrations - migrations created with Python 2 need 'fixing' when run with Python 3
View gist:36acb563acd54fc3ddf0
$ mkdir bugtest
$ cd bugtest
$ virtualenv --python=python2.7 env_p27
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in env_p27/bin/python2.7
Also creating executable in env_p27/bin/python
Please make sure you remove any previous custom paths from your /home/luke/.pydistutils.cfg file.
Installing setuptools, pip...done.
$ source env_p27/bin/activate
View gist:33d497dfab74ead527d0
Firefox dev console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at This can be fixed by moving the resource to the same domain or enabling CORS.
Chrome dev console:
XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access. The response had HTTP status code 503.
You can’t perform that action at this time.