Skip to content

Instantly share code, notes, and snippets.

View petecleary's full-sized avatar

Pete Cleary petecleary

View GitHub Profile
@petecleary
petecleary / LeapHandPosition.js
Created October 30, 2017 12:23
Leap Motion JavaScript hand position. Simple method to collect the palm position of the first hand on every leap motion frame loop.
var handPos = { handId: '', normX: 0, normY: 0, normZ: 0, posX: 0, posY: 0, posZ: 0, rotX: 0, rotY: 0, rotZ: 0, set: false };
Leap.loop(function (frame) {
var handIds = {};
if (frame.hands === undefined) {
var handsLength = 0
} else {
var handsLength = frame.hands.length;
}
@petecleary
petecleary / UdpMessage.cs
Created October 17, 2017 06:41
How to send a UDP message in C#
using System.Net;
using System.Net.Sockets;
string hostName = "192.168.1.1";
int port = 5000;
string msg = "Hello";
UdpClient udpClient = new UdpClient(hostName, port);
Byte[] sendBytes = Encoding.ASCII.GetBytes(msg);
@petecleary
petecleary / CompassLocation.cs
Created October 17, 2017 06:36
Unity mobile compass controller, how to enable and rotate the transform based on the magnetic heading
using System;
using UnityEngine;
using UnityEngine.UI; //required for Input.compass
public float compassSmooth = 0.5f;
private float m_lastMagneticHeading = 0f;
public class CompassController : MonoBehaviour {
// Use this for initialization
void Start () {
@petecleary
petecleary / trail.html
Created October 17, 2017 06:30
Mouse Trail on HTML Canvas
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trail</title>
</head>
<body>
<div class="parent">
<div class="container">
<canvas id="trailCanvas" width="800" height="600" style="margin:0;padding:0;z-index:500; border: 1px solid #000;"></canvas>
@petecleary
petecleary / location.js
Created October 17, 2017 04:57
In Browser location test using navigator.geolocation - example @ https://www.piandmash.com/experiments/location-tracking-in-your-browser/
var x = document.getElementById("demo");
var watchID = null;
var counter = 0;
function geo_success(position) {
counter += 1;
x.innerHTML = "Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude + ", Count: " + counter;
}
function geo_error() {
x.innerHTML = "Sorry, no position available.";
@petecleary
petecleary / headTracking.js
Created October 17, 2017 04:53
Head tracking using Tracking.Js - this example is linked into a synth made in tone.js - for more details see https://www.piandmash.com/experiments/head-tracking-synth/
window.onload = function () {
var video = document.getElementById('video');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var tracker = new tracking.ObjectTracker('face');
try{
tracker.setInitialScale(4);
tracker.setStepSize(2);
tracker.setEdgesDensity(0.1);
@petecleary
petecleary / comms.js
Created October 17, 2017 04:44
Web Socket - a starting point for a simple web socket communication object, sending JSON with a to value to target all or one specified user
var piComms = function (userName, setGlobal, pingInterval) {
'use strict';
var user = userName;
var pingTimerId;
var pingTimerInterval = (pingInterval != undefined) ? pingInterval : 5000;
setGlobal = (setGlobal != undefined && setGlobal == false);
var pub = {
setUserName: function (userName) {
@petecleary
petecleary / gist:5106718
Created March 7, 2013 09:22
CSV, MongoDB example Loops through an import CSV and writes the rows to mongo
//npm install csv
//npm install mongodb
var csv = require('csv');
var fs = require('fs');
var start = Date.now();
// Retrieve
var mongoclient = require('mongodb').MongoClient;
@petecleary
petecleary / gist:5063652
Last active December 14, 2015 09:18
localizeReader is a function that helps provides a standard way to read a resource based on a culture. It takes the object to find the value for and the culture. It will first look for the specific culture ("de-DE"), then fallback to the neutral culture ("de"), then to a default version, then pick the first in the object. It works for objects as…
var localizeReader = exports;
(function (localizeReader) {
localizeReader.get = function(obj, culture){
var c = (!culture) ? 'default': culture;
if(obj[c] !== undefined) return obj[c];
c = c.split('-')[0];
if(obj[c] !== undefined) return obj[c];
for (var prop in obj) {
return obj[prop];
}