Skip to content

Instantly share code, notes, and snippets.

@robdmc
robdmc / holoviews_stacked_area_chart.py
Last active January 30, 2021 19:34
Holoviews stacked area plot
c_list = []
for col in df.columns[1:]:
c = hv.Area((df.date, df[col]/1e6), 'Date', 'Active Pipeline ($M)', label=col).opts(color=hv.Cycle('Set1'))
c_list.append(c)
hv.Area.stack(hv.Overlay(c_list))
@robdmc
robdmc / monstrous_visidatarc.py
Last active January 17, 2021 19:55
Visidata Monstrosity
def syncSaveSheets(givenpath, *vsheets, confirm_overwrite=False):
"""
Copy of saveSheets function, but without async stuff
"""
filetype = givenpath.ext or options.save_filetype
savefunc = getattr(vd, 'save_' + filetype, None) or vd.fail('no function to save as type %s' % filetype)
if givenpath.exists() and confirm_overwrite:
confirm("%s already exists. overwrite? " % givenpath.given)
import networkx as nx
G = create_graph()
# Show graph in notebook
A = nx.drawing.nx_agraph.to_agraph(G)
A.layout('dot')
graphviz.Source(A.to_string())
@robdmc
robdmc / altair_plotting_example.py
Last active June 16, 2020 23:23
Altair example
import altair as alt
alt.data_transformers.disable_max_rows()
chart = alt.Chart(df)
chart.mark_line().encode(
x='timestamp:T',
y='ask:Q',
color='strike:O'
).properties(
width=800,
@robdmc
robdmc / holoviews_color_cycle_color_names.py
Last active June 16, 2020 23:47
holoviews_color_cycle_color_names
# Example of a plot
c = hv.Curve((x, y)).options(color=hv.Cycle('RdBu'))
# Show valid color cycles
def format_list(l):
print(' '.join(sorted([k for k in l if not k.endswith('_r')])))
format_list(hv.Cycle.default_cycles.keys())
"""
@robdmc
robdmc / pretty_print_display_hook.py
Created June 5, 2020 22:05
Pretty Print Display Hook
import pprint
import sys
sys.displayhook = pprint.pprint
coverage run --branch -m pytest -v --capture=no --pdb -k partial_test_method_name
coverage report -m -i --include='cash_flow*'
@robdmc
robdmc / ssh_port_forward.sh
Last active February 1, 2021 02:31
ssh port forwarding
# ssh -L<port_on_local_machine>:<remote_machine_as_seen_from_remote_machine>:<port_on_remote_machine> <remote_machine_as_seem_from_local_machine>
# In the example above, all traffic sent to port 5901 on your local host is
# being forwarded to port 4492 on the remote server located at 188.17.0.5.
ssh –L 5901:188.17.0.5:4492 [email protected]
# Another example. This makes it look like a jupyter server on port 8888 of the miner1 host
# is running on port 8888 of your local machine
ssh -L8888:localhost:8888 miner1
@robdmc
robdmc / bern_test.ipynb
Last active April 6, 2020 17:37
Bernstein Density Test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@robdmc
robdmc / jupyter_cell_widths.py
Created February 28, 2020 18:16
Jupyter make cell widths full screen
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))