Skip to content

Instantly share code, notes, and snippets.

@KPB3rd
KPB3rd / installJupyter.txt
Last active March 24, 2024 02:19
Install Jupyter on Mac
// Install conda
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
// Make virtual env
conda create -n jupyter python ipython jupyterlab nodejs numpy matplotlib scipy ipywidgets
@KPB3rd
KPB3rd / Python script location dir
Created September 30, 2022 14:43
Get the directory location where the python script file is
# get the location of the script, NOT the location we are running from
# Consider if the code is run by python or exe
# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
dir_path = os.path.dirname(sys.executable)
elif __file__:
dir_path = os.path.dirname(os.path.realpath(__file__))
@KPB3rd
KPB3rd / constexpr in template.cpp
Created August 24, 2022 21:25
Using constexpr in templated func
template <typename T>
func() {
if constexpr(std::is_same<T, TheTypeIWant>::value) {
}
else {
}
}
@KPB3rd
KPB3rd / recursive_remote_git_update
Last active September 8, 2022 20:29
Update git submodule remotes
find -wholename "*/.git/config" -type f -exec sed -i 's/<insertoldstring>/<insertnewstring/g' {} +
git submodule sync
@KPB3rd
KPB3rd / bezier.cpp
Created July 19, 2022 16:06
Bezier code for path planning
// https://github.com/Rezonality/mutils/blob/6adc3fa9d160f455092637032cb6fcd6162d0b93/include/mutils/math/math_utils.h#L124
template <typename T>
inline T Bezier(float t, T p0, T p1, T p2, T p3) {
return std::pow(1 - t, 3) * p0 + 3 * std::pow(1 - t, 2) * t * p1 + 3 * (1 - t) * (t * t) * p2 + std::pow(t, 3) * p3;
}
template <typename T>
inline T BezierPt(float t, T p0, T p1, T p2, T p3)
{
@KPB3rd
KPB3rd / Simple racing threading.cpp
Created April 15, 2022 15:14
Example of using 2 threads and stopping them if the other finished
std::atomic<bool> is_from_start_solved(false);
std::atomic<bool> is_from_goal_solved(false);
// Example lambda to check if either is high
auto is_path_solved = [&]() -> bool { return is_from_goal_solved.load() || is_from_start_solved.load(); };
auto from_start = [&]() -> void { is_from_start_solved = true; };
auto from_goal = [&]() -> void { is_from_goal_solved = false; };
std::thread t_from_start(from_start);
@KPB3rd
KPB3rd / enforce_template_type.cpp
Created March 29, 2022 15:35
Require a templated type for a member function
template <class T>
class(std::vector<thing> things) {
static_assert(std::is_same_v<T, TheTypeIWant>, "This constructor requires TheTypeIWant!");
}
@KPB3rd
KPB3rd / cmake download files from ftp.txt
Created February 23, 2022 16:30
Download files using cmake
# Individual File download
if(NOT DEFINED DOWNLOADED OR NOT ${DOWNLOADED})
file(DOWNLOAD
"ftp://10.0.IP.IP/example.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/data/"
SHOW_PROGRESS
STATUS status
LOG log)
endif()
@KPB3rd
KPB3rd / Matplotlib Animation and gif.py
Created November 9, 2021 14:07
Matplotlib Animation and gif
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib import cm
fig = plt.figure()
ax = fig.add_subplot(111)
scat = ax.scatter([], [])
def animate(i):
@KPB3rd
KPB3rd / Set json or xml node in file.py
Last active October 6, 2021 20:43
Function to update a node in a json or xml file
import xml.etree.ElementTree as ET
import json
def nested_json_set(dic, keys, value):
for key in keys[:-1]:
dic = dic.setdefault(key, {})
dic[keys[-1]] = value
def ReplaceStringInFile(filename, child_tree, dest_ip):
# try: