Skip to content

Instantly share code, notes, and snippets.

View krhoyt's full-sized avatar

Kevin Hoyt krhoyt

View GitHub Profile
@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 / 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 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 / 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 / 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 / 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 / app.js
Last active May 27, 2017 23:55
Particle Location with Google Integration
var cfenv = require( 'cfenv' );
var express = require( 'express' );
var jsonfile = require( 'jsonfile' );
var parser = require( 'body-parser' );
var Particle = require( 'particle-api-js' );
var request = require( 'request' );
// External configuration
config = jsonfile.readFileSync( __dirname + '/config.json' );
@krhoyt
krhoyt / image.js
Created May 18, 2017 09:10
Animated File Upload Button
var express = require( 'express' );
var fs = require( 'fs' );
var multer = require( 'multer' );
var path = require( 'path' );
var randomstring = require( 'randomstring' );
// Router
var router = express.Router();
// Upload storage options
@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>