Skip to content

Instantly share code, notes, and snippets.

View planetceres's full-sized avatar

Matt Shaffer planetceres

View GitHub Profile
@planetceres
planetceres / joblib_parallel_with_timeout.py
Last active February 21, 2020 05:13
parallel processing with timeout
# Source: https://github.com/joblib/joblib/pull/366#issuecomment-267603530
# Source2: https://github.com/joblib/joblib/issues/522
# Source3: https://github.com/mapillary/OpenSfM/blob/199f2dc4a535397afc8fdeb76d67053e76015b61/opensfm/reconstruction.py#L470
import time
import multiprocessing
import functools
from joblib import Parallel, delayed
@planetceres
planetceres / get_version.py
Created February 10, 2020 03:41
Get version of python library
import tensorflow as tf
(major, minor, _) = tf.__version__.split(".")
@planetceres
planetceres / tree_file_types.sh
Created December 5, 2019 22:56
Count/show file types in recursive tree
#!/bin/bash
# Reference: https://unix.stackexchange.com/a/387631
for d in */ ; do
echo $d
find $d -type f | sed -r 's/.*\/([^\/]+)/\1/' | sed 's/^[^\.]*$//' | sed -r 's/.*(\.[^\.]+)$/\1/' | sort | uniq -c | sort -nr
# files only | keep filename only | no ext -> '' ext | keep part after . (i.e. ext) | count | sort by count desc
done
@planetceres
planetceres / hdf5_to_dict.py
Last active December 4, 2019 02:12
Read .hdf5 as dict
#!/usr/bin/python
'''
Source
https://gitlab.kuberlab.io/lsheiba/keras/blob/fbe7873fc0f43090e2df52b85867b8b6179516ca/keras/models.py
'''
from keras.models import load_model
from keras import layers as layer_module
import h5py, json, pprint
@planetceres
planetceres / load_module_dynamic.py
Last active November 22, 2019 03:04
load python module dynamically
# Source: https://stackoverflow.com/questions/301134/how-to-import-a-module-given-its-name-as-string
import importlib
py_module = "std_msgs.msg"
py_class = "String"
PyClass = getattr(importlib.import_module(py_module), py_class)()
@planetceres
planetceres / compare_hosts.sh
Created September 20, 2019 20:01
Compare ubuntu packages between two hosts
#!/bin/bash
# Reference: https://askubuntu.com/a/344396
function _compare_hosts () {
echo "Usage: $ ./compare_pkgs.sh username@ip_address1 username@ip_address2 ~/.ssh/id_rsa1 ~/.ssh/id_rsa2"
# 1: remote_host = user@ip_address
# 2: ssh_key = ~/.ssh/id_rsa
if [[ ! -z $1 ]]; then
local remote_host1=$1
@planetceres
planetceres / rate_scheduler
Created June 20, 2019 00:03
Threaded Cron Execution Timer Python
#!/usr/bin/env python
# reference: https://stackoverflow.com/a/13151299
'''
Usage:
def hello(name):
print "Hello %s!" % name
print "starting..."
@planetceres
planetceres / activate_cuda.sh
Last active May 24, 2019 02:41
CUDA activation in shel script
#!/bin/bash
trap "exit" INT TERM ERR
trap "kill 0" EXIT
HOME_DIR=$(getent passwd "$USER" | cut -d: -f6)
CURRENT_DIR=${PWD##*/}
WORKSPACE_PATH=$(pwd)
CUDA_VERSION=10.0
export CUDA_VISIBLE_DEVICES=0,1
@planetceres
planetceres / display_links.py
Created May 9, 2019 02:20
Display file links in Jupyter iPython
@planetceres
planetceres / get_intrinsic_matrix.py
Created April 11, 2019 17:28
Realsense Intrinsic Matrix
import pyrealsense2 as rs
import numpy as np
'''
Intrincs and Exrinsic information available from command line with RealSense SDK
$ rs-enumerate-devices -c
'''
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1920, 1080, rs.format.bgr8, 30)