Skip to content

Instantly share code, notes, and snippets.

"""
Sample script to use ThreadPoolExecutor in a way that is easy to interrupt.
"""
import concurrent.futures
import threading
from tqdm import tqdm
# A flag indicating whether jobs should be cancelled.
cancel_jobs = threading.Event()
@RichardKelley
RichardKelley / depth_anything.py
Created January 29, 2024 18:19
A ROS2 node that uses Depth Anything to get depth from a monocular camera in real time.
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2
import numpy as np
import torch
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
### This script wraps all executables in the anaconda bin folder so that they can be used without adding Anaconda
### to the path which would break some functionality of ROS (Robot Operating System)
###
### The commands e.g. jupyter notebook will cause the script to add anaconda to the path, start jupyter notebook
### and after jupyter notebook terminated remove anaconda from the path again
###
### Notable commands:
### * release-the-snake Adds conda to the path and removes all aliases defined by this script
### Conda will stay in the PATH until the end of the session (terminal is closed) or
### until "cage-the-snake" is called
@RichardKelley
RichardKelley / ml_utils.py
Created March 11, 2019 19:10
ML utilities
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from matplotlib.patches import Ellipse
from math import sqrt
def build_dataset(n_samples, n_features, n_classes = 1):
'''
Create a dataset.
@RichardKelley
RichardKelley / gist:02f6e62971aa07a844387e49eb6a95ff
Created March 1, 2018 00:53
Loading a policy trained with OpenAI baselines to visualize and render. Specifically for Reacher-v2.
import gym
import tensorflow as tf
from baselines.ppo2 import policies
from baselines.common import set_global_seeds, tf_util as U
env = gym.make("Reacher-v2")
def policy_fn(s, ob_space, ac_space):
return policies.MlpPolicy(s, ob_space=ob_space, ac_space=ac_space, nbatch=1, nsteps=1)
% A Simple LaTeX Example
% Author: Richard C Kelley
% This is a comment. A comment begins with a '%' and extends to the
% end of the line.
% We always start our LaTeX documents by specifying the document class
% we want to use. There are several document classes available that
% you could use if you wanted - article, book, report, letter,
% etc. For many purposes, though, all you need is the article
@RichardKelley
RichardKelley / structhash.cpp
Created January 16, 2018 19:56
Computing the SHA-256 Hash of a C++ Structure in Memory
#include "PicoSHA2/picosha2.h"
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
struct person {
std::string name;
@RichardKelley
RichardKelley / probit.rkt
Last active October 10, 2017 04:39
Probit Function in Racket. This gives quantiles of the standard normal, which ends up being trickier to implement than you might guess. We follow the "quantile mechanics" approach of Steinbrecher and Shaw: http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/EJAM_Quantiles.pdf.
#lang racket
(define (sum-to n term)
(letrec ((S (lambda (acc k)
(cond
[(eq? k 0) (+ (term 0) acc)]
[else (S (+ acc (term k)) (- k 1))]))))
(S 0.0 n)))
(define vs '())
@RichardKelley
RichardKelley / CMakeLists.txt
Created August 2, 2017 14:13 — forked from linknum23/CMakeLists.txt
CMakeList configuration for compiling ROS and Driveworks on a Tegra (Drive PX2)
cmake_minimum_required(VERSION 3.1)
project(dw_wrapper)
set (CMAKE_CXX_STANDARD 11)
# FindDriveworks.cmake, ArchConfiguration.cmake, and LibFindMacros.cmake were needed for my setup they are taken from driveworks/samples/cmake/
# ArchConfiguration.cmake was the only file that needed small changes, remove the fatal error on line 17 and add the following lines in its place
# set(VIBRANTE TRUE)
# add_definitions(-DVIBRANTE)
# this is the path I placed the driveworks cmake files in
@RichardKelley
RichardKelley / pytorch_xor.py
Created July 13, 2017 07:25
Using Pytorch to learn xor
import numpy as np
import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.nn.functional as F
import torch.optim as optim
class XorNet(nn.Module):
def __init__(self):
super().__init__()