How to create a MEAN+ stack application (MongoDB, Express, Angular, Node + Bootstrap, Jade)

Steps

      Create a Node.js with Express.js App
      Create a Git repository and clone to localhost
      Add Angular.js
      Add Bootstrap
      Add MongoDb
      Add Jade
      Add an API for GET /people
      Connect to MongoDb
      Create a sortable table with Angular

Create a Node.js with Express.js App

I will be using Bluemix to host, build and deploy my Node.js application and the MongoDb service. I am developing on my localhost for unit testing before I upload my application to Bluemix, but you can also use the online editor and online Git instead.

1. If you do not have a Bluemix account yet, sign up for a free account at http://ibm.biz/bluemixnyc,
2. Once you have an account, go to your Bluemix console at https://console.ng.bluemix.net/,
3. Go to your Dashboard,
4. In the ‘Cloud Foundry Apps’ box, click ‘CREATE APP’,

5. Choose ‘WEB’

Continue reading

Calling a Watson service in Java

Overview

Note: this API needs to be updated to v2. Identify is now a resource on the Language Translation API.
http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation/api/v2/

Making an HTTP REST API POST request in Java is in principle as simple this:
Request request = Request.Post(serviceURI)
.addHeader("Authorization", basicAuthorization)
.bodyString(body, ContentType.APPLICATION_FORM_URLENCODED);
Executor executor = Executor.newInstance();
String response = executor.execute(request).returnContent().asString();

This code, uses the Apache Fluent API, which exposes only the essentials of the Apache HTTPClient.

The Authorization header is required for authentication by the Watson API, and is a base64 encoded string.
String auth = username + ":" + password;
String basicAuthorization = "Basic "+ Base64.encodeBase64String(auth.getBytes());

The POST request is “x-www-form-urlencoded” and in Java consists of a List<NameValuePair>:
List<NameValuePair> params = new ArrayList<NameValuePair>();

Continue reading

Call IBM Watson APIs to add Machine Learning to your App

You can easily add very cool IBM Watson APIs to your application. You need to sign up for Bluemix, create an application and bind APIs or services to the app. This will create credentials (username and password) for each API or service.

Create a Bluemix acccount

First if you have not signed up for a Bluemix account yet, go to http://ibm.biz/bluemixnyc and Sign Up.

Create an App

Once you have confirmed your account, go to the Catalog and choose any Runtime. We will only use the runtime to bind services to, which will give us API credentials. For example, name the app ‘my-app1’.

Add a Service

Now, to add Services either go to Catalog > Services, and add a service to your app, or go to your app’s admin page. Bluemix is based on Cloud Foundry, so apps in Bluemix are listed under ‘CF Apps.’ Go to Dashboard > CF Apps > ‘my-app1’, and click the ‘Add a Service or API.’ I will add Personality Insights to my app in this example. Edit the required fields and click the Create button. Bluemix might ask you to restage your app. Now we’re ready to call the Personality Insights API.

Call the Watson API

To make a REST call to a Watson API, you must add an Authorization header with a Base64 encoded “Basic :” string. To generate the Basic Authorization header, use the colon as a separator for username and password and Base64 encode the Authorization string.

String username = "username from your service credentials";
String password = "password from your service credentials";
String s = username + ":" + password;
byte[] b = s.getBytes();
String enc = Base64.encodeBase64String(b);
String authorization = "Basic "+enc;

To call the API with the above credentials use the following curl statement from command line.

curl -X POST -H "Authorization: Basic BzAvEATz4UYqKfU5JA66GSIwKNgdATGiADR8YiWaOSH2Purd6tedhKUJaPa3KLshLq==" -H "Content-Type: text/plain" -H "Accept: application/json" -H "Accept-Language: en" -H "headers: true" -d 'put your text here' https://gateway.watsonplatform.net/personality-insights/api/v2/profile

For the API reference details go here
http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/apis/#!/personality-insights/profile

This curl command will return a response object that you can visualize with the Visualize Personality Insights API.
http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/apis/#!/personality-insights/visualize

Mikhail Bulgakov, Morphine (1926)

Mikhail Bulgakov, Morphine (1926), 55p

Bulgakov’s Morphine is a simple short story that uses his experience as a doctor and morphine addict in simple diary form. The most beautiful aspect of Morphine is the evidence of what a great short story requires, a genuine heartfelt compassion, the experience of real life, maybe the auto-biographical element sets the quality of any short story apart from a fantasy story. I’m a big fan of fictionalized auto-biographical material, Morphine proves why. The story reads easily in a day, without losing attention, as if it was written in equal amount of time.

Elena Ferrante, The Days of Abandonment (2002)

Elena Ferrante, The Days of Abandonment (2002), 188p

With the popularization of the literary markets, apparently an inevitable consequence of following a purist American theology of Capitalism, eliminating all public investments to balance the public good out of the equation of interest, it can be difficult to find elevating literary writers these days. I have almost completely stopped sifting through the may top ten lists, awards and nominations like the homeopathic New York Times best seller list, such a Mayan veil and scam of literature was never invented before, or the New Yorker with its blase short stories that fail to shock any man with a real taste for life. How can one take the American literary landscape every serious again, it’s worth a novel full of labyrinths.

But Elena Ferrante, if for a moment we consider this her real name, has the true spirit of an author, she feels enough has been done to a book once it has been written, once she has poured her confessions to paper and added an artificial construct to make it credible. Once in print, only the reader can add meaning to a story. I believe strongly that only out of such absence of vanity, out of such love for the imagination that reality is shunned, and certainly the false desire to be in the public spotlight, can bring forth any literature close to being worth reading.

One can place some remarks to the almost fantastical scene of the protagonist taking the ‘key’ into her mouth in order to ‘unlock’ the ‘door’. This is almost a childish mistake of heavy symbolism in a too easily recognizable form, but apart from this scene that sadly lasts for pages, the book remains true to credible fiction, and though she perhaps could dig deeper into her self and add more revealing reflections of her human soul, the book carries a reflective burden with it. Another point of criticism is that women tend to identify with being victimized too easily, and this book is no relief from it, not a very emancipated protagonist perhaps. It’s not how Marguerite Duras would have witnessed the story.

But nevertheless, Ferrante delivers a true novel of the human soul, and The Days of Abandonment is a mirror to many.

The New Yorker, Women on the Verge, The fiction of Elena Ferrante, by James Wood (21 January 2013)

Faces (52)

The tip of her nose was powdered thickly, round like a ripe plumb. She owned a pair of glazing, dark brown eyes, circumligned by a crisp, black border, like burnt pits hanging from a tree, above her pointy, white chin, cleaved by the sharp, blazingly red stripes of her thin lips.

Keith Devlin, The Man of Numbers (2011)

themanofnumbers_keithdevlin_2011 Keith Devlin, The Man of Numbers (2011) is a largely historical biography about Leonardo Bigollo (~1170 – ~1250 CE), better known in his own time as Leonardo Pisano or in our time as Leonardo Fibonacci.

Fibonacci is best known for the sequence of Fibonacci numbers (1,2,3,5,8,13,21… etc), whose limit of ratios we know as the Divino Proportion coined by Luca Pacioli (1445-1517), the Golden Ratio coined by Martin Ohm (1792-1811), or as it is called in Euclid’s Elements, the extreme and mean ratio. Fibonacci numbers are only one of several mathematical puzzles posed in his Liber Abaci (1202), the Book of Calculation, a teaching book for mercantile administration, in which Leonardo describes the basics of the Hindu-Arab counting system, at the time largely unknown in Europe, where the Roman and medieval systems were still dominant. Devlin argues that the Liber Abaci caused a mathematical revolution that facilitated the mercantile boom of the Renaissance.

The book by Devlin is a little light on facts and mathematics, though none are absent, maybe because there are only few historic facts known about Leonardo, and because most of the math in our time sounds like very basic modern mathematics described in very cryptically described textual puzzles. If you really want to know everything about Fibonacci’s influence, you should read the translation of the Liber Abacci. If you really want to know everything about the mercantile revolution, you should read perhaps about Cosimo de’ Medici (1389-1464), or about the scientific revolution, you should read perhaps about Galileo Galilei (1564-1642).