Saturday, May 23, 2015

JavaScript - shuffle an array, mix up array elements randomly

Mix up (shuffle) array JavaScript function is taken from here:
Fisher–Yates Shuffle http://bost.ocks.org/mike/shuffle/
function shuffle(array) {
  var m = array.length, t, i;

  // While there remain elements to shuffle…
  while (m) {

    // Pick a remaining element…
    i = Math.floor(Math.random() * m--);

    // And swap it with the current element.
    t = array[m];
    array[m] = array[i];
    array[i] = t;
  }

  return array;
}

Friday, May 22, 2015

JavaScript D3 - random integer number

Decimal values are fine, but if you ever need whole numbers, you can use JavaScript’s Math.round() method. For example, you could wrap the random number generator from this line
    var newNumber = Math.random() * 30;
as follows:
    var newNumber = Math.round(Math.random() * 30);
Example:
d3.selectAll("p").style("color", function() { return "hsl(" + Math.round(Math.random() * 360) + ",100%,50%)"; });

JavaScript D3 - The power of data()

http://alignedleft.com/tutorials/d3/the-power-of-data

Wednesday, May 20, 2015

Create ls command for Windows cmd

In order to enable cmd on Windows run ls command just run from command line this:
echo dir %1 > %systemroot%\system32\ls.bat

Javascript D3 good basic explanation

http://synthesis.sbecker.net/articles/2012/07/08/learning-d3-part-1

JavaScript D3 - example how the function(d, i) works

http://jsfiddle.net/M8nK8/

==HTML==
<script src="http://d3js.org/d3.v3.min.js"></script>
<section></section>


===JS D3==

var data=[10,20,30,40];

var lis = d3.select("section")
          .append("ul")
            .selectAll("li")
            .data(data)

lis.enter()
 .append("li")
 .text(function(d,i){ return "item n° "+i+" has value: "+d})

JavaScript D3 - forEach() vs each() function

The main takeaway is that, using .each() you get access to 3 things you need: dthis and i. With .forEach(), on an array (like in the example from the beginning) you only get 2 things (d and i), and you'd have to do a bunch of work to also associate an HTML element with those 2 things. And that, among other things, is how d3 is useful.

http://stackoverflow.com/questions/13465796/d3-javascript-difference-between-foreach-and-each

Tuesday, May 19, 2015

GWT DataGrid with LeafValueEditor

====== UIBINDER =======

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'
             xmlns:b.grid='urn:import:org.gwtbootstrap3.client.ui.gwt'
             xmlns:b='urn:import:org.gwtbootstrap3.client.ui' >