Skip to content

Instantly share code, notes, and snippets.

@NathanaelGandhi
NathanaelGandhi / ros2-source-aliases-setup.sh
Last active June 4, 2024 00:38
setup aliases for sourcing ROS2 (POSIX-compliant script)
#!/bin/sh
# Define the shell rc (ie. ~/.bashrc or ~/.zshrc)
SHELL_RC="${HOME}/.$(basename ${SHELL})rc"
# Check if SHELL_RC exists, if not, use .profile
if [ ! -f "${SHELL_RC}" ]; then
echo "${SHELL_RC} not found"
SHELL_RC="$HOME/.profile"
fi
@NathanaelGandhi
NathanaelGandhi / .pre-commit-config.yaml
Last active April 18, 2024 12:42
Pre-Commit all the things
---
ci:
autofix_prs: false
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
@NathanaelGandhi
NathanaelGandhi / install-ohmybash.sh
Created February 8, 2024 07:20
Install OhMyBash Script
#!/bin/bash -eu
## Author: Nathanael Gandhi
################################################################################
if [ -d ~/.oh-my-bash ]
then
echo "Directory ~/.oh-my-bash already exists. Not installing"
else
#!/bin/bash -eu
apt-get install -y wget zsh fonts-powerline && \
echo "[config-zsh] installing oh-my-zsh" && \
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O - | zsh || true && \
echo "[config-zsh] installing oh-my-zsh plugins" && \
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && \
sed -i 's|plugins=(git)|plugins=(git zsh-autosuggestions zsh-syntax-highlighting)|g' ~/.zshrc && \
echo "[config-zsh] setting theme to agnoster" && \
@NathanaelGandhi
NathanaelGandhi / Containerfile.doxygen
Last active July 6, 2023 07:00
Development Containerfile for building Doxygen documentation
################################################################################
# Title: Development Container for building Doxygen documentation
# Author: Nathanael Gandhi | gist.github.com/NathanaelGandhi
# Notes: Container for all project dependencies. Intended to be run using
# distrobox. Can be built with either Docker or Podman.
################################################################################
# Base Image
FROM ubuntu:22.04
################################################################################
# Base Configuration
@NathanaelGandhi
NathanaelGandhi / Containerfile.dev.stm32
Last active July 8, 2023 15:17
Development Containerfile for STM32 projects
################################################################################
# Title: Development Container for STM32 projects
# Author: Nathanael Gandhi | gist.github.com/NathanaelGandhi
# Notes: Container for all project dependencies. Intended to be run using
# distrobox. Can be built with either Docker or Podman.
################################################################################
# Base Image
FROM ubuntu:22.04
################################################################################
# Base Configuration
@NathanaelGandhi
NathanaelGandhi / .clang-format
Last active June 17, 2023 17:02
Clang format file for C/C++ projects
################################################################################
# Title: Clang format file for C/C++ projects
# Author: Nathanael Gandhi | gist.github.com/NathanaelGandhi
# Notes: see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
################################################################################
---
BasedOnStyle: Google
Language: Cpp
IndentWidth: 4
UseTab: Never
@NathanaelGandhi
NathanaelGandhi / bash-function-setupSsh.sh
Last active June 8, 2023 22:44
bash function to setup ssh
#!/bin/bash -eu
# author: Nathanael Gandhi
# github.com/NathanaelGandhi
################################################################################
# setup ssh #
################################################################################
setupSsh()
{
echo " • Setup ssh access"
@NathanaelGandhi
NathanaelGandhi / bash-function-setupLocale.sh
Last active June 8, 2023 22:44
bash function to setup locale information
#!/bin/bash -eu
# author: Nathanael Gandhi
# github.com/NathanaelGandhi
################################################################################
# setup locale information #
################################################################################
setupLocale()
{
locale_id=en_AU.UTF-8
@NathanaelGandhi
NathanaelGandhi / bash-function-forceRoot.sh
Last active June 8, 2023 23:03
bash function to ensure that the script is run with root privileges
#!/bin/bash -eu
# author: Nathanael Gandhi
# github.com/NathanaelGandhi
# If the user is not root, it performs the following actions:
# 1. It assigns the absolute path of the currently running script to the variable exe_name using the readlink -f command. This ensures that exe_name contains the full path of the script even if it was executed using a relative path.
# 2. It then uses sudo to execute the script again as root, passing the same script path ($exe_name) and any command-line arguments ($@) to it.
# 3. Finally, it exits the current instance of the script with the same exit code ($?) as the root-executed script.
# In summary, this code snippet is designed to ensure that the script is run with root privileges. If it's not being run as root, it will re-execute itself using sudo to gain the necessary privileges.