The way this works is that for each notebook, jupyter starts a python "kernel" process that actually runs the notebook's code. That kernel gets a json file with info on the notebook's location on the disk passed through its command line. Since we're running code in that exact python process, we can just grab that json file from sys.argv, and read it ourselves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
def deltaify(list_of_tuples): | |
return list_of_tuples[0], [ tuple( b-a for a,b in zip(tup1, tup2) ) for tup1, tup2 in zip(list_of_tuples[:-1], list_of_tuples[1:]) ] | |
smallest_format = lambda num: 'b' if num < 2**7 else 'h' if num < 2**15 else 'i' if num < 2**31 else 'q' | |
make_format = lambda es: ''.join(smallest_format(e) for e in es) | |
def pack(list_of_tuples): | |
offx, deltas = deltaify(list_of_tuples) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Modified cd that also displays the directory's contents if the listing is less than 5 lines long | |
function cd | |
if test -n "$argv" | |
if test -e $argv -a ! -d (realpath $argv) | |
set argv (dirname $argv) | |
end | |
end | |
builtin cd $argv | |
and test (ls -C -w $COLUMNS |wc -l) -le 5; and ls | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding: utf-8 | |
import csv | |
import argparse | |
avm_xml_template = '''<?xml version="1.0" encoding="utf-8"?> | |
<phonebooks> | |
<phonebook> | |
{entries} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import re | |
pinyinToneMarks = { | |
u'a': u'āáǎà', u'e': u'ēéěè', u'i': u'īíǐì', | |
u'o': u'ōóǒò', u'u': u'ūúǔù', u'ü': u'ǖǘǚǜ', | |
u'A': u'ĀÁǍÀ', u'E': u'ĒÉĚÈ', u'I': u'ĪÍǏÌ', | |
u'O': u'ŌÓǑÒ', u'U': u'ŪÚǓÙ', u'Ü': u'ǕǗǙǛ' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import ctypes | |
import gi | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gtk, GLib | |
gi.require_version('GL', '1.0') | |
from OpenGL import GL, GLX |
OlderNewer