Skip to content

Instantly share code, notes, and snippets.

View krhoyt's full-sized avatar

Kevin Hoyt krhoyt

View GitHub Profile
@krhoyt
krhoyt / index.html
Created May 13, 2017 10:08
Tracking.JS Face Detection on Canvas
<html>
<head>
<title>People</title>
<link href="/style/people.css" rel="stylesheet" type="text/css">
</head>
<body>
@krhoyt
krhoyt / watson.json
Created April 21, 2017 20:55
Isolate Watson Keywords
{
"api": "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze",
"url": "http://_CONTENT_YOU_WANT_WATSON_TO_LOOK_AT_",
"username": "_YOUR_WATSON_API_USERNAME_",
"password": "_YOUR_WATSON_API_PASSWORD_",
"threshold": 0.70,
"limit": 20
}
@krhoyt
krhoyt / present.sh
Created February 16, 2017 15:29
Toggle clear desktop for presentations or screen recordings.
#!/bin/bash
file="present.txt"
if [ -f "$file" ]
then
rm $file
defaults write com.apple.finder CreateDesktop true
killall Finder
else
echo "You got this." > $file
@krhoyt
krhoyt / ble.swift
Created February 5, 2017 19:07
BLE notifications.
import CoreBluetooth
import UIKit
class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate {
var manager:CBCentralManager!
var peripheral:CBPeripheral!
let BEAN_NAME = "Bean+"
let BEAN_SCRATCH_UUID = CBUUID(string: "a495ff21-c5b1-4b44-b512-1370f02d74de")
@krhoyt
krhoyt / hih61xx.js
Last active August 30, 2016 20:56
HIH6130 temperature and humidity from a Tessel 2 (I2C).
// Hardware access
var tessel = require( 'tessel' );
// Sensor values
var humidity = null;
var temperature = null;
// Sensor
// Default address
var hih = tessel.port['B'].I2C( 0x27 );
@krhoyt
krhoyt / readings.js
Created August 8, 2015 03:58
Full CRUD for Cloudant on Express 4.
var router = require( 'express' ).Router();
var Reading = {
// Get all readings
// Get latest reading
// Get readings within a page
getReadings: function( req, res ) {
var params = null;
@krhoyt
krhoyt / app.js
Created July 29, 2015 00:20
IBM Mobile Cloud Services Boilerplate
// Libraries
var express = require( 'express' );
var ibmbluemix = require( 'ibmbluemix' )
var ibmdata = require( 'ibmdata' );
var winston = require( 'winston' );
// Constants
var LOG_PATH = '../logs/winston.log';
// Bluemix
@krhoyt
krhoyt / transform.js
Created March 19, 2015 16:37
Linear transform to map a value in one range to a value in another.
function scale( value, old_top, old_bottom, new_top, new_bottom )
{
// minTo + (maxTo - minTo) * ((value - minFrom) / (maxFrom - minFrom))
return new_bottom + ( new_top - new_bottom ) * ( ( value - old_bottom ) / ( old_top - old_bottom ) );
}
@krhoyt
krhoyt / parse-cookie.js
Created February 10, 2015 20:40
Parse a cookie value containing JSON (sent from Node/Express).
@krhoyt
krhoyt / oop-javascript.js
Created December 24, 2014 19:57
Basic OOP template for JavaScript libraries.
// Originally
// http://phrogz.net/js/classes/OOPinJS.html
function Proxy()
{
// Private variables and methods
// Only priveleged
var MY_PRIVATE = "PRIVATE";
var moar_private = null;