Skip to content

Instantly share code, notes, and snippets.

@stephenmm
stephenmm / ROS_setup_from_new_ubuntu.txt
Last active September 5, 2018 16:22
Robotic Operating System tutorial from fresh ubuntu
1 sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2 sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
3 sudo apt-get update
4 sudo apt-get install ros-melodic-desktop-full
5 sudo rosdep init
6 rosdep update
7 echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
8 source ~/.bashrc
9 sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
10 printenv | grep ROS
@stephenmm
stephenmm / gphoto2_cygwin_x_install_notes.bash
Last active August 16, 2018 05:37
Notes on installing gphoto2 on cygwin/X
# Installing gphoto2 on cygwin (NOTE: This is with cygwin/X installed and working already so a lot of the graphical stuff had been worked out)
git clone https://github.com/gphoto/gphoto2.git
cd gphoto2/
autoreconf -is # Not installed. Need these cygwin packages: autoconf automake gettext
apt-cyg install autoconf
apt-cyg install automake
apt-cyg install gettext
autoreconf -is # Still not working. Need gettext-tools which is gettext-devel in cygwin
#autoreconf-2.69: failed to run autopoint: No such file or directory
#autoreconf-2.69: autopoint is needed because this package uses Gettext
@stephenmm
stephenmm / get_clip.bashrc
Last active July 23, 2018 17:21
My workaround for not having xsel or xclip. Also shows use of named params and how to safely return values without overwriting globals.
# Get the current clipboard contents. Can be used in three different ways:
# 1) clip=$( get_clip ) # puts clippboard contents directly to the STDOUT
# 2) get_clip file=clipFile # puts clippboard contents in the file provided
# 3) get_clip rtrnVar=myClip # puts clippboard contents in the variable myClip
# This is a way of getting clipboard contents from a bash script
get_clip () {
local file rtrn rtrnVar && local $*; # declare possible named variables
local rtrnFile errCode; # declare private variables
[[ ! $file ]] && file=$( mktemp ) || rtrnFile=true
gvim $file -T dumb --noplugin -n -es -c 'set nomore' +'normal "*P' +'wq';
@stephenmm
stephenmm / file_menu2.bash
Created July 12, 2018 20:23
Interactive and visual selection of array with arrows or 'j' 'k' keys. Can also edit (with autocomplete) the selection
#!/usr/bin/env bash
# Started from this code: https://unix.stackexchange.com/a/415155/14014
# Renders a text based list of options that can be selected by the
# user using up, down, 'j', 'k', and enter keys and returns the
# string in provided file.
# 'e' to edit the current string
# 'q' to quit
#
# Arguments : list of options, maximum of 256
@stephenmm
stephenmm / file_menu.bash
Last active July 12, 2018 14:25
Tweak bash select function with default value
# Pass the choices as individual arguments.
# Output is the chosen item, or "", if the user just pressed ENTER.
# Example:
# choice=$(selectWithFirstItemDefault 'one' 'two' 'three')
# files=( $( ls -at /sims/$PROJ/results/$USER/*.svcf ) )
# choice=$(selectWithFirstItemDefault "${files[@]}")
# Code mostly taken from https://stackoverflow.com/a/42790579/120681 w/ my own tweaks
selectWithFirstItemDefault() {
local item i=0 numItems=$#
@stephenmm
stephenmm / plt_csv.sh
Last active July 5, 2018 19:13
A simple way to create plots for your csv data...
# CSV file can be pretty generic but the one I am using looks something like this:
# date,host,test_name,sim_dir,matlab_dir_id,note,sensitivity,mod_clk,num_tones,tone_freq_0,tone_amp_0,ATT,SNR,SINAD,THD,THDN,SFDR,SFDRnh,exp_ATT,exp_SNR,exp_THD,exp_THDN,exp_SFDR,exp_SFDRnh
# 2018-06-27 19:10:49,afrma306,rnd_tone_test,/some/path/to/regress_Jun27_182851/simulate/rand_tone_test_1_-482062569_1, 1,PDM,-19.000000,508077.000000,1,1499.000000,75.255000,-37.523000,46.682000,46.799000,0.023000,0.457000,-89.607000,-89.607000,37.523000,21.088528,0.525000,9.263240,-50.564104,-50.564104
# 2018-06-27 19:15:17,afrma809,rnd_tone_test,/some/path/to/regress_Jun27_182851/simulate/rand_tone_test_1_469551002_1, 1,PDM,-41.000000,1568337.000000,1,9885.000000,83.357000,-51.585000,70.499000,70.499000,0.000000,0.030000,-133.390000,-133.390000,51.585000,27.177713,0.803399,105.000000,0.000000,-73.728294
CSV=/path/to/data.csv
X=tone_amp_0
Y=ATT
Z=sensetivity
@stephenmm
stephenmm / systemverilog_macro_expansion.cpp
Last active June 21, 2018 22:57
Example of how to convert SV macros into CPP macros and use GCC to debug the macro expansion.
// Example:
// gcc -E -CC systemverilog_macro_expansion.cpp -D PREPROC_ONLY=1
// gcc -E -CC systemverilog_macro_expansion.cpp -D PREPROC_ONLY=0
// gcc systemverilog_macro_expansion.cpp -D PREPROC_ONLY=0 -fno-exceptions && a.out
//
//
#define STD_5BIN_RANGE_CALC_MIDP(dflt, shift) ( (dflt) + ( (dflt) >> (shift) ) )
#define STD_5BIN_RANGE_CALC_MIDN(dflt, shift) ( (dflt) - ( (dflt) >> (shift) ) )
#define N_UNSIGNED_BITS_TO_FSP(bits) ( (1<<bits)-1 )
@stephenmm
stephenmm / interactive_grid.py
Created June 4, 2018 23:26
Very simple interactive grid. Kick start for simple grid based games.
#!/usr/bin/env python3
# Very simple interactive grid. Could be the basis for simple games.
# taken from https://stackoverflow.com/a/30045893/120681 Arthur Vaïsse
from tkinter import *
class Cell():
FILLED_COLOR_BG = "blue"
EMPTY_COLOR_BG = "black"
FILLED_COLOR_BORDER = "blue"
@stephenmm
stephenmm / gg.bashrc
Last active September 13, 2018 00:48
Use 'gg' to open whatever is in the clipboard in gvim quickly.
# This would normally just go in your .bashrc file
# My workaround for not having xsel or xclip
# Get the current clipboard contents. Can be used in three different ways:
# 1) clip=$( get_clip ) # puts clippboard contents directly to the STDOUT
# 2) get_clip file=clipFile # puts clippboard contents in the file provided
# 3) get_clip rtrnVar=myClip # puts clippboard contents in the variable myClip
# This is a way of getting clipboard contents from a bash script
get_clip () {
local file rtrn rtrnVar && local $*; # declare possible named variables
@stephenmm
stephenmm / bash-named-param
Last active July 23, 2018 20:36 — forked from caruccio/bash-named-param
Named parameters in bash
# Do you like python named parameters (kvargs) ?
# Well, you can have it in bash too!! (but unfortunatly this will not allow you to mix positional and named parameters)
function myfunc() { local $*; echo "# foo=$foo, bar=$bar"; }
myfunc bar=world foo=hello
# foo=hello, bar=world
#########
# And with default arguments: