Skip to content

Instantly share code, notes, and snippets.

@amergin
amergin / dc.problem.seriesChart.js
Created Dec 30, 2014
Problem with DC.js series chart grouping and sorting
View dc.problem.seriesChart.js
var createSVG = function($scope, config) {
var getLabel = function(variable, circle) {
return variable + " (" + circle.name() + ")";
};
var getLabels = function() {
var ret = [];
_.each(config.groups, function(group, name) {
_.each( $scope.filterOnSet(group, name).all(), function(obj) {
var circle = obj.key.circle;
View variance-reduce2.js
this.getReducedSTD2 = function(dimensionGroup, variable) {
// see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
var reduceAdd = function (p, v) {
var value = +v.variables[variable];
if( _.isNaN(value) ) {
//pass
}
else {
if( p.n === 0 ) {
p.k = value;
View variance-reduce.js
this.getReducedSTD = function(dimensionGroup, variable) {
// see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Decremental_algorithm
var reduceAdd = function (p, v) {
var obj = p;
var value = +v.variables[variable];
if( _.isNaN(value) ) {
//pass
} else {
obj.n = obj.n + 1;
var oldM2 = obj.M2;
View gist:03a93a16461dcf2ea6e8
var t = beta / _sqrt;
console.log("degrees", degrees);
console.log("beta", beta, "sqrt", _sqrt);
console.log("t=", t, "tprob=", statDist.tprob(degrees, t));
var pvalue = 2 * (1 - statDist.tprob(degrees, t));
console.log("pvalue=", pvalue);
Tulosteet ylläolevasta:
degrees 82 (program):64
beta 1.0097334538696747 sqrt 0.015688694906613447 (program):65
@amergin
amergin / stretch_colors.js
Last active Aug 29, 2015
Stretch available color range to be used based on the values
View stretch_colors.js
// Specs:
// - As a default, the colour range should be scaled so, that at least 70% (..ish) of the colour range is available for the data shown.
// Example: we have a map with lowest positive correlation at r=0.85 and highest at r=0.99 while the negative correlations span from r=-0.2 to r=-0.35. The desired colour range would then be as follows:
// 100% red at r=0.99,
// 30% red at r=0.85,
// white at r=0,
// 30% blue at r=-0.2 and
// 100% blue at r=-0.35.
function CustomScale() {
View dc-js-exported-with-crowbar2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amergin
amergin / grid-config.js
Last active Aug 29, 2015
Overlapping grid windows, angular-gridster
View grid-config.js
$scope.itemMapper = {
sizeX: 'window.grid.size.x',
sizeY: 'window.grid.size.y',
row: 'window.grid.position.row',
col: 'window.grid.position.col'
};
var emitResize = function($element) {
dc.events.trigger( function() {
$rootScope.$emit('gridster.resize', $element);
@amergin
amergin / output.txt
Last active Aug 29, 2015
Math.js regression performance problem, code
View output.txt
_xMatrixTransp size = 2,4084
_xMatrix size = 4084
_normalTargetData size = 4084
View client.py
# -*- coding: utf-8 -*-
# Modified lightsocket import script, based on Lightsocket
# example script by James Thornton (http://jamesthornton.com)
# mundane modification stuff
import os
import commands
import sys
import datetime
import re # regexp
View importclass.py
# -*- coding: utf-8 -*-
# Class implementation for importing stuff to Neo4j
# based on Lightsocket examples by
#James Thornton (http://jamesthornton.com)
from java.lang import Long, Double, Integer, String
from com.tinkerpop.rexster.util import ElementHelper
from com.tinkerpop.blueprints.pgm.impls.neo4j import Neo4jGraph
from com.tinkerpop.blueprints.pgm.impls.neo4jbatch import Neo4jBatchGraph