Skip to content

Instantly share code, notes, and snippets.

@gokhansolak
gokhansolak / svg_to_eps.sh
Created September 13, 2022 19:00
Convert all svg files in the folder to eps files, using Inkscape
#!/usr/bin/env bash
# optionally clear all eps files
# rm *.eps
for f in *.svg
do
fname=${f##*/}
fprefix=${fname%.*}
echo $fprefix
@gokhansolak
gokhansolak / auto_source_catkin_setup.sh
Last active November 11, 2020 10:44
Source the workspace of the current working directory automatically, if it matches the pattern. Append this to the .bashrc file.
# source the workspace of the current working directory automatically
home_dir=~/
ws_ptr="(${home_dir}ws/[0-9a-zA-Z ]+)/?"
if [[ $PWD =~ $ws_ptr ]]; then
ws_dir=${BASH_REMATCH[1]}
source $ws_dir/devel/setup.bash
fi
@gokhansolak
gokhansolak / mp_psuedo_inv.cpp
Last active November 23, 2021 19:16 — forked from pshriwise/mp_psuedo_inv.cpp
Moore-Penrose Pseudo-Inverse Using Eigen, works for non-square matrix
// method for calculating the pseudo-Inverse as recommended by Eigen developers
template<typename _Matrix_Type_>
_Matrix_Type_ pseudoInverse(const _Matrix_Type_ &a, double epsilon = std::numeric_limits<double>::epsilon())
{
Eigen::JacobiSVD< _Matrix_Type_ > svd(a ,Eigen::ComputeThinU | Eigen::ComputeThinV);
double tolerance = epsilon * std::max(a.cols(), a.rows()) *svd.singularValues().array().abs()(0);
return svd.matrixV() * (svd.singularValues().array().abs() > tolerance).select(svd.singularValues().array().inverse(), 0).matrix().asDiagonal() * svd.matrixU().adjoint();
}
@gokhansolak
gokhansolak / reindex_files.sh
Created June 4, 2020 14:17
Re-index files by changing the index suffix of file names.
#!/bin/bash
# Re-index files by changing the index suffix of file names.
# Usage: reindex_files <pattern> <offset>
# It renames all files in the folder following "pattern + number + extension" naming.
# <pattern> can be any regex (care not to match the index number).
# <number> is an integer ([0-9]+)
# It works for files with no extension as well.
# It will ask for confirmation before renaming the files.
rename_all(){
@gokhansolak
gokhansolak / compress_bags.sh
Created June 4, 2020 11:14
Simple script for compressing all bag files under a folder
#!/bin/bash
# Simple script for compressing all bag files under a folder.
# Optionally, deletes the backup files created by rosbag.
read -p "Compress every bag file under $PWD ? (y/n)" yn
# initial user consent
if [ "$yn" == "n" ]; then
exit 0
fi
# optionally remove backups right away
@gokhansolak
gokhansolak / renumerate_param_list.py
Created June 2, 2020 16:22
This script will renumerate the item indexes in a YAML dictionary.
#!/usr/bin/env python3
# This script will renumerate the item indexes in a
# YAML dictionary. ROS currently does not support easy
# acquisition of list of objects from parameter server,
# so I prefer using indexed dictionaries. However, it
# is tiring to index them manually. This script does it.
# Example yaml file (iter_prefix = 'p'):
# https://github.com/gokhansolak/lfd-experiments-iros2019/blob/master/data/grasp/pregrasp.yaml
@gokhansolak
gokhansolak / neq_display_error.ipynb
Created February 16, 2020 21:10
Ipython file demonstrating the \neq latex display problem
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gokhansolak
gokhansolak / add_license_notice.py
Created February 5, 2020 15:21
This program adds the given license notice at the beginning of all c, cpp, h, hpp files in a folder
#! /usr/bin/env python
# This program adds the given license notice at the
# beginning of all c, cpp, h, hpp files in a folder
#
# usage:
# change to the directory that contains the code files
# python3 add_license_notice.py <license_file> <source_path>
# it will apply the changes too all files in that directory
import glob
@gokhansolak
gokhansolak / dmp_archive_updater.py
Created November 21, 2019 02:13
This program adds DmpBbo namespace to the class names in a dmp xml archive to solve boost::serialization's unregistered_class error
#!/usr/bin/env python
# This program adds DmpBbo namespace to the class names
# in a dmp xml archive to solve boost serialization's
# unregistered_class error
# usage:
# change to the directory that contains dmp xml files
# python3 dmp_archive_updater.py
# it will apply the changes too all xml files in that directory
@gokhansolak
gokhansolak / iterate_exp.sh
Last active November 17, 2020 12:06
Repeats ROS experiments, keeps a notes file in Markdown format
#!/usr/bin/env bash
# This script calls a certain ROS launch file with incremental experiment numbers,
# and records user notes in order to a markdown (md) file.
# exp_type: name of the launch file
# exp_no: last index to start from
#
#
# usage (arguments are optional):
# ./iterate_exp.sh exp_type exp_no ros_package[optional]