Skip to content

Instantly share code, notes, and snippets.

@jj-github-jj
jj-github-jj / array_of_named_elements.py
Last active November 18, 2022 13:46
array of data structures (dicts) python
import copy
from metadict import MetaDict
''' define data structure using dict Metadict'''
tl_dict=MetaDict ({f'L{n}': 0 for n in range (4)})
''' use dot access . Can create array of these
data structure built using dict (MetaDIct allows dot access)
'''
def set_dict(d,values):
d=copy.deepcopy(d)
@jj-github-jj
jj-github-jj / vcode_snippets.ipynb
Last active October 12, 2022 01:50
vscode related
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jj-github-jj
jj-github-jj / svg_util.ipynb
Last active September 16, 2022 18:30
svg utili
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jj-github-jj
jj-github-jj / quanitiphy usage
Last active September 3, 2022 04:49
basic quantiphy usage
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from quantiphy import Quantity
a=Quantity('30MHz')
print (a) # 30 MHz
a.as_tuple()[0]
a.render() # '30 MHz'
float(a) # 30000000.0
# importing packages
# IF errors replace line 30 in cipher.py as follows
# var_regex = re.compile(r"^\$*\w+\W")
import sys
import os
ytpath=r'https://www.youtube.com/watch?v=2SCOYFkvXWQ'
!{sys.executable} -m pip install pytube
import pytube
from pytube import YouTube
@jj-github-jj
jj-github-jj / interpolate
Created February 12, 2022 18:22
interpolate function for one line interpolation
def y_interpolate (xnew,x,y):
from scipy.interpolate import interp1d
y_interpolate_function = interp1d(x, y)
return (y_interpolate_function(xnew))
@jj-github-jj
jj-github-jj / holoviews_snippets.py
Last active January 25, 2022 13:46
holoviews examples
#https://notebook.community/redlegjed/cheatsheets/holoviews_cheatsheet
#bokeh figure from holoview
bf=hv.render(p) #bf is bokeh figure object
bf
def formatter(value):
return str(value) + ' days'
curve.relabel('Tick formatters').opts(xformatter=formatter, yformatter='$%.2f', width=500)
@jj-github-jj
jj-github-jj / jupyter environment
Last active September 11, 2022 23:08
environment utility snippets
#force reload of specific module without restarting kernel. Useful for debug
import importlib
importlib.reload(<module name>)
# get path of python exe jupyter lab is using
!python --version
!jupyter kernelspec list
!jupyter --version
!{sys.executable} -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple jjutil
def shelve_multiple(list_of_objects=[],fname=''):
""" not providing filename, uses default current notebook name but slow ipynbname function
shelve files are fname.shelf.dir,.data, and .bak(?)
copy these files with ipynb files to save restore objects without re-running
"""
import ipynbname
if fname =='':
fname=ipynbname.name() #use note book name but way too slow so best to pass filename
@jj-github-jj
jj-github-jj / EXPORT IPYNB OUTPUT AS HTML.PY
Created December 26, 2021 16:43
EXPORT IPYNB OUTPUTS ONLY AS HTML
# output html without code only outputs. Use in ipynb file
#
#!pip install ipynbname
try :
import ipynbname #utility to get current notebook name and path
except:
!pip install ipynbname
import ipynbname #utility to get current notebook name and path
nb_fname_full= ipynbname.name()+'.ipynb'
!jupyter nbconvert "{nb_fname_full}" --no-input --to html