Skip to content

Instantly share code, notes, and snippets.

View bsdz's full-sized avatar

Blair Azzopardi bsdz

View GitHub Profile
@bsdz
bsdz / 00-debugger-setup.py
Last active March 23, 2018 08:06
How to remotely debug jupyter notebooks using pydev in Eclipse
"""
This script enables step-by-step debugging of jupyter notebooks remotely
from pydev in Eclipse. Save this script to your ipython startup folder. You
can find this by running the following in a notebook cell:
get_ipython().profile_dir.startup_dir
To trigger a breakpoint, start up pydevs remote debugging server and then
insert the following code where you wish the breakpoint to start:
@bsdz
bsdz / unittest_numpy_extensions.py
Created April 1, 2018 09:46
How to inject wrapped numpy test assertions into unittest namespace
""" monkey patch unittest to include numpy assertions.
Maps numpy assert_func_name to numpyAssertFuncName.
Example:
class NumpyWrapperTest(unittest.TestCase):
def test_allclose_example(self):
a1 = np.array([1.,2.,3.])
self.numpyAssertAllclose(a1, np.array([1.,2.,3.1]))
@bsdz
bsdz / 10-python-markdown-magic.py
Last active July 8, 2018 11:11
Emulate python-markdown jupyter extension with a magic that also works in jupyter lab.
"""
This script enables python variables to be formatted in markdown. Similar
to python-markdown. Save this script to your ipython startup folder. You
can find this by running the following in a notebook cell:
get_ipython().profile_dir.startup_dir
To use:
foo = "some python value"
@bsdz
bsdz / jupyter_browser_clipboard.py
Last active November 10, 2023 09:32
Jupyter - Copy to clipboard via browser's clipboard
"""Copy text in remote Jupyter sessions.
Copy text to OS clipboard when using Jupyter remotely. Uses web browsers
clipboard via Javascript.
NOTE: also available as extension. not suitable for large data, e.g df with 100k rows.
"""
from IPython.display import HTML
@bsdz
bsdz / logprof.py
Last active July 14, 2023 12:08
Simple python module for logging times of function or context
import logging
import resource
from contextlib import ContextDecorator
from time import perf_counter_ns
class logprof(ContextDecorator):
def __init__(self, label, logger=None, **kwds):
self.label = label
self.logger = logger or logging.getLogger(__name__)