Skip to content

Instantly share code, notes, and snippets.

@takluyver
takluyver / 2to3_nb.py
Last active Jun 20, 2020
Run 2to3 on IPython notebooks
View 2to3_nb.py
#!/usr/bin/env python3
"""
To run: python3 nb2to3.py notebook-or-directory
"""
# Authors: Thomas Kluyver, Fernando Perez
# See: https://gist.github.com/takluyver/c8839593c615bb2f6e80
import argparse
import pathlib
from nbformat import read, write
@takluyver
takluyver / make_nb.py
Created Jul 21, 2016
Make a notebook from a script
View make_nb.py
"""Create a notebook containing code from a script.
Run as: python make_nb.py my_script.py
"""
import sys
import nbformat
from nbformat.v4 import new_notebook, new_code_cell
nb = new_notebook()
@takluyver
takluyver / asyncio_magic.py
Created Jan 25, 2016
Cell magic for 'await' expressions in IPython
View asyncio_magic.py
# (c) Thomas Kluyver, 2016
# Use it under the MIT license
# This is fairly experimental. Use at your own risk.
import ast
from ast import Call, Attribute, Name, Load
import asyncio as asyncio_mod
#import astpp
from IPython.utils.text import indent
@takluyver
takluyver / README.md
Created Sep 6, 2014
Flatten notebooks for git diff
View README.md

Copy nbflatten.py to somewhere on $PATH. Then, in the root of a git repository, run these commands:

echo "*.ipynb diff=ipynb" >> .gitattributes 
git config diff.ipynb.textconv nbflatten.py

When you change a notebook and run git diff, you'll see the diff of flattened, simplified notebooks, rather than the full JSON. This does lose some information (metadata, non-text output), but it makes it easier to see simple changes in the notebook.

This doesn't help with merging conflicting changes in notebooks. For that, see nbdiff.org.

View GPL_EXCEPTION.txt
Riverbank GPL Exception version 1.1
===================================
Additional rights granted beyond the GPL (the "Exception").
As a special exception to the terms and conditions of version 2.0 of the GPL,
Riverbank hereby grants you the rights described below, provided you agree to
the terms and conditions in this Exception, including its obligations and
restrictions on use.
@takluyver
takluyver / cache_format_options.py
Created Aug 27, 2019
Karabo data cache format experimentation
View cache_format_options.py
import json
import h5py
import numpy as np
def read_json(path):
with open(path) as f:
loaded_data = json.load(f)
res = {}
for info in loaded_data:
@takluyver
takluyver / VDS issue.ipynb
Created Apr 9, 2019
HDF5 virtual dataset access issue
View VDS issue.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takluyver
takluyver / example
Created May 13, 2016
Debug on interrupt
View example
$ python3 interrupt-debug.py
0
1
2
3
^C--Return--
> /home/takluyver/scratch/interrupt-debug.py(6)handle_sigint()->None
-> pdb.set_trace()
(Pdb) p a
4
View ipytables.py
class TableCell(object):
bg_colour = None
def __init__(self, value, header=False, bg_colour=None, text_colour=None):
self.value = value
self.header = header
self.bg_colour = bg_colour
self.text_colour = text_colour
def _make_css(self):
You can’t perform that action at this time.