Skip to content

Instantly share code, notes, and snippets.

View sempostma's full-sized avatar

Sem Postma sempostma

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Neural network</title>
</head>
<body>
<h3 id="msg">Training Neural Network...</h3>
<script src="https://cdn.jsdelivr.net/npm/jimp@0.2.27/browser/lib/jimp.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/synaptic/1.1.4/synaptic.min.js"></script>
const { Architect, Trainer } = synaptic;
const int = Math.floor;
const catagorical = i => {
const arr = new Array(26).fill(0);
arr[i] = 1;
return arr;
};
Jimp.loadFont(Jimp.FONT_SANS_16_BLACK).then(function (font) {
function obj2csv(obj, opt) {
if (typeof obj !== 'object') return null;
opt = opt || {};
var scopechar = opt.scopechar || '/';
var delimeter = opt.delimeter || ',';
if (Array.isArray(obj) === false) obj = [obj];
var curs, name, rownum, key, queue, values = [], rows = [], headers = {}, headersArr = [];
for (rownum = 0; rownum < obj.length; rownum++) {
// (c) 2018 Sem Postma
// This code is licensed under MIT license
(function () {
var endScopeObj = {};
window.obj2xml = function (obj, opt) {
if (!opt) opt = {};
var rootName = opt.rootName || 'root';
var declaration = opt.declaration === 'auto' ? '<?xml version="1.0" encoding="utf-8"?>' : opt.declaration;
var indentation = opt.indentation || 0;
class Heap {
constructor() {
this.items = [];
}
seek() { return this.items[0]; }
}
export class MaxHeap extends Heap {
This file has been truncated, but you can view the full file.
[
{
"occupation_code": "00-0000",
"occupation_title": "All Occupations",
"level": "total",
"employment": "142,549,250",
"employment_rse": "0.1%",
"employment_per_jobs": "1000.000",
"median_hourly_wage": "$18.12",
"mean_hourly_wage": "$24.34",
@sempostma
sempostma / num-to-utf8-and-back.js
Last active December 3, 2018 22:11
Number to UTF8 and back
function convertBase(value, fromBase) {
return value.split('').reverse().reduce(function (carry, digit, index) {
const digitVal = digit.charCodeAt(0);
if (digitVal >= fromBase) throw new Error('Invalid digit `' + digit + '` for base ' + fromBase + '.');
return carry += digitVal * (Math.pow(fromBase, index));
}, 0);
}
function encode(value, toBase = 65535 /* safe range */) {
var utf8 = value.toString().split('').map(function(x) {
@sempostma
sempostma / sw.js
Last active December 11, 2018 11:48
Jekyll Serviceworker that just works
---
---
var DYNAMIC_CACHE = 'dynamic-cache-{{ site.time | date: "%s" }}';
var STATIC_CACHE = 'static-cache-{{ site.time | date: "%s" }}';
// listen for outgoing network request
self.addEventListener('fetch', function (event) {
// try to find response object in the cache
// associated with current request
const NLP = require('natural');
const path = require('path');
const readline = require('readline');
const fs = require('fs');
const { stemmer } = require('./config');
const trainingDataPath = process.argv[2];
const classifierName = process.argv[3];
if (!trainingDataPath || !classifierName) {
console.log('usage: node . <path/to/trainingdata.json> <classifier_name>');
@sempostma
sempostma / final-approach.html
Last active February 7, 2019 13:15
final-approach.html
<!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>Game</title>
<style>