Skip to content

Instantly share code, notes, and snippets.

@BCadet
BCadet / cat.md
Last active August 1, 2024 07:15
cat magic stdin/out redirection and mixing

How to abuse cat stdin to redirect file content

cat with stdin EOF tag can be used to mix stdin input and file content

cat - << 'EOF' "file.txt"
text from stdin to prepend to file.txt content
EOF
@BCadet
BCadet / install_xc32.expect
Created February 20, 2023 14:07
expect script to automate installation of the microchip xc32 toolchain
#!/usr/bin/expect
# usage: ./install_xc32.expect ./xc32_<version>-full-install-linux-x64-installer.run
set installer [lindex $argv 0]
set install_args [lindex $argv 1]
spawn $installer
set timeout -1
@BCadet
BCadet / FTDIRelays.py
Created November 23, 2022 15:59
simple python driver to communicate with USB relay module based on FTDI chip like https://www.sainsmart.com/products/4-channel-5v-usb-relay-module
from pyftdi.gpio import GpioController
import argparse
class FTDIRelays:
def __init__(self):
self._gpio = GpioController()
self._state = 0 # SW cache of the GPIO output lines
def pins(self):
print(self._gpio.direction)
@BCadet
BCadet / liblightmodbus-doc.cmake
Last active October 6, 2022 06:31
Doxygen CMake variables to build the liblightmodbus documentation : https://github.com/Jacajack/liblightmodbus
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/documentation/liblightmodbus")
set(DOXYGEN_GENERATE_TAGFILE "${CMAKE_BINARY_DIR}/documentation/liblightmodbus.tag")
set(DOXYGEN_PROJECT_NAME "liblightmodbus - a lightweight, header-only, hardware-agnostic Modbus RTU/TCP library")
set(DOXYGEN_PROJECT_BRIEF "A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library")
set(DOXYGEN_PROJECT_NUMBER 3.0)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
set(DOXYGEN_EXCLUDE_PATTERNS "*/doc/doxygen-awesome-css/*")
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_ENABLE_PREPROCESSING YES)
set(DOXYGEN_MACRO_EXPANSION YES )
@BCadet
BCadet / doxygen.cmake
Last active October 20, 2022 15:38
CMake snippets
# function to create a TARGET_NAME Doxygen target with Doxygen parameters defined in PARAM_FILE and the sources located in SOURCE_DIR
function(create_documentation TARGET_NAME PARAM_FILE SOURCE_DIR)
find_package(Doxygen REQUIRED dot)
include(${PARAM_FILE})
doxygen_add_docs(${TARGET_NAME}-doc
${SOURCE_DIR}
)
if(DOXYGEN_GENERATE_LATEX AND DOXYGEN_USE_PDFLATEX)
add_custom_command(
TARGET ${TARGET_NAME}-doc
@BCadet
BCadet / xilinx_autoGenToken.sh
Created August 19, 2022 12:33
auto generate xilinx authentication token with expect
#!/usr/bin/expect
set installer [lindex $argv 0]
set email [lindex $argv 1]
set password [lindex $argv 2]
spawn $installer -b AuthTokenGen
set timeout -1
set ret 0
expect {
@BCadet
BCadet / petalinux-accept-eula.sh
Created August 8, 2022 12:55
petalinux eula acceptation script
#!/usr/bin/expect
set installer [lindex $argv 0]
set install_args [lindex $argv 1]
spawn $installer $install_args
set timeout -1
expect {
"Press Enter to display the license agreements" { send "\r"; exp_continue}
"(press RETURN)" {send "\r"; sleep 1; send "q"; exp_continue}
@BCadet
BCadet / .udev_rules
Last active July 7, 2023 12:22
U-dev rules
UDEV rules
@BCadet
BCadet / getScriptPath.bash
Created August 1, 2022 07:47
get absolute path of a script
#! /bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
@BCadet
BCadet / vscode-devcontaier-on-server.md
Created July 4, 2022 11:50
Make VSCode devcontainer works on a machine with multiple users

github issue

Problem

When multiple users try to user VSCode devcontainer on a remote server, some files are initialized in the /tmp path with the user ownership.
When a second user tries to user VSCode remote server, he's stuck on an ACCESS DENIED error in these folders.

Workaround

Each user shall create a folder with his username in /tmp and export in his .bashrc the variable TMPDIR=/tmp/$USER.