Can the blockchain kill fake news?

Not actually fake news, but still good for a laugh.
Bloomberg View columnist Megan McArdle has an interesting article on fake news: Fact-Checking's Infinite Regress Problem. Fake news constitutes blocks of information fabricated either wholly or in part from falsehoods to serve a political end. It is an act of commission, as opposed to a related act of omission: reporting blocks of true information chosen selectively to serve a political end.

A natural response to the problem of fake news is the emergence of fact-checkers. But on what basis are these elected or self-appointed fact-checkers to be trusted? Who will guard the guardians? The solution cannot be to appoint another layer of super-fact-checkers, since this process results in an infinite regress. Ultimately, the solution will have to reside in an answer like: "The guarded must guard the guardians."

Fake news--or fake history, for that matter--is not something new. Every society is built on a store of publicly accessible information--a shared history--that evolves over time. But who is assigned write-privileges to this public ledger and how can they be trusted? How can we be sure that Caesar, for example, didn't fabricate much of what is recorded in his Commentaries?

This the problem with public ledgers where everyone has a write-privilege, as we do with the Internet. But the problem is an ancient one. In small social groups, individuals sometimes spread fake news about others or themselves. Whether this information becomes part of the group's shared history may at times depend more on its truthiness than its truthfulness. And false rumors sometimes do destroy individual reputations. A society that cannot guard against individuals freely rewriting its history for personal/political gain at the expense of the community is almost surely doomed to fail. This is not to say that societies cannot function if they rely on a shared history consisting of fake news. Indeed, they may even flourish if fake news takes the form of (say) nation-founding myths designed to promote social cohesion.

You might be wondering what any of this has to do with blockchain. Well, a blockchain is simply a shared (distributed) database (history) where the database is updated and kept secure through some communal consensus algorithm. In this piece "Why the Blockchain should be familiar to you" I argue that blockchain technology has been around for a long time. Unfortunately, there are limitations to what a distributed network of human brains talking to each other through traditional methods can accomplish as communities grow larger. But recent advancements in our brain power (computers) and communications technologies (Internet) have now made a global blockchain possible. This is exactly what Bitcoin has accomplished.
 
And so, as 2016 comes to a close, I put forth a whimsical question. Can blockchain (somehow) kill fake news? No, I don't think so. Well, maybe yes, in some circumstances. (Did I mention that I'm an economist?)

The answer depends on what parts of our shared history we can expect to manage through a computer-based blockchain (and on the details of the consensus protocol). The Bitcoin blockchain appears to have solved the fake news problem for its particular application (essentially, debiting/crediting money accounts--though broader applications appear possible). Might the same principles be used to manage the database at, say, Wikipedia (see How Wikipedia Really Works: An Insider's Wry, Brave Account)?

Ultimately, I'm afraid that the fundamental problem with fake news is not that we don't have the technology to prevent it. The problem seems more deeply rooted in the natural (if unbecoming) human trait of preferring truthiness over truth, especially if truthiness salves where the truth might hurt. I'm not sure there's a solution to this problem apart from trying to instill in ourselves these good Roman virtues (veritas and aequitas, in particular).

Happy New Year everyone! Wishing you all the best for 2017.

***
PS. Just came across this interesting piece: Can Geeks Defeat Lies? Thoughts on a Fresh New Approach to Dealing with Online Errors, Misrepresentations, and Quackery.

How to package a java standalone app using maven assembly

The sample codes below will assemble a zipped package of a java standalone app.

Dependencies:
  • maven-jar-plugin - to create the jar
  • maven-assembly-plugin - to assemble the distribution package
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.broodcamp.App</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

What we have in the code:
  1. In the jar plugin we define the main class and set the classpath to lib.
  2. We supply a descriptor on how we want to assemble the distribution package. We also bind the plugin to maven's package phase and single goal. So that we we execute maven install, the package will be automatically generated.
assembly.xml file
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>MyApp Scraper</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<filtered>true</filtered>
<directory>src/main/resources</directory>
<outputDirectory>./</outputDirectory>
<excludes>
<exclude>assembly.xml</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<useTransitiveDependencies>true</useTransitiveDependencies>
<includes>
<include>*</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>

assembly is an xml file where we define how we want to package our distribution. What we have:

  1. format of the package is zip
  2. We package all the resources inside src/main/resources folder excluding assembly.xml
  3. We include all the jar files in the ${project.build.directory} folder which is basically the target.
  4. We save the maven dependencies in the lib folder. Note that we set the class path to the same directory. We set transitive dependencies to true and includes all. For some reason, without include=*, some transitive dependencies are not included.

How to send http request using apache httpcomponents library

There are many ways to send request to a server and one of them is by using http client library. But this library has 2 versions now. The old httpclient and this httpcomponents. We will provide a sample code to try the latter.

But before that we need to add maven dependency to our project, this is assuming you are working on a maven project.

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
</dependency>

A method that sends post request with variables:

public static String postRequest(String url, Map<String, String> params) throws IOException {
log.debug("sending POST request to={}, params={}", url, params);

try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
List<NameValuePair> postParameters = new ArrayList<>();

// add post parameters
params.forEach((key, value) -> {
postParameters.add(new BasicNameValuePair(key, value));
});

// initialize the post request
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(postParameters));

StringBuilder responseString = new StringBuilder();

// execute the request
HttpResponse response = httpClient.execute(httpPost);

// read the response
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity responseHttpEntity = response.getEntity();
InputStream content = responseHttpEntity.getContent();

BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = buffer.readLine()) != null) {
responseString.append(line);
}

// release all resources held by the responseHttpEntity
EntityUtils.consume(responseHttpEntity);

log.debug("html-------\r\n" + responseString);

return responseString.toString();
} else {
log.error("Error sending request with status=" + response.getStatusLine().getStatusCode());
}

}

return "";
}

And finally a sample method call:

public Map<String, String> params= new HashMap<>();
params.put("param1", "value1");
params.put("param2", "value2");
params.put("param3", "value3");

MyClass.postRequest(AppSettings.MEMBER_NAME_URL, params);

How to create a data table in angular using ngTable

I'm trying to evaluate front end frameworks since it's becoming more and more popular lately (I'm more of a backend developer using primefaces). And so I'm looking at angular2 and react, but in this tutorial we will be trying to develop a data table from angular2.

What surprises me is, though there are a lot of ui frameworks, available production ready made components are lacking compared to primefaces.

Let the code talk for itself. Note though that I didn't use typescript yet since ngTable doesn't have a documentation yet on its website.

Also notice that the original web service that I use supported paging and sorting, that's why I have some extra parameters in the request: Page, RecsOnPage and SortBy. I did not bother to provider client side paging because it's already in the docs and is easy to understand.

<html>

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script src="https://unpkg.com/angular@1.5.5/angular.js"></script>
<script src="https://unpkg.com/ng-table@3.0.1/bundles/ng-table.min.js"></script>

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"></link>
<link href="https://unpkg.com/ng-table@3.0.1/bundles/ng-table.min.css" rel="stylesheet"></link>

<script>
var app = angular.module('ngTableTest', ['ngTable']);

app.controller("mainController", function($scope, NgTableParams, mainControllerService) {
console.debug('mainController.init');

$scope.tableParams = new NgTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: 0, // length of data
getData: function(params) {
var sortNameValue = "";
for (var keyName in params.sorting()) {
sortNameValue = keyName;
sortNameValue = sortNameValue + "_" + params.sorting()[keyName];
}
return mainControllerService.getData(params.page(), params.count(), sortNameValue).then(function(data) {
console.debug("data received length=" + data.data.RestResponse.result.length);
params.total(data.data.RestResponse.result.length); // set total for recalc pagination
return data.data.RestResponse.result;
});
}
});

console.log('mainController.end');
});

app.service("mainControllerService", function($http) {
console.debug('mainControllerService.init');

var service = {
cachedData: [],
getData: function(page, count, sorting) {
console.debug("fetching page=" + page + ", count=" + count + ", sorting=" + JSON.stringify(sorting));
var params = {
Page: page,
RecsPerPage: count,
SortBy: sorting
};
var config = {
params: params
}
var promise = $http.get("http://services.groupkt.com/country/get/all", config)
.success(function(response) {
console.debug('downloaded ' + response.RestResponse.result.length + ' records');
angular.copy(response.RestResponse.result, service.cachedData);
});
return promise.then(function(result) {
return result;
});
}
}

return service;
});
</script>
</head>

<body>
<div ng-app="ngTableTest" ng-controller="mainController">
<div loading-container="tableParams.settings().$loading">
<table class="table table-condensed table-bordered table-striped" ng-table="tableParams" showfilter="false">
<tbody>
<tr ng-repeat="x in $data">
<td data-title="'Name'" sortable="'name'">{{ x.name }}</td>
<td data-title="'Alpha2 Code'" sortable="'alpha2_code'">{{ x.alpha2_code }}</td>
<td data-title="'Alpha3 Code'" sortable="'alpha3_code'">{{ x.alpha3_code }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>

</html>

Code is also available here for easier download: https://github.com/czetsuya/AngularNgTable

Maybe next article is about using typescript :-)

References:
http://ng-table.com/

How to run a wildfly server inside docker

Before we begin you must configure docker, I am using Ubuntu so I followed the guide here: https://docs.docker.com/engine/installation/linux/ubuntulinux/. Choose the appropriate OS that applies to you.

Let's do this in sequence:

  1. Checkout and compile the very basic javaee war from https://github.com/czetsuya/hello-javaee.
  2. In Ubuntu create a new folder: wildfly-hello:
    >mkdir wildfly-hello
  3. Copy hello-javaee.war inside wildfly-hello.
  4. Create a Dockerfile and insert the lines below inside the same folder.

    from jboss/wildfly
    run /opt/jboss/wildfly/bin/add-user.sh admin admin@1234 --silent
    add hello-javaee.war /opt/jboss/wildfly/standalone/deployments/
    cmd ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
  5. Inside the wildfly-hello folder build the Dockerfile.
    >docker build -it wildfly-hello .
  6. Run the docker image
    >docker run wildfly-hello
  7. Get the ip address of the container by:
    >docker ps - to get the container id
    >docker inspect -f '{{ .NetworkSettings.IPAddress }}' CONTAINER_ID
  8. Now we should have the ip address of docker, we can now open wildfly in the browser.
What does the lines in step 3 means?
-from is a docker keyword use to import an image from docker hub hub.docker.com
-run is a command that runs an executable file, in this case we are adding a user with application management role
-add lets us add a file inside the container
-cmd tells the docker to execute this by default, when we execute docker run

Teknisk trøbbel

Med mindre du er en multinasjonal bank som forvalter hundrevis av milliarder, bør du holde deg unna teknisk analyse.

“I realized that technical analysis didn’t work when I turned the chart upside down and didn’t get a different answer.” – Warren Buffet

Teknisk analyse betyr å bruke tidligere kursutvikling til å forutse fremtidig pris. Dersom teknisk analyse faktisk fungerer, er det som å plukke tusenlapper fra fortauet.

Men siden kursutviklingen er så tilgjengelig og metodene så velkjente, er det vanskelig å forstå hvorfor de store profesjonelle aktørene, som er langt hurtigere enn amatørene, lar alle pengene ligge der.

Neida, vi kan ikke avskrive teknisk analyse helt. Det kommer an på om det er en student som sitter på gutterommet sitt og tegner streker på en graf eller et multinasjonalt selskaper med hundrevis av «kvanter» med doktorgrad på lønningslisten og med enorme dataressurser tilgjengelig. Finanskjemper kan kanskje tjene noe, men amatørene har små sjanser.


De største aktørene har en topp kvalifisert stab og avanserte og hemmelige algoritmer som analyserer børskursene kontinuerlig. Om selve handelen basert på de hemmelige algoritmene faktisk er lønnsomt vet vi ikke i og med at resultatene aldri publiseres i vitenskapelige tidsskrift.

Men kvantene og datasentrene kan også fungere som rene markedsføringsverktøy for å selge en illusjon om høyteknologisk trading. At finanskjempene på en eller annen måte tjener penger på teknisk analyse er det liten tvil om, men vi vet ikke om det er fra selve handelen eller fra klientene fortjenesten høstes.

Dette er dårlig nytt for amatørene. De største aktørene driver større, er raskere og har langt lavere kostnader enn amatørene. Når proffene i tillegg har markedsføring som en ekstramotivasjon, så er amatørene sjanseløse. Konkurransen mellom de store aktørene vil da presse ut hver eneste lille dråpe av fortjeneste helt til det ikke finnes noe mer. Når amatørene kommer etter med sine «trendkanaler» og «brudd» er det ikke mer å hente.

Teknisk analyse brukes altså også av proffene. Forskning viser at så godt som alle fondsforvaltere bruker en eller annen form for teknisk analyse. Og teknisk analyse kan nok være lønnsomt for de store, på en eller annen måte. Men det virker veldig usannsynlig at det kan ha noe for seg for amatørene og småinvestorene.

En stor forskjell mellom de profesjonelle og amatørene er at de proffe tester sine algoritmer med vitenskapelige metoder for å identifisere strategier som faktisk fungerer. En vitenskapelig holdbar metode innebærer at en lovende strategi må passere to steg. I steg to testes metoden på nye friske data, og den må bestå begge testene for å kunne erklæres som lønnsom. I tillegg må metoden overvinne transaksjonskostnadene, som kan bli betydelige dersom antall transaksjoner er høyt.

De fleste amatørinvestorer kommer ikke til steg én en gang. Om det i det hele tatt testes er det sjelden snakk om vitenskapelig holdbare tester. Den vanlige fremgangsmåten for en amatørinvestor er å kjøpe en bok med femti år gamle teorier som aldri har vært testet fordi teoriene er så kompliserte, i den tro at det skal fungere. At disse bøkene som oftest mangler kapitler med vitenskapelig testing forteller jo sitt. Overbevisning er viktigere enn bevis i denne bransjen.

De viktigste seleksjonskriteriene er gjerne at teoriene høres rimelige ut eller anekdotisk bevis for at noen har sagt at de tjener på det. Ingen kvantitativ testing av resultatene eller måling av prestasjoner. Joda, det går an å tjene penger på teknisk analyse, men da må du skrive boken og ikke kjøpe den.


Teknisk analyse: Å bruke kursutviklingen og volum til å forutse fremtidige priser.

Kvant: Fra engelsk ("quant"). Forkortelse for "kvantitativ analytiker". Betegnelsen brukes på matematisk og statistisk orienterte analytikere som utvikler programmer og handelsalgoritmer for finansielle aktører.