Useful Code Snippets

Even as a super awesome engineer, there are still basic things that I always forget. Like 1+1… or whether it’s cos(0)=1 or sin(0)=1. That’s why it’s so useful to have a cheatsheet at all times!

Anyhow, here are some things I have to search Google for waaaay too often:

Converting MOV to GIF:

ffmpeg -i -vf scale=560:560/a -pix_fmt rgb24 -r 20 -f gif - | gifsicle --optimize=3 --delay=5 > home_anim3.gif

Got this from here.

Great Markdown cheatsheet

Viewing ROS image topics:

rosrun image_view disparity_view image:=/camera/depth_registered/disparity
rosrun image_view image_view image:=/camera/rgb/image_color

Copying file from local to server via SSH:

scp /path/to/source-file user@host:/path/to/destination-folder/

More commands found here.

Opening ROS serial node (defaults to port /dev/ttyUSB0):

rosrun rosserial_python _port:=/dev/ttyUSB0

Send ROS message to node:

rostopic pub /topic_name std_msgs/String hello

Full wiki page.

Create/merge new Git branch:

git checkout -b newbranch
git merge newbranch

Excluding packages from catkin_make:

# "List of ';' separated packages to build"
catkin_make -DCATKIN_BLACKLIST_PACKAGES="foo;bar"

Compiling threaded C++ code:

g++ foo.cpp -o foo -pthread -std=c++11

Finding custom libraries when compiling C++:

g++ laser_calibrate.cpp $(pkg-config --libs opencv) -o calib

Force uninstall apt packages via dpkg:

sudo dpkg --force-all -P

Installing sublime or other packages w/ custom executable:

sudo mv Sublime\ Text\ 2/ /opt/
sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime

Useful Links:
WordPress SSH commands
MX-64 Docpage

Leave a Reply

Your email address will not be published. Required fields are marked *