Skip to content

Instantly share code, notes, and snippets.

View msbarry's full-sized avatar

Michael Barry msbarry

  • MetroWest Boston
View GitHub Profile
@msbarry
msbarry / SlidesToDoc.gs
Last active February 7, 2024 11:39
Google App Script to create a doc with speaker notes from slides
var INPUT_PRESO_ID = "<id>";
var OUTPUT_DOC_ID = "<id>";
function createNotesDoc() {
var presentation = Slides.Presentations.get(INPUT_PRESO_ID)
var out = DocumentApp.openById(OUTPUT_DOC_ID)
out.getBody().clear();
table = out.getBody().appendTable();
var links = [];
for (var i = 0; i < presentation.slides.length; i++) {
@msbarry
msbarry / README.md
Last active September 13, 2023 18:34
Visvalingam vs. Douglas-Peucker

Two well-known algorithms for polyline simplification are the Douglas Peucker and Visvalingam algorithms.

The Douglas Peucker algorithm uses a recursive divide-and-conquer approach. It starts by drawing a straight line from the first point to the last point. Then it finds the intermediate point that is furthest away from the straight line and deems this the "most important" and splits the polyline into two halves at that point. This process is repeated on both halves until the distance of the intermediate point is below a certain threshold, after which all points on that sub-polyline are thrown away since they have a negligible impact on the overall shape.

The Visvalingam algorithm works from the inside-out. It starts by computing the area of the triangle formed by each consecutive three points along the polyline. Then the midpoint of the triangle with the least area is thrown out since those three points are the closest to colinear and the area of triangles on either side are recomputed. The process

// To run:
// 1) Install java 17 (JDK, not JRE)
// 2) Then get latest planetiler.jar: wget https://github.com/onthegomap/planetiler/releases/latest/download/planetiler.jar
// 3) Then run this file with: java -cp planetiler.jar Powerlines.java --area=monaco --download --force
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.Planetiler;
import com.onthegomap.planetiler.Profile;
import com.onthegomap.planetiler.VectorTile;
@msbarry
msbarry / colorspaces.glsl
Last active July 14, 2021 10:16
glsl color space conversion
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
@msbarry
msbarry / index.html
Last active July 1, 2020 12:54 — forked from jadiehm/data.csv
Choropleth U.S. county map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Independent Farms by County - Choropleth</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="http://d3js.org/queue.v1.min.js"></script>
<script type="text/javascript" src="http://d3js.org/topojson.v1.min.js"></script>
</head>
@msbarry
msbarry / ElasticsearchSource.scala
Created June 16, 2017 19:11 — forked from quiiver/ElasticsearchSource.scala
Scalding source for Elasticsearch
package com.twitter.scalding.sources
import cascading.tuple.Fields
import cascading.tap.Tap;
import org.elasticsearch.hadoop.cascading.EsTap
import com.twitter.scalding._
abstract class ElasticsearchSource extends Source {
@msbarry
msbarry / index.html
Last active March 21, 2017 19:18
M/M/1 Queue Simulation
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>M/M/1 Queue</title>
<style type="text/css">
body {
font-size: 12px;
font-family: Arial;
width: 960px;
@msbarry
msbarry / .block
Last active October 20, 2016 16:57
World Health Scatterplot
license: mit
@msbarry
msbarry / build_trie.js
Created February 9, 2016 10:30
Building/searching a trie in js
var txt = require("fs").readFileSync("app/names.txt", "utf8");
var nicknames = require('./nicknames');
var words = txt.split("\n");
var trie = build(words);
optimize(trie);
require('fs').writeFileSync('app/trie.js', 'trie = ' + toString(trie));
function tokenize(str) {
return str
.toLowerCase()
@msbarry
msbarry / woof.bash
Last active January 19, 2016 17:13
Send yourself notifications from the command line
# Some utilities for sending notifiations to yourself from the command line (mac only).
# Just add them to your ~/.bashrc and fill in these parameters.
# See them all in action: "ugh <long running command> && woof command succeeed || woof command failed"
TWITTER_HANDLE= # twitter handle
EMAIL_ADDRESS= # email address
CELL_EMAIL_ADDRESS= # email address for your cell phone (ie 1234567890@vtext.com)
TERMINAL_APP="com.apple.Terminal" # replace with iterm if you use that
THEME_SONG="~/waiting.mp3" # replace with a path to your theme song