Skip to content

Instantly share code, notes, and snippets.

View awesomebytes's full-sized avatar

Sam Pfeiffer awesomebytes

View GitHub Profile
@awesomebytes
awesomebytes / default_camera_info.py
Last active November 4, 2022 01:43
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
awesomebytes / dockerexec.py
Last active March 14, 2023 22:51
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
awesomebytes / code_connect_via_command_line.md
Last active June 28, 2025 20:33
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
awesomebytes / find_roscores.py
Created September 22, 2020 01:22
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()
try:
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'`
else
echo "No roscore found, setting ROS_MASTER_URI and ROS_IP to localhost defaults."
export ROS_MASTER_URI=http://localhost:11311
export ROS_IP=127.0.0.1
export ROS_NETWORK_INTERFACE=lo

To visualize a custom AprilTags description

In python/ipython 2.7

custom_apriltag_string = "wwwwwwwwwbbbbbbwwbddddbwwbddddbwwbddddbwwbddddbwwbbbbbbwwwwwwwww"
for idx, c in enumerate(custom_apriltag_string):
    if idx % 8 == 0 and idx > 0:
        print
    print c,
@awesomebytes
awesomebytes / Gif_from_video.md
Last active January 19, 2021 23:26
Create a gif from a video ubuntu commandline ffmpeg

How to create a GIF from a video

ffmpeg -i video.mp4 -r 15 -vf "scale=512:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -ss 00:00:03 -to 00:00:09 video.gif

From https://askubuntu.com/questions/648603/how-to-create-an-animated-gif-from-mp4-video-via-command-line

  • -i video.mp4 is the input video.
  • -r 15 is the FPS, 10 or 15 is usually fine, more would be too big of a file.
  • -vf "scale=512:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse optimizes the palette of colors of the gif and sets the scale (512px here, use 768 if you need it a bit bigger, but be aware of the final size of the gif if you do so, 512 is a good tradeoff).
#!/bin/bash
tar cvzf cmake-3.18.0.binary-aarch64.tar.gz /usr/local/doc/cmake-3.18/cmsys/Copyright.txt /usr/local/doc/cmake-3.18/cmlibrhash/COPYING /usr/local/doc/cmake-3.18/cmzlib/Copyright.txt /usr/local/doc/cmake-3.18/cmcurl/COPYING /usr/local/doc/cmake-3.18/cmnghttp2/COPYING /usr/local/doc/cmake-3.18/cmzstd/LICENSE /usr/local/doc/cmake-3.18/cmliblzma/COPYING /usr/local/doc/cmake-3.18/cmlibarchive/COPYING /usr/local/doc/cmake-3.18/cmlibuv/LICENSE /usr/local/bin/cmake /usr/local/bin/ctest /usr/local/bin/cpack /usr/local/share/cmake-3.18/include/cmCPluginAPI.h /usr/local/doc/cmake-3.18/Copyright.txt /usr/local/share/cmake-3.18/Help /usr/local/share/cmake-3.18/Help/prop_cache /usr/local/share/cmake-3.18/Help/prop_cache/ADVANCED.rst /usr/local/share/cmake-3.18/Help/prop_cache/VALUE.rst /usr/local/share/cmake-3.18/Help/prop_cache/HELPSTRING.rst /usr/local/share/cmake-3.18/Help/prop_cache/STRINGS.rst /usr/local/share/cmake-3.18/Help/prop_cache/MODIFIED.rst /usr/local/share/cmake-3.18/Help/prop_cache/TYPE.rst /usr
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.