Skip to content

Instantly share code, notes, and snippets.

View linknum23's full-sized avatar

Lincoln Lorenz linknum23

  • MicroNova
  • United States
View GitHub Profile
@linknum23
linknum23 / app.py
Last active May 21, 2021 19:28 — forked from vigneshjs/app.py
Adding multiple request and response examples to swagger docs in fastAPI
"""
FastAPI uses pydantic models to validate the API request body and also generate the swagger documentation. Since the schema
generated by pydantic only comply to JSON schema specification and not to openAPI specification, swagger documentation
generated from pydantic models do not support adding multiple examples for a request body.
Ref: https://fastapi.tiangolo.com/tutorial/schema-extra-example/#technical-details
In the following code, I have extended fastAPI openAPI schema to include multiple request body examples.
"""
import json
@linknum23
linknum23 / binary2header.bash
Last active July 30, 2020 18:27
Binary file to C array (for including the binary as a C array in a header file)
#!/bin/bash
xxd -i binary_file > binary_file_as_c_header.h
grep -zo "START.*END" File
@linknum23
linknum23 / runx
Last active July 13, 2020 16:35
bash helper, run a command x number of times
#!/bin/bash
# run bash command x number of times
# ie. 'runx 10 echo "Hello"' will print Hello 10 times
# partially from: https://stackoverflow.com/questions/3737740/is-there-a-better-way-to-run-a-command-n-times-in-bash
function runx() {
for _ in $(seq "$1"); do
eval ${*:2}
done
}
@linknum23
linknum23 / test_list_to_dict_lookup.launch
Last active December 11, 2019 13:54
Roslaunch combine dictionary lookups from list
<?xml version="1.0"?>
<launch>
<!-- List of things to lookup in dict, in our case sensors -->
<arg name="sensors" value="s1,s2" />
<!-- Actual python dictionary. In our case this maps sensors to topics -->
<arg name="sensor_topics" value="{
's1':'t1',
's2':'t2',
's3':'t3'
}" />
@linknum23
linknum23 / find_and_prepend.bash
Last active October 14, 2019 20:14
Advanced find and replace/prepend with sed
#!/bin/bash
# these ideas was used during conversion from C code to C++
directory_whitelist="dir1 dir2" # directories to replace files in
for dir in $(directory_whitelist); do
pushd $dir;
# do replacement but use prefix to make sure replacement only happens once (in this case prepending std::)
# \1 in the replace portion of the sed command is used to keep the character before the match (typically a space or '(')
@linknum23
linknum23 / early_exit.bash
Created July 2, 2018 16:29
exit or return in bash, handles sourced and direct execution
# parameter tests
if [ INSERT_TEST_HERE ] ; then
return 2>/dev/null || exit
fi
# do real stuff
@linknum23
linknum23 / upgrade_xc32.bash
Last active July 2, 2018 17:59
upgrade microchip x32 peripheral libraries without peripheral libraries executable ( assumes 1.40 is installed and has peripheral libraries )
#!/bin/bash
read -p "compiler version: " version
if [ ! -e /opt/microchip/xc32/v$version ] ; then
echo "directory /opt/microchip/xc32/v$version not found"
echo "not an installed version"
return 2>/dev/null || exit
fi
mkdir -p /opt/microchip/xc32/v${version}/pic32-libs/include/lega-c
@linknum23
linknum23 / replay_bag_1khz.launch
Last active March 6, 2018 19:18
Launching 1KHz bagfile playback
<?xml version="1.0"?>
<launch>
<arg name="play_bag" default="true"/>
<arg name="uut" default="my_node"/>
<param name="use_sim_time" value="true"/>
<arg name="bag_file" value="$(env HOME)/.ros/my_bag.bag"/>
<node pkg="my_pkg" type="$(param uut)" name="$(param uut)_node" output="screen"/>
<!-- NOTE: standard rosbag published clock rate of 100Hz, was too slow for my ros timer callbacks -->
<!-- Produce a clock, using the bagfile, at 1KHz to make timer callbacks up to a KHz work! -->
@linknum23
linknum23 / bash_nmcli_wifi_aliases.bash
Created September 20, 2017 16:50
bash nmcli wifi aliases
# nmcli aliases from man nmcli
alias wifi-list='nmcli dev wifi list'
alias wifi-connect='nmcli con up id'
alias wifi-add='nmcli --ask dev wifi connect '