Skip to content

Instantly share code, notes, and snippets.

@srathi-monarch
srathi-monarch / limit_cpu.sh
Last active July 23, 2024 17:19
Limit cpu usage when running a command (i.e. cgroup interface for
systemd-run --user --scope -p CPUQuota=25% --slice=stress -- stress -c 1
# Where you replace stress -c 1 with your command
# Ubuntu 20.04 doesn't support this with non root users, so you have to run
sudo systemd-run --scope -p CPUQuota=25% --slice=stress -- stress -c 1
# Note that this remove all the environment variables.
# If you want to run as the current user
sudo systemd-run --scope -p CPUQuota=25% --uid="$(id -u)" --gid="$(id -g)" --slice=stress -- id
@srathi-monarch
srathi-monarch / list_python_imports.sh
Last active July 8, 2024 06:43
List python imports
#!/usr/bin/sh
{ grep -Poh '(?<=^import )[^.][A-Za-z_.]*' . -r ; grep -Poh '(?<=^from )[^.].*(?=import)' . -r ; } | cut -d '.' -f 1 | tr -d ' ' | sort | uniq
@srathi-monarch
srathi-monarch / cc_setup.bash
Last active July 8, 2024 05:09
Setup catkin with unified compile commands for all packages
#! /usr/bin/bash
# Run: `catkin config --append-args --cmake-args "-DCMAKE_EXPORT_COMPILE_COMMANDS=1"` to setup catkin correctly.
export ROS_WS_DIR=`catkin locate` || { echo "Not in a catkin workspace." ; exit 1; }
source /opt/ros/noetic/setup.bash
[[ -f ./devel/setup.bash ]] && source ./devel/setup.bash
echo -ne "[\n]" > $ROS_WS_DIR/.catkin_tools/CATKIN_BUILD_DUMMY.json
@srathi-monarch
srathi-monarch / get_ip.sh
Created July 8, 2024 04:45
IP from ip addr
ip addr show tun0 | grep -Po '(?<=inet )([0-9]{1,3}\.){3}[0-9]{1,3}(?=/[0-9]{1,3})'
@srathi-monarch
srathi-monarch / delay.sh
Created July 5, 2024 07:14
Add delay to ros nodes from roslaunch using launch-prefix.
#! /usr/bin/sh
if [ $# -lt 2 ]; then
echo "Usage: $0 <delay> <command> [args...]"
exit 1
fi
sleep "$1"
shift
exec "$@"
#! /usr/bin/zsh
set -euo pipefail
# Arguments
# -t | --tractor=TRACTOR_NAME
# -r | --run=RUN_NAME
DATA_HOME="${HOME}/kalibr_ws/sync_logs/"
@srathi-monarch
srathi-monarch / join_bags.py
Last active July 8, 2024 04:53
Joins rosbags that are in chronological order into a single bagfile.
#! /usr/bin/python3
import sys
from pathlib import Path
import rosbag
from tqdm import tqdm
def main():
@srathi-monarch
srathi-monarch / import_rosbag.py
Created June 5, 2024 07:05
Get rosbag on a newer python version
# python -m pip install rosbag rospkg pycryptodome gnupg
import sys
import Crypto
sys.modules['Cryptodome'] = Crypto
import rosbag
@srathi-monarch
srathi-monarch / install_cloudflare_cert.sh
Created May 28, 2024 08:38
Install Cloudlfare's `.pem` to the system certificate store.
sudo mkdir /usr/local/share/ca-certificates/cloudflare
cd !$
sudo cp ~/Downloads/Cloudflare_CA.pem ./Cloudflare_CA_1.crt # Note that the extension has changed.
sudo update-ca-certificates
@srathi-monarch
srathi-monarch / clean_gitconfig.sh
Created May 21, 2024 09:22
Clean .gitconfig (removes comments),
IFS=$'\n'; for key in $(git config --global -l); do bash -c "git config --file=.gitconfig_new $(echo $key | tr '=' ' ')"; done
# Chekc both files and replace .gitconfig if it looks good!.