Skip to content

Instantly share code, notes, and snippets.

@josephcoombe
josephcoombe / ssh_from_windows_with_subprocess_openssh_example.py
Last active December 19, 2023 15:52
SSH from Windows 10 using subprocess + OpenSSH
# SSH from Windows 10 using Python subprocess + built-in OpenSSH
#
# Alternatives to using subprocess include:
# Fabric: http://www.fabfile.org/
# Paramiko: http://www.paramiko.org/
#
# References:
# OpenSSH in Windows 10: https://blogs.msdn.microsoft.com/commandline/2018/01/22/openssh-in-windows-10/
# The only simple way to do SSH in Python today is to use subprocess + OpenSSH...: https://gist.github.com/bortzmeyer/1284249
# Issue8557 - subprocess PATH semantics and portability: https://bugs.python.org/issue8557
@josephcoombe
josephcoombe / pretty_print_nested_dictionaries_with_json_module.py
Last active November 30, 2018 22:01
Python: Pretty print nested dictionaries
# Python: Print nested dictionaries
#
# Taken from:
# https://stackoverflow.com/a/3314411/8670609
import json
print(json.dumps({'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}},
sort_keys=True, indent=4))
# {
@josephcoombe
josephcoombe / get_str_objects_instead_of_unicode_from_json_using_object_hook.py
Created September 26, 2018 17:05
Python: Get str objects instead of Unicode from JSON
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python: Get str objects instead of Unicode from JSON
# using object_hook
#
# Taken from:
# Source: https://stackoverflow.com/a/33571117
import json
# Install Google Cartographer and Local Protobuf Version
#
# Based on:
# install_cartographer_proto_locally.sh: https://gist.github.com/l1va/630043c4a23e6b3f5c73c088ba6b62d5
#
# References:
# Cartographer ROS Integration: https://google-cartographer-ros.readthedocs.io/en/latest/index.html
# Compiling Cartographer ROS: https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html
# This file was generated by an older version of protoc - #625: https://github.com/googlecartographer/cartographer_ros/issues/625
# Issue8557 - subprocess PATH semantics and portability: https://bugs.python.org/issue8557
@josephcoombe
josephcoombe / python_xml_etree_xpath_example.py
Last active April 2, 2019 14:15
Python xml.etree with XPath
# Python xml.etree with xpath
#
# References:
# The ElementTree XML API: https://docs.python.org/2/library/xml.etree.elementtree.html
import xml.etree
from xml.etree.ElementTree import Element
from xml.etree import ElementTree as ET
from xml.dom import minidom
<gazebo reference='joint_name'>
<preserveFixedJoint>true</preserveFixedJoint>
</gazebo>
@josephcoombe
josephcoombe / recursive_glob_for_python2.py
Created February 7, 2020 03:49
Recursive glob for Python 2
# References:
# https://stackoverflow.com/a/2186639/8670609
import os
import fnmatch
def recursive_glob(treeroot, pattern):
results = []
for base, dirs, files in os.walk(treeroot):
goodfiles = fnmatch.filter(files, pattern)
@josephcoombe
josephcoombe / list_r_packages_and_licenses.cmd
Created July 20, 2020 22:21
List R Packages and Licenses Batch File
@echo off
setlocal enableDelayedExpansion
set r_library_relative_path=R\library
echo %r_library_path%
for /d %%i in ("%~dp0%r_library_relative_path%\*") do (
echo %%~nxi
findstr /b License: %%i\DESCRIPTION
echo.
)
@josephcoombe
josephcoombe / gazebo_uri_paths_to_mesh_files_in_ros_packages.xml
Last active October 18, 2021 15:18
Gazebo URI Paths to Mesh Files in ROS Packages
<!--
https://stackoverflow.com/a/53759308
https://answers.gazebosim.org//question/6416/using_a_urdf_in_gazebo-package-uris-not-described/?answer=6419#post-id-6419
https://answers.ros.org/question/195402/creating-custom-gazebo-world-files-from-sdfsdaes-for-use-with-roslaunch/?answer=357489#post-id-357489
-->
<package>
<!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<buildtool_depend>catkin</buildtool_depend>