Skip to content

Instantly share code, notes, and snippets.

View vicapow's full-sized avatar

Victor vicapow

View GitHub Profile
@vicapow
vicapow / js-to-json
Created May 31, 2015 03:17
js-to-json
#! /usr/local/bin/node
var vm = require('vm');
var Writable = require('stream').Writable;
var ws = Writable();
var chunks = [];
ws._write = function (chunk, enc, next) {
chunks.push(chunk);
next();
};
@vicapow
vicapow / index.html
Created May 30, 2015 23:13
circle packing with depth dependent padding
<!DOCTYPE html>
<html>
<style>
body {
margin: 0;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js" charset="utf-8"></script>
<script>
@vicapow
vicapow / README.md
Last active August 29, 2015 14:19
Possible workshop schedule

Possible schedule for a D3.JS workshop.

@vicapow
vicapow / _.md
Last active August 29, 2015 14:19
test
@vicapow
vicapow / d3-masonic.js
Created March 15, 2015 19:14
masonic demo
// Checkout the project page at: https://github.com/shawnbot/masonic
(function(exports) {
var VERSION = "0.1.0";
d3.masonic = function() {
var columnCount = 0,
columnWidth = 200,
outerWidth = 0,
outerHeight = 0,
@vicapow
vicapow / index.js
Created March 1, 2015 10:59
non-recursive array flattening
var a = [1, 2, [2], [1, 2, [3, 4, [5]]], [[4, 5], 3, 2, 1], [1]];
function flatten(array) {
var stack = [];
var out = [];
var tail;
stack.push({array: array, idx: 0});
while(stack.length) {
tail = stack[stack.length - 1];
if (tail.idx >= tail.array.length) {
@vicapow
vicapow / react+d3-boilerplate.js
Created February 16, 2015 20:51
React + D3 boilerplate
var D3ReactTemplate = React.createClass({
sel: function() { return d3.select(this.getDOMNode()) },
getDefaultProps: function() {
return {
valueAccessor: function(d) { return d.value },
width: 400,
height: 400
}
},
getInitialState: function() {
@vicapow
vicapow / ols.js
Created February 16, 2015 19:48
Ordinary Least Squares
// Ordinary Least Squares
function ols(points_, pointAccessor) {
var points = points_.map(pointAccessor || function(d) { return d })
var xmean = d3.mean(points, function(d) { return d[0] })
var ymean = d3.mean(points, function(d) { return d[1] })
var bNum = points
.reduce(function(c, d) { return (d[0] - xmean) * (d[1] - ymean) + c }, 0)
var bDenom = points
.reduce(function(c, d) { return c + Math.pow(d[0] - xmean, 2) }, 0)
var b = bNum / bDenom
@vicapow
vicapow / Readme.md
Last active March 8, 2023 07:37
WebGL + d3.layout.force

This demo uses d3.layout.force() to calculate the node positions and then passes those to webGL to render them on the GPU.

@vicapow
vicapow / gist:197b75f8951daddf783b
Created February 7, 2015 20:26
PCA from covariance matrix vs sklearn
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
# X = np.array([
# [ -2.500000000000001, -1.873333333333334],
# [ 0.2333333333333325, 0.026666666666666394],
# [ 0.8666666666666663, 0.8266666666666662],
# [ -1.7000000000000006, -1.1733333333333338],
# [ 3.1000000000000005, 2.1933333333333334]