Skip to content

Instantly share code, notes, and snippets.

Thomas Kluyver takluyver

Block or report user

Report or block takluyver

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
@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 / 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 / 2to3_nb.py
Last active Jul 15, 2019
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 / 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.

@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):
@takluyver
takluyver / atomicity_issue_pull.py
Created Dec 7, 2018
Pyzmq multipart atomicity issue
View atomicity_issue_pull.py
import os
from time import monotonic
import zmq
# Set up a PULL socket
ctx = zmq.Context()
sock = ctx.socket(zmq.PULL)
sock.set_hwm(1)
sock.connect("tcp://127.0.0.1:8541")
@takluyver
takluyver / pull.py
Created Dec 7, 2018
ZMQ push/pull HWM experiment
View pull.py
import zmq
# Set up the socket
ctx = zmq.Context()
sock = ctx.socket(zmq.PULL)
sock.set_hwm(1)
sock.setsockopt(zmq.RCVBUF, 16 * 1024)
sock.connect("tcp://127.0.0.1:8541")
print("RCVHWM", sock.getsockopt(zmq.RCVHWM))
You can’t perform that action at this time.