Skip to content

Instantly share code, notes, and snippets.

View KaiWedekind's full-sized avatar
:octocat:
Strongest Avenger.

Kai Wedekind KaiWedekind

:octocat:
Strongest Avenger.
  • IBM Deutschland GmbH
  • Germany
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Speech Recording</title>
</head>
<body>
<script>
@KaiWedekind
KaiWedekind / my-todos.js
Last active August 12, 2018 06:12
Universal todo component built with custom elements v1 - Class definition
class MyTodos extends HTMLElement {
constructor() {
// always call super() first in your constructor to inherit from your parent class
super();
}
}
// register new tag and associate it with the class
customElements.define('my-todos', MyTodos);
@KaiWedekind
KaiWedekind / my-todos.js
Last active August 12, 2018 06:19
Universal todo component built with custom elements v1 - Lifecycle methods
class MyTodos extends HTMLElement {
// called when the HTML parser sees the HTML tag
constructor () {
// always call super() first in your constructor to inherit from your parent class
super();
this.title = 'My todos';
}
// called when the element is inserted in the DOM
// immediately after constructor if the element is in the DOM already
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My todos</title>
</head>
<body>
<my-todos></my-todos>
@KaiWedekind
KaiWedekind / googlemail-markup.js
Created August 12, 2018 09:57
How Google Mail markup should look like.
<body>
<google-mail>
<mail-header></mail-header>
<mail-navigation></mail-navigation>
<mail-list>
<mail-thread id="74738ff5-5367-5958-9aee-98fffdcd1876">
<mail-content from="john.doe@gmail.com" to="jane.doe@gmail.com">
<h2>Hi Jane</h2>
<article>
<p>...</p>
@KaiWedekind
KaiWedekind / my-todos.js
Last active August 13, 2018 06:35
Lifecycle callbacks
class MyTodos extends HTMLElement {
// called when the HTML parser sees the HTML tag
constructor () {
// always call super() first in your constructor to inherit from your parent class
super();
this.title = 'My todos';
}
// called when the element is inserted in the DOM
// immediately after constructor if the element is in the DOM already
function getContrast50(hex){
return (parseInt(hex, 16) > 0xffffff/2) ? 'black': 'white';
}
function getContrastYIQ(hexcolor){
var r = parseInt(hexcolor.substr(0, 2), 16);
var g = parseInt(hexcolor.substr(2, 2), 16);
var b = parseInt(hexcolor.substr(4, 2), 16);
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
return (yiq >= 128) ? 'black' : 'white';
}
[
{ "input": { "r": "0.00", "g": "0.00", "b": "0.00" }, "output": { "white": 1 } },
{ "input": { "r": "0.85", "g": "0.88", "b": "0.56" }, "output": { "black": 1 } },
{ "input": { "r": "0.33", "g": "0.35", "b": "0.84" }, "output": { "white": 1 } },
{ "input": { "r": "0.00", "g": "0.99", "b": "1.00" }, "output": { "black": 1 } }
]
'use strict'
const brain = require('brain.js');
const data = require('./training-data.json');
const network = new brain.NeuralNetwork();
network.train(data, { log: true });
const result = network.run({ r: 0, g: 1, b: 0.65 });