Skip to content

Instantly share code, notes, and snippets.

View davidmashburn's full-sized avatar

David Mashburn davidmashburn

  • Pluralsight, LLC
  • Boston, MA
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidmashburn
davidmashburn / fancy_indexing.py
Created August 24, 2019 00:45
Fancy Indexing (simplified version)
def _make_fancy(*args, **kwds):
return (fancyIndexingDict(*args, **kwds)
if len(kwds) or (len(args) and hasattr(args[0], 'keys')) else
fancyIndexingList(*args, **kwds))
def _fancy_getitem(fancy_x, index):
index = index if hasattr(index, '__iter__') else (index, )
index = index if type(index) is tuple else tuple(index)
if isinstance(fancy_x, fancyIndexingDict):
@davidmashburn
davidmashburn / gist:2a9d88409ce18aab68992385457f0ba6
Created September 26, 2018 16:58
Gently restart Gnome Shell
# Command to run in TTY (Ctrl-Alt-F5 or similar)
# Found this little gem on https://bugs.launchpad.net/ubuntu/+source/mutter/+bug/1181666
dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
@davidmashburn
davidmashburn / jupyter_setup.sh
Created March 11, 2018 16:53
Generate .desktop-style launchers for Jupyter that allow you to one-click into a fresh shell + other Jupyter config
# I miss the simplicity of launching a fresh shell when using Jupyter
# This is my wonderfully weird way of fixing that (at least on Linux)
# Config and desktop integration:
jupyter notebook --generate-config
echo "
import os
from subprocess import check_call
@davidmashburn
davidmashburn / gist:9764309
Last active August 29, 2015 13:57
genericSlice
def genericSlice(length,start=None,stop=None,step=None,includeStop=False,oneBased=False,checkBounds=False):
'''A generic version of "slice" supporting:
* dropping or keeping the stop value
* 0-based and 1-based indexing
* optional bounds checking
* +/-/None indexes (as usual)
Requires the length of the list that will be sliced.
Returns a slice object.