Run npm init to create package.json file for the application npm init Then install Express in the app directory app and save it in the dependancies list npm install express –save Generate a self-signed certificate cd sslcert openssl req -nodes -new -x509 -keyout server.key -out server.cert Enable HTTPS in Express (index.js) var fs = require(‘fs’); […]

Read More →

import org.junit.Test; import java.util.HashMap; import java.util.Map; public class FlatmapTest { @Test public void test() { Map<Integer, Map<String, Integer>> map = new HashMap<>(); Map<String, Integer> map1 = new HashMap<>(); map1.put(“a”, 1); map1.put(“b”, 2); map.put(1, map1); map1 = new HashMap<>(); map1.put(“c”, 3); map1.put(“d”, 4); map.put(2, map1); Integer sum = map.values().stream() .map(Map::values) .flatMap(i -> i.stream()) .reduce(0, Integer::sum); System.out.println(sum); […]

Read More →

public class Clazz { int type; int value; BigDecimal dValue; public Clazz(int type, BigDecimal dValue) { this.type = type; this.dValue = dValue; } public Clazz(int type, int value) { this.type = type; this.value = value; } public int getType() { return type; } public int getValue() { return value; } public BigDecimal getDValue() { return […]

Read More →

Sometimes can be useful extract some specific attribute from a JSON string. This can be done easily with com.google.code.gson library in this way. Let’s consider the following JSON: This is the maven dependancy: And finally the code to extract the value of “field2”:

Read More →