Skip to content

Instantly share code, notes, and snippets.

View takluyver's full-sized avatar

Thomas Kluyver takluyver

View GitHub Profile
@takluyver
takluyver / html_resource_stuffer.py
Created January 19, 2018 15:08
Stuff JS and CSS into an HTML file
"""Fetch JS & CSS referenced from the web, and stuff it into the HTML."""
import lxml.html
import requests
IN_FILE = "Using Nbconvert.slides.html"
OUT_FILE = "Using Nbconvert.slides.stuffed.html"
document = lxml.html.parse(IN_FILE)
class CompleteAttrs(object):
def __getattr__(self, name):
if name == 'foo':
return 1
if name == 'bar':
return 2
raise AttributeError(name)
def __dir__(self):
return ['foo', 'bar'] + object.__dir__(self)
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[1;5D": backward-word
"\e[1;5C": forward-word
# I don't need pings as I tab complete things
set bell-style none
@takluyver
takluyver / mods.json
Last active October 19, 2017 14:00
Unrecognised stdlib modules
{
"notfiles": [
"_ast",
"_codecs",
"_collections",
"_functools",
"_imp",
"_io",
"_locale",
"_operator",
@takluyver
takluyver / qtconsole_interrupt.ipynb
Created October 10, 2017 11:10
Qtconsole crashing on interrupt
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takluyver
takluyver / gist:2682c5333e10934218c7e6baa04f2eda
Created July 16, 2017 14:38
rapid-router py3 test failures
======================================================================
ERROR: test_multiple_levels (game.tests.test_scoreboard.ScoreboardCsvTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/takluyver/Code/rapid-router/game/tests/test_scoreboard.py", line 203, in test_multiple_levels
actual_header, actual_rows = self.actual_data(response.content)
File "/home/takluyver/Code/rapid-router/game/tests/test_scoreboard.py", line 270, in actual_data
split = content.split("\r\n")
TypeError: a bytes-like object is required, not 'str'
@takluyver
takluyver / gist:edcfd25c64875a947158b19b2bbb21cb
Created July 16, 2017 14:34
Traceback from codeforlife-portal
ERROR:root:Exception occurred while handling GET request to /portal/admin/map/
Traceback (most recent call last):
File "/home/takluyver/miniconda3/envs/rr-py3/lib/python3.6/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/takluyver/miniconda3/envs/rr-py3/lib/python3.6/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/takluyver/miniconda3/envs/rr-py3/lib/python3.6/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
if test_func(request.user):
File "/home/takluyver/miniconda3/envs/rr-py3/lib/python3.6/site-packages/django/contrib/auth/decorators.py", line 71, in check_perms
raise PermissionDenied
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takluyver
takluyver / myexporter.py
Last active June 1, 2017 21:18
Pass extra variables to nbconvert template
# Pass an extra variable to an nbconvert template
# Untested
from nbconvert.exporters import HTMLExporter
class MyExporter(HTMLExporter):
def from_notebook_node(self, nb, resources=None, my_var=None, **kw):
self.environment.globals['my_var'] = my_var
return super().from_notebook_node(nb, resources=resources, **kw)
@takluyver
takluyver / gist:08fb5894286470c5b156f3f5835eb1fd
Created May 30, 2017 13:13
Errors from cwltool 'make test'
$ make test
./setup.py test
running pytest
Searching for typing<3.6,>=3.5.2
Best match: typing 3.5.3.0
Processing typing-3.5.3.0-py2.7.egg
Using /home/takluyver/Code/cwltool/.eggs/typing-3.5.3.0-py2.7.egg
Searching for schema-salad<3,>=2.4.20170308171942
Best match: schema-salad 2.5.20170428142041