Monday, May 25, 2015

JavaScript - JSON.parse(), JSON.stringify()


https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Sunday, May 24, 2015

Spring Boot gradle webapp with Java persistence on server side and AngularJS+Bootstrap on client (link)

http://www.rnowak.info/2014/06/spring-boot-and-angularjs-quick-start.html

WebStorm JetBrains - install and run sample AngularJS app

1. Install WebStorm
2. Install NodeJS
3. Check it is installed:
   C:\Users\Andre>npm -version
   2.10.1
4. Run from the AngularJS root project directory npm install:
e.g. listed below.
5. In order to debbug JavaScript check that your Chrome has jetbrains-ide-support extension. If it is not installed look for it here: https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji

JavaScript - testing tools: Jasmine (BDD), JsUnit, Karma (test runner)

1. Jasmine http://jasmine.github.io/ is the priority for testing, due to its BDD approach. 
2. JsUnit is an option (w/o BDD):http://www.jsunit.net/
3. Karma http://karma-runner.github.io/0.12/index.html - it is JavaScript test runner.

AngularJS + Bootstrap best practice

The main point: with AngularJS use pure CSS Bootstrap (don't use BootstrapJS)
https://scotch.io/tutorials/how-to-correctly-use-bootstrapjs-and-angularjs-together

angular.bootstrap - function in module ng:  https://docs.angularjs.org/api/ng/function/angular.bootstrap

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