Skip to content

Instantly share code, notes, and snippets.

View travis23's full-sized avatar

Travis Niederhauser travis23

View GitHub Profile
@travis23
travis23 / ranges_in_between_ranges.py
Created September 24, 2019 15:42
[Boundaries Between Range Boundaries] #endpoints #numpy #classify #pandas
def get_ranges_in_between_ranges(df, start_name, stop_name):
"""
Get range boundaries in between range boundaries arranged to be strictly increasing.
For example if we had three range boundaries where the range start and stop values
are found in two separate columns in a dataframe,
start, stop
-----------
0, 5
7, 8
@travis23
travis23 / logging.py
Last active October 30, 2019 18:03
[Simple Logging] #python #logging #jupyter
def create_logger(log_file_path, display_level, file_level):
"""
Logs to file as well as to display.
See https://www.dataquest.io/blog/advanced-jupyter-notebooks-tutorial/
Args:
log_file_path (str):
display_level (int): logging.INFO for example
file_level (int): logging.INFO for example
@travis23
travis23 / read_csv.py
Created January 9, 2020 19:23
[Read csv with Python] #python #csv #null
# See https://stackoverflow.com/questions/7894856/line-contains-null-byte-in-csv-reader-python
with open(path_to_csv_file) as f:
reader = csv.reader((x.replace('\0', '') for x in f), delimiter=',') # Handle null values
while True:
try:
line = next(reader)
except StopIteration:
break
print(line) # process lines
@travis23
travis23 / create_data_directory.py
Created January 23, 2020 20:43
[Create Data Directory with Meaningful Name] #directory #python #pendulum
import os
import pendulum
def create_data_directory(
data_kind, # 'VolCal'
data_source_id,
timezone,
parent_directory
):
@travis23
travis23 / OpenJupyterLab.bat
Created April 15, 2020 15:56
[Batch File to Open Jupyter Lab] #batch #Jupyter #Anaconda
set root=C:\Users\user\Anaconda3
call %root%\Scripts\activate.bat %root%
call activate py37
call cd "C:\Users\TNiederhauser\Dropbox (Medic)\MedicData\Floor Scale"
call jupyter lab
@travis23
travis23 / verify_path_exists.py
Last active April 30, 2020 20:31
[Verify Path Exists] #os #path #assert #raise #python
def verify_path_exists(path_):
try:
assert os.path.exists(path_)
except (AssertionError,) as error:
print()
print('Path not found')
print(path_)
raise FileNotFoundError
@travis23
travis23 / levels_to_step_plot.py
Last active June 30, 2020 11:58
[levels_to_step_plot] #python #plot #step_plot
import numpy as np
def levels_to_steps_post(x_vec, y_vec):
"""Provides data like matplotlib.pyplot.step with where set to 'post'"""
x_new = [None] * (len(x_vec) * 2 - 1)
y_new = [None] * (len(x_vec) * 2 - 1)
for i in range(len(x_vec)-1):
x_new[2*i] = x_vec[i]
@travis23
travis23 / remove_nonunique_times.py
Last active July 7, 2020 14:49
[remove points that contain non-unique time values from timeseries] #numpy #values #unique #python #strictly_increasing #timeseries
indices = np.unique(time_arr.values, return_index=True)[1]
time_strict = time_arr.values[indices]
response_strict = response_arr.values[indices]
@travis23
travis23 / RunOnLoad.html
Last active September 9, 2020 15:30
[On Loading Page Run Javascript] #html #javascript #onload
<head><script>
function initialize()
/* Initialize the web page */
{
/* Do stuff */
}
</script></head>
<body onload="initialize()">
@travis23
travis23 / CallFunction.html
Created September 9, 2020 15:42
[Javascript call function every x msec] #javascript #html #delay #sleep #pause #wait
<head>
<script>
window.setInterval(function() {myFunction()}, 500)
function myFunction() {
/* Do stuff */
}
</script>
</head>