Skip to content

Instantly share code, notes, and snippets.

Almost done with my PhD thesis...

Sam Pfeiffer awesomebytes

Almost done with my PhD thesis...
View GitHub Profile
#!/usr/bin/env bash
# Template from
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
awesomebytes /
Created Oct 27, 2020
Get variable type user friendly name in C++

How to get the type of a variable in C++

#include <boost/units/detail/utility.hpp>
using boost::units::detail::demangle;
auto demangled_name = demangle(typeid(MY_VARIABLE).name());
std::cout << "variable is of type: '"<< demangled_name << "'" << std::endl;
awesomebytes /
Created Oct 21, 2020
ssh -X with opengl Qt enabled app solution to neither GLX nor EGL are enabled

ssh -X Qt OpenGL error solution

To avoid the following error: QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled when doing X forwarding via SSH one needs to install the following (in the remote machine where you are sshing into). This also solves black screen for me.

# This is needed in the remote machine
sudo apt-get install libegl-mesa0 libglx-mesa0
awesomebytes /
Last active Nov 10, 2020
Use qt serialbus in ubuntu 18.04 with qt 5.9

Using the Qt serialbus (to access a CAN bus) in Ubuntu 18.04

I was trying to compile a Qt project that uses the Qt serialbus module and it was not configuring when using qmake, the error was: Unknown module(s) in QT: serialbus. So I needed to build qtserialbus myself.

While trying to build it I ran into: fatal error: private/qobject_p.h: No such file or directory.

# Overkill: get all qt-stuff
sudo apt install qml-module-qt-labs-folderlistmodel qml-module-qtquick-extras qml-module-qtquick-controls2 qt5-default libqt5quickcontrols2-5 qtquickcontrols2-5-dev qtcreator qtcreator-doc libqt5serialport5-dev build-essential qml-module-qt3d qt3d5-dev qtdeclarative5-dev qtconnectivity5-dev qtmultimedia5-dev
awesomebytes /
Last active Oct 9, 2020
Publish a default camera_info topic from an image topic
#!/usr/bin/env python
import sys
import numpy as np
import cv2
import rospy
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import CameraInfo, Image, CompressedImage
Publish a default CameraInfo topic from an Image or CompressedImage topic
awesomebytes /
Last active Oct 2, 2020
docker exec -t forwarding signals wrapper
#!/usr/bin/env python3
import sys
import argparse
import os
import subprocess
import signal
import time
import threading
import shlex
import docker
awesomebytes /
Last active Dec 25, 2020
How to open Visual Studio Code via command line (local file, remote-ssh, docker, remote-docker)

How to open Visual Studio Code via command line

In order to open a Visual Studio Code sometimes we want to do it from the command line. Either because that allows us to just open the current file or folder, or because we would like to script opening some specific resource. This resource may be placed in another machine (e.g. via ssh), or in a docker container (running in the same machine or in another machine).

Local file or folder

code <file or folder>
# e.g. code .
awesomebytes /
Created Sep 22, 2020
Find roscores running in your network
#/usr/bin/env python
import socket
import time
from multiprocessing import Process, Queue
def check_server(address, queue, port=11311):
# Create a TCP socket
s = socket.socket()
s.connect((address, port))
# this is part of .bashrc / .bash_profile
if [[ $(ps aux | grep bin/roscore | grep -v grep) ]]; then
export ROS_MASTER_URI=`python -c "import rosgraph; print(rosgraph.Master('ip_checker').getUri())"`
export ROS_IP=`python -c "import rosgraph; print(rosgraph.Master('ip_checker').getUri().replace('http://','').replace(':11311/',''))"`
export ROS_NETWORK_INTERFACE=`ifconfig | grep $ROS_IP -1 | awk 'NR==1{print $1}' | sed 's/://g'`
echo "No roscore found, setting ROS_MASTER_URI and ROS_IP to localhost defaults."
export ROS_MASTER_URI=http://localhost:11311
export ROS_IP=