Skip to content

Instantly share code, notes, and snippets.

View krhoyt's full-sized avatar

Kevin Hoyt krhoyt

View GitHub Profile
@krhoyt
krhoyt / async.js
Created April 6, 2019 22:04
IBM Cloud Function to handle Watson classification of image files placed into Cloud Object Storage.
async function main( params ) {
if( params.status === 'added' ) {
const authorization = await rp( {
url: 'https://iam.ng.bluemix.net/oidc/token',
method: 'POST',
form: {
apikey: params.COS_API_KEY,
response_type: 'cloud_iam',
grant_type: 'urn:ibm:params:oauth:grant-type:apikey'
},
@krhoyt
krhoyt / index.html
Created December 23, 2017 22:19
Tesseract.JS OCR
<html>
<head>
<title>Tesseract</title>
<style>
body {
align-items: center;
display: flex;
flex-direction: row;
@krhoyt
krhoyt / browser.js
Created October 22, 2018 15:44
Upload audio file from web to Watson via Cloud Function.
class Captions {
// Constructor
constructor() {
// Holds audio dialog
this.conversation = [];
// Watson logo
// Used as proxy for file selector
// Allowing for customization of interaction
let watson = document.querySelector( 'button.file' );
@krhoyt
krhoyt / kindle.js
Last active July 20, 2018 18:28
Parse Kindle Notes (July 2018)
// Phase 1 - Create additional elements
let dummy = document.createElement( 'textarea' );
document.body.appendChild( dummy );
// Phase 2 - Parse, format, and place on clipboard
// Repeat as needed for each selected book
let notes = document.querySelectorAll( 'span[id=\'highlight\']' );
let pages = document.querySelectorAll( 'span[id=\'annotationHighlightHeader\']' );
let output = '';
@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 / decision.js
Created July 17, 2018 19:54
Interesting alternative decision structure using ES6.
let foo = ( {
a: () => { return 'a'; },
b: () => { return myFunction; }
} )[bar] || 3;
@krhoyt
krhoyt / basic-pubnub.php
Created December 5, 2014 18:13
Basic example of publishing to PubNub from PHP. Really distilled down to just the REST calls.
<?php
$CHANNEL = "iot";
$PUB_KEY = "_YOUR_PUBLISH_KEY_";
$SUB_KEY = "_YOUR_SUBSCRIBE_KEY_";
$SECRET_KEY = "_YOUR_SECRET_KEY_";
$PUBNUB = "http://pubsub.pubnub.com";
$data = array(
"count" => 3
@krhoyt
krhoyt / pie.chart.js
Created March 22, 2018 22:43
Dynamic SVG Pie Chart
let template = document.querySelector( 'template.sentiment' );
let svg = template.content.querySelector( 'svg' );
let colors = ['#9575CD', '#5E35B1', '#311B92'];
let radius = ( this.root.clientWidth * 0.80 ) / 2;
let rotation = 0;
let slices = [
( value.negative / value.total ) * 100,
( value.nuetral / value.total ) * 100,
( value.positive / value.total ) * 100
@krhoyt
krhoyt / credentials.json
Created January 10, 2018 16:59
Reading Twitter timeline history.
{
"key": "_your_key_here_",
"secret": "_your_secret_here_"
}
@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>