Skip to content

Instantly share code, notes, and snippets.

View w8r's full-sized avatar
💭
learning

Alexander Milevski w8r

💭
learning
View GitHub Profile
@w8r
w8r / .block
Created February 23, 2017 10:01 — forked from enjalot/.block
Rainbow Pack (adapted for d3.unconf badge)
license: gpl-3.0
height: 960
@w8r
w8r / matrix.js
Created February 23, 2017 17:24
Matrix container
class Matrix {
constructor (h, w, ArrayType = Uint32Array) {
this._w = w;
this._h = h;
this._arrayType = ArrayType;
this._mtr = new (this._arrayType)(this._w * this._h);
}
get (r, c) {
return this._mtr[this._w * r + c];
@w8r
w8r / index.html
Last active February 24, 2017 14:20
Collision detection on 1000s of lines
<!doctype html>
<html>
<head>
<title>Measure rtree for feature detection</title>
<script src="https://unpkg.com/d3@4.4.1"></script>
<script src="https://unpkg.com/rbush@2.0.1/rbush.min.js"></script>
<style>
html, body {
width: 100%;
@w8r
w8r / sqrt-non-recursive.js
Last active February 27, 2017 16:36
Non-reqursive sqrt approximation
function sqrt(x, eps = 1e-3){
function mean(a,b){
return (a + b) / 2
}
function newEstimate(estimate){
return mean( estimate, x / estimate )
}
@w8r
w8r / adjListToMatrix.js
Created March 14, 2017 17:22
adjacency list to adjacency matrix
for (var row = 0; row < D.length; row++) {
var values = D[row];
var adj = data.attributes.adjacency[data.list[row]], i, len;
for (i = 0, len = values.length; i < len; i++) {
values[i] = Number.POSITIVE_INFINITY;
}
for (i = 0, len = adj.nodes.length; i < len; i++) {
if (idxMap[adj.nodes[i]] !== undefined) {

Keybase proof

I hereby claim:

  • I am w8r on github.
  • I am w8r (https://keybase.io/w8r) on keybase.
  • I have a public key ASCxf-8Lq10bKs8xt26a7DQqpb7bZ6w0p1JsZExTL2lzEAo

To claim this, I am signing this object:

@w8r
w8r / LICENSE
Last active April 7, 2017 09:10
Planetary graph coarsening
Copyright (c) 2017, Alexander Milevski <info@w8r.name>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@w8r
w8r / Readme.md
Last active June 9, 2017 14:01
Largest empty circle

Largest empty circle

@w8r
w8r / insert_sort.js
Last active July 20, 2017 14:31
Insert sort with indexes
function insertSort(indexes, values) {
for (var i = 1, len = indexes.length; i < len; i++) {
var tmp = indexes[i], j = i;
while (values[indexes[j - 1]] > values[tmp]) {
indexes[j] = indexes[j - 1];
--j;
}
indexes[j] = tmp;
}
@w8r
w8r / liang-barsky.js
Created August 2, 2017 13:19
Liang-Barsky line clipping
/**
* Liang-Barsky function by Daniel White
*
* @link http://www.skytopia.com/project/articles/compsci/clipping.html
*
* @param {number} x0
* @param {number} y0
* @param {number} x1
* @param {number} y1
* @param {array<number>} bbox