Skip to content

Instantly share code, notes, and snippets.

@nilreml
Last active September 7, 2024 10:36
Show Gist options
  • Save nilreml/7cfa6d1f6d974a74a59073c0d65a9f6a to your computer and use it in GitHub Desktop.
Save nilreml/7cfa6d1f6d974a74a59073c0d65a9f6a to your computer and use it in GitHub Desktop.
# Display all cell outputs
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
# Rich print
import rich.console
print = rich.console.Console(force_jupyter=False, width=220).print
# Render markdown/svg cells:
from IPython.display import display, Markdown, SVG
# display(Markdown(...)) # e.g. df.to_markdown()
# display(SVG(...))
# Pretty print tensors:
import lovely_tensors as lt
lt.lovely(...)
# Pretty print XML:
from pygments import highlight
from pygments.lexers import XmlLexer
from pygments.formatters import HtmlFormatter
from IPython.display import HTML, display
def print_xml(xml:bytes) -> None:
formatter = HtmlFormatter(style='gruvbox-dark')
display(HTML(
'<style type="text/css">{}</style>{}'.format(
formatter.get_style_defs(".highlight"),
highlight(xml, XmlLexer(), formatter),
)))
print_xml([BaseXmlModel].to_xml(pretty_print=True))
# Requirements:
ipykernel
ipywidgets
pandas
tabulate
lovely-tensors
torch
torchvision
torchaudio
rich
pygments
types-pygments
pydantic
pydantic-xml
lxml
# Memoize 3rd party function:
import functools
import [lib]
[lib.func] = functools.wraps([lib.func])(functools.cache([lib.func]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment