Skip to content

Instantly share code, notes, and snippets.

View ant358's full-sized avatar
🎯
Focusing

Anthony Wynne ant358

🎯
Focusing
  • Plymouth, UK
View GitHub Profile
@ant358
ant358 / exercise-loops-and-functions.go
Created November 26, 2023 19:13
Exercise: Loops and Functions. Solution
import (
"fmt"
"math"
)
var j int = 10
func Sqrt(x float64) float64 {
return math.Sqrt(x)
}
@ant358
ant358 / display_whole_df_in_terminal.py
Last active October 5, 2023 14:57
Sometimes your working in systems where you don't have access to the source data. Use this to print out whole csv's . Then cut and paste
import pandas as pd
# number of rows of dataframe
no_rows = len(df)
pd.options.display.max_rows = no_rows
print(df)
# then cut and paste into a text file
# and use find and replace to add in the comma's etc
@ant358
ant358 / get_source.py
Last active March 18, 2023 18:30
To print out the source of functions in memory
# https://docs.python.org/3/library/inspect.html
import inspect
print(inspect.getsource(mystery_function))
@ant358
ant358 / agile-dash-app.py
Created October 6, 2022 21:22
The main app for a Jupyter Dash dahboard
# instantiate the app and set the bootstrap theme
app = JupyterDash(__name__, external_stylesheets=[dbc.themes.SOLAR])
# layout the app
app.layout = html.Div([
html.Br(),
# first row
dbc.Row([
# title left
dbc.Col(
@ant358
ant358 / agile-dash-slider.py
Created October 6, 2022 21:15
Sliders for Jupyter Dash dashboard
# the sliders
sliders = [
# put a blank line at the top
html.Br(),
# slider 1
dcc.Slider(
# set the scale
0, 25,
value=12.5,
id='indy_over_tools',
@ant358
ant358 / agile-dash-gauge.py
Created October 6, 2022 21:12
The Dash gauge for Jupyter Dash dashboard
# the gauge
gauge = [daq.Gauge(
id='agile-gauge',
# make a colour gradient on the scale
color={"gradient":True,
"ranges":{"green":[0,33],
"yellow":[33,66],
"red":[66,100]}},
# create a custom scale
scale={"custom": {
@ant358
ant358 / agile-dash-proxy.py
Created October 6, 2022 21:06
Setup the Jupyter Dash proxy
# setup the proxy
JupyterDash.infer_jupyter_proxy_config()
@ant358
ant358 / agile-dash-imports.py
Created October 6, 2022 21:04
Import the modules required to run a Jupyter Dash dashboard in Google Colab
# load python modules
import dash_daq as daq
import dash_bootstrap_components as dbc
import pandas as pd
import numpy as np
from jupyter_dash import JupyterDash
from dash import dcc, html, Input, Output
@ant358
ant358 / install_jupyter_dash.py
Created October 6, 2022 21:01
Install the packages needed for Google Colab to run Jupyter Dash
# install required modules not in Colab by default
!pip install --quiet jupyter-dash dash_daq dash-bootstrap-components
@ant358
ant358 / truncate.py
Created January 6, 2022 15:21
Truncate numbers (force them to round down)
def truncate(f, n=2):
return math.trunc(f * 10 ** n) / 10 ** n