1. 2017-12-15 - Pretty print duration; Tags: Pretty print duration

    Pretty print duration

    Performing a reindex job in Elasticsearch gives you the time the job took.

    curl -XPOST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
    > {
    >   "source": {
    >     "index": "fo-log-2017.05.05"
    >   },
    >   "dest": {
    >     "index": "fo-log-fix-2017.05.05",
    >      "pipeline": "kt-improve"
    >   }
    > }'

    The outcome.

    	"took": 13147934,
    	"timed_out": false,
    	"total": 15855322,
    	"updated": 0,
    	"created": 15855322,
    	"deleted": 0,
    	"batches": 15856,
    	"version_conflicts": 0,
    	"noops": 0,
    	"retries": {
    		"bulk": 0,
    		"search": 0
    	"throttled_millis": 0,
    	"requests_per_second": -1.0,
    	"throttled_until_millis": 0,
    	"failures": []

    13147934 milliseconds is a little bit cryptic. A simple way to give your customers a more human readable information is the JavaScript pretty-ms package and its CLI.

    npm install --global pretty-ms
    npm install --global pretty-ms-cli

    The usage prints 3 hours, 39 minutes, 7.9 seconds

    pretty-ms 13147934
    3h 39m 7.9s
  2. 2017-07-21 - Minify JSON; Tags: Minify JSON

    Minify JSON

    Another way to minify JSON is to use the npm package.


    npm install -g json-minify


    Having a test-data.json file

      "friends": [
          "id": 0,
          "name": "Amparo Henry"
          "id": 1,
          "name": "Stone Ferguson"
          "id": 2,
          "name": "Cheryl Rocha"

    Defaults to stdout

    tan@omega:~$ json-minify test-data.json
    {"friends":[{"id":0,"name":"Amparo Henry"},{"id":1,"name":"Stone Ferguson"},{"id":2,"name":"Cheryl Rocha"}]}

    Write to new file

    json-minify test-data.json > minified.json

    Or use it as pipe

    tan@omega:~$ curl -s http://elasticsearch:9200 | json-minify
    {"name":"dev","cluster_name":"fo-test","cluster_uuid":"sE_HoGSZRKyhGHN9lk2gSA","version":{"number":"5.4.3","build_hash":"eed30a8","build_date":"2017-06-22T00:34:03.743Z","build_snapshot":false,"lucene_version":"6.5.1"},"tagline":"You Know, for Search"}
  3. 2017-07-21 - Convert JSON 2 CSV in JavaScript; Tags: Convert JSON 2 CSV in JavaScript

    Convert JSON 2 CSV in JavaScript

    json2csv is java script library which allows conversion of the format csv and json on a linux terminal.


    Install it with npm

    npm -g json2csv


    A quick demonstration


        "_id": "5971ebce9b51d3f1afee6a34",
        "index": 0,
        "guid": "c48c4f70-e825-4be9-a1a9-63a145dc469d",
        "isActive": false
        "_id": "5971ebce3dc681e6c106cca5",
        "index": 1,
        "guid": "3f3ad5d9-f59b-4f79-92c6-b589fc29a3a5",
        "isActive": false
        "_id": "5971ebce96c43c94c6b984de",
        "index": 2,
        "guid": "ac24adb1-1c74-4f1f-ba6c-c108f76941f4",
        "isActive": false

    Export to CSV

    $ json2csv -i test-data.json -o output.csv

    The above input will result in this output:

  4. 2017-05-28 - Reduce Java Script content serving; Tags: Reduce Java Script content serving

    Reduce Java Script content serving

    To improve page speed on websites, one technique is to deliver less java-script files than leave them in their original state. While it is good for maintenance and separation of concerns to isolate or have a component structure, it isn’t in the way presenting or serving the content. This post demonstrate how to minify, or in the same sense uglify, your java script code with the node package uglify-js.

    UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit.


    I do assume you are familiar with node, and therefore can install uglify with npm.

    sudo npm install -g uglify-js

    Example minimization of input.js, writing the to output.min.js

    uglifyjs --compress --mangle -- input.js > output.min.js

    You may use tools like gulp or grunt to automatize the minimization of your java script files. It doesn’t stop with your own files. For instance using third party solutions like lunrjs. The lunrjs version 2.0.4 doesn’t provide any minimized version of its script. UglifyJS does a pretty good job.

    Another challenge is to merge the minimized versions into one single java script file. Just loop over your minimised versions and append them to your desired java script file, e.g.

    for i in $(ls *.min.js); do cat $i >> ~/build/cinhtau.min.js; done

    This is one of several solutions to reduce the delivery of java script files for your website. So far it was the simplest one.

  5. 2015-07-09 - Google Charts; Tags: Google Charts

    Google Charts

    Google Charts is a Java Script library that offers you to visualize data as charts. Through GWT (Google Web Toolkit) it is accessible in Java. It is also accessible via Flash. For any data e.g. metrics, org-charts or other statistical stuff.

    Google Org Chart

    Take a look at the FAQ and Terms of Services about the capabilities and legal issues.