Skip to content

Instantly share code, notes, and snippets.

View dcyoung's full-sized avatar

David Young dcyoung

View GitHub Profile
"""
A base class for managing rest requests asynchronously in python.
Usage:
class MyRequestManager(AioRequestManager, metaclass=ABCMeta):
def __init__(self, **kwargs):
super(MyRequestManager, self).__init__(**kwargs)
def some_specific_request(self):
endpoint = f"{self._base_url_address}/some/url/endpoint"
return await self.__request_json(endpoint)
@dcyoung
dcyoung / RetryHelpers.cs
Created March 3, 2020 19:18
Lightweight, dependency free retry helpers.
using System;
using System.Threading.Tasks;
namespace Util
{
public static class RetryHelpers
{
public static async Task RetryOnExceptionWithBackoffAsync(int maxRetries, TimeSpan initialDelay, Func<Task> action)
{
await RetryOnExceptionWithBackoffAsync<Exception>(maxRetries, initialDelay, action);
@dcyoung
dcyoung / render_process.js
Created May 31, 2018 01:14
Opening files from Electron Render Process
// electron modules
const { dialog } = require('electron').remote;
...
// Instruct the main process to open a file dialog where the user can select a file
function openFileDialog() {
const options = {
title: 'Select a json file!',
filters: [
@dcyoung
dcyoung / client.matlab
Created April 4, 2018 00:13
Controlling robotic pendulum using a kinect sensor.
%%%%%%%%%%%%%%% CLIENT %%%%%%%%%%%
clear all; close all; clc;
tcpipClient = tcpip('172.16.1.71',55000,'NetworkRole','Client') %for
% server running on kinect computer
set(tcpipClient,'InputBufferSize',8);
set(tcpipClient,'Timeout',1000);
fopen(tcpipClient);
while(1)
rawData = fread(tcpipClient,1,'double');
@dcyoung
dcyoung / GenerateStimuli.cs
Created April 4, 2018 00:10
VR Depth perception experiment. Script rearranges game objects so that they appear to be of equal size when viewed.
using UnityEngine;
using System.Collections;
public class GenerateStimuli : MonoBehaviour
{
public GameObject[] stimulusObjs; //specify the objects in the inspector for use in the stimulus loop
public GameObject targetEye; //the reference point that will be used to determine how stimuli should be rearranged
private bool bSeqInProgress = false; //true for the duration of the displayed stimulus sequence
public float desiredAngularDiameterInDeg; //will determine the apparent size of all the stimuli
@dcyoung
dcyoung / ToggleTracking.cs
Created April 4, 2018 00:08
Toggle position and rotation tracking of VR headset using quaternion math.
using UnityEngine;
using System.Collections;
public class ToggleTracking : MonoBehaviour
{
private Transform eyeCenter;
private Transform trackingSpace;
private bool bUseRotationalTracking = true;
private bool bUsePositionalTracking = true;
@dcyoung
dcyoung / VRMirror.cs
Created April 4, 2018 00:06
A virtual reality mirror in unity.
using UnityEngine;
using System.Collections;
public class VRMirror : MonoBehaviour
{
public CameraFlipper cameraFlipper;
public GameObject copyCat;
private Vector3 copyCatStartingPosition;
private Transform eyeCenter;
@dcyoung
dcyoung / automated_teddy_bear_sim.cpp
Created April 4, 2018 00:02
MEL expression script for automating the duplication and placement of many items.
$num = 30; //number of bear duplicates to generate;
//define the reference bear to duplicate
string $ref_bear = "bear0";
//for each bear to be duplicated
for ($i = 1; $i < $num; $i++)
{
select($ref_bear);
duplicate - rr;
select - d;
@dcyoung
dcyoung / rigging_tank_treads.cpp
Created April 3, 2018 23:58
Simple MEL expression for rigging tank treads in Maya.
int $numTreads = 36;
string $pathNames[];
for ($i = 1; $i < ($numTreads + 1); ++$i)
{
$pathNames[$i - 1] = "motionPath" + $i;
}
float $Zdist = TrackLeft_Control.translateZ;
float $circumference = curveInfo1.arcLength;
int $direction;
@dcyoung
dcyoung / match_features_ratio.cpp
Created April 3, 2018 23:52
Matching features using ratio and ssd techniques
// This just uses the ratio of the SSD distance of the two best matches as the score
// and matches a feature in the first image with the closest feature in the second image.
// It can match multiple features in the first image to the same feature in
// the second image.
void ratioMatchFeatures(const FeatureSet &f1, const FeatureSet &f2, vector &matches, double &totalScore)
{
int m = f1.size();
int n = f2.size();
matches.resize(m);