Skip to content

Instantly share code, notes, and snippets.

View krhoyt's full-sized avatar

Kevin Hoyt krhoyt

View GitHub Profile
@krhoyt
krhoyt / blockhash.js
Created May 31, 2017 19:44
Image Hashing in the Browser
// Original source:
// https://github.com/commonsmachinery/blockhash-js
// Update for local file reading
// Update (loosely) for ES6
// Removes dependencies from origina project
class Blockhash {
constructor() {
this.canvas = document.createElement( 'canvas' );
this.canvas.style.visibility = 'hidden';
this.canvas.style.position = 'absolute';
@krhoyt
krhoyt / entities.py
Last active June 3, 2017 15:12
Watson Conversation System Entities
import json
import requests
import sys
# Read configuration options
with open( '../bluemix/config.json' ) as data_file:
config = json.load( data_file )
# URL for Conversation API call
url = '{0}{1}{2}{3}{4}'.format(
@krhoyt
krhoyt / conversation.js
Created June 5, 2017 21:05
Using Watson Conversation System Entities
var express = require( 'express' );
var request = require( 'request' );
// Router
var router = express.Router();
// Send message to Conversation
// Return found system entities
router.post( '/message', function( req, res ) {
// Build URL
@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 / credentials.json
Created January 10, 2018 16:59
Reading Twitter timeline history.
{
"key": "_your_key_here_",
"secret": "_your_secret_here_"
}
@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 / 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 / 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 / index.html
Last active October 15, 2023 11:54
Canvas ImageData to Web Worker
<html>
<head>
<title>Image Processing Worker</title>
<style>
body {
align-items: center;
display: flex;
flex-direction: column;
@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' );