Category Archives: Uncategorized

Jenkins Best Practices – Practical Continuous Deployment in the Real World — GoDaddy Open Source HQ

Source: Jenkins Best Practices – Practical Continuous Deployment in the Real World — GoDaddy Open Source HQ

Java Beans and DTOs

DTO (Data Transfer Object)

Data Transfer Object is a pattern whose aim is to transport data between layers and tiers of a program. A DTO should contain NO business logic

public class UserDTO {
    String firstName;
    String lastName;
    List<String> groups;

    public String getFirstName() {
        return firstName;
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    public String getLastName() {
        return lastName;
    public void setLastName(String lastName) {
        this.lastName = lastName;

    public List<String> getGroups() {
        return groups;
    public void setGroups(List<String> groups) {
        this.groups = groups;

Java Beans

Java Beans are classes that follows certain conventions or event better they are Sun/Oracle standards/specifications as explained here:

Essentially, Java Beans adhere to the following:

  • all properties are private (and they are accessed through getters and setters);
  • they have zero-arg constructors (aka default constructors)
  • they implement the Serializable Interface

The main reason why we use Java Beans is to encapsulate

public classBeanClassExample() implements {

  private int id;

  //no-arg constructor
  public BeanClassExample() {

  public int getId() {
    return id;

  public void setId(int id) { = id;

So, yeah what is the real difference? If any?

In a nutshell, Java Beans follow strict conditions (as discussed above) and contain no behaviour (as opposed to states), except made for storage, retrieval, serialization and deserialization. It is indeed a specification, while DTO (Data Transfer Object) is a Pattern on its own. It is more than acceptable to use a Java Bean to implement a DTO pattern.

Avro is amazing!

Why Avro For Kafka Data?

Scala, give me a break :)

I have been recently asked whether it is possible to use break (and continue as well) in a loop with Scala and it occurred to me that I have never come across such a case. Coming from Java, I do know how to employ break and continue in a while loop, for example, so why would it be different in Scala, considering that it is builds on top of the JVM? It is actually a bit more complicated than that. Although Scala does not specifically have the keywords break and continue, it does offer similar functionality through scala.util.control.Breaks.

Here is an example of how to use break from the Class Breaks, as follows:

import scala.util.control.Breaks._

val in = new BufferReader(new InputStreamReader(

breakable {
  while (true) {
    println ("? ")
    if (input.readLine() == "") break

In Java, the above would corresponding to this:

BufferedReader in =
   new BufferedReader(new InputStreamReader(;
   while (true) {
     if (in.readLine() == "") break

The breakable function has become available from Scala 2.8 onwards and before that we would have tacked the issues mostly through 2 approaches:

  • by adding a boolean variable indicating whether the loops keeps being valid;
  • by re-writing the loop as a  recursive function;

Happy Scala programming 🙂


2 minutes to spare: Apache NiFi on Mac

As a Mac user, I usually run Apache NiFi using one of the two approaches:

  • by standing up a Docker container;
  • by downloading and installing locally on your Mac;

Running a NiFi Container

You can install Docker on Mac via Homebrew:

brew install docker

Alternatively it is possible to download the Docker Community Edition (CE): an easy to install desktop app for building, packaging and testing dockerised apps, which includes tools such as Docker command line, Docker compose and Docker Notary

After installing Docker, this will let you pull the NiFi image:

docker pull apache/nifi:1.5.0

Next, we can start the image and watch it run:

docker run -p 8080:8080 apache/nifi:1.2.0

Downloading and Installing NiFi locally

Installing Apache NiFi on Mac is quite straightforward, as follows:

brew install nifi

This assumes that you have Homebrew installed. If that is not the case, this is the command you will need:

ruby -e "$(curl -fsSL" < /dev/null 2> /dev/null

Here is where NiFi has been installed:


Some basic operations can be done with these commands:

bin/ run, it runs in the foreground,

bin/ start, it runs in the background

bin/ status, it checks the status

bin/ stop, it stops NiFi

Next step, whatever approach you took at the beginning, is to verify that your NiFi installation/dockerised version is running. This is as simple as visiting the following URL:


Happy Nif-ing 🙂

Machine Learning’s ‘Amazing’ Ability to Predict Chaos

Machine Learning’s ‘Amazing’ Ability to Predict Chaos

Download SQUID – Your News Buddy

An Oracle JDBC Client

A while ago I was tasked to write a small application in order to connect to an Oracle Database and perform a set of simple queries. For such a task, I have employed the DAO (Data Access Object) pattern and a corresponding DAO Interface. A basic Java client, in turn, calls the instantiation of such DAO class, which implements a the DAO interface. As follow, the application in its internal details:

Oracle DB Client 

[code language=”java”]
package oracledb.connection.client;
import oracledb.connection.dao.OracleDB_DAO;

public class OracleConnectionClient {

public static void main(String[] args) throws Exception {

OracleDB_DAO dao = new OracleDB_DAO();

The Data Access Object (DAO) implementation. The method[code]readPropertiesFile()[/code]

parses a properties file containing the access credentials and DB connection details.


[code language=”java”]
package oracledb.connection.dao;

import java.sql.*;
import java.util.Properties;

public class OracleDB_DAO implements OracleDB_DAO_Interface {

public static String SAMPLE_SELECT_QUERY = “SELECT * FROM CUSTOMERS WHERE FirstName = ‘Eliott’ AND LastName = ‘Brown'”;

private static String driverClass = “oracle.jdbc.driver.OracleDriver”;
private Connection connection;
private static String dbUrl;
private static String userName;
private static String password;

static String resourceName = “”;

* Read the properties Initialise the DAO
* @throws IOException
* @throws ClassNotFoundException

public void readPropertiesFile() throws IOException, ClassNotFoundException {

ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties props = new Properties();
InputStream resourceStream = loader.getResourceAsStream(resourceName);

// Return the properties
dbUrl = props.getProperty(“dburl”);
userName = props.getProperty(“dbuser”);
password = props.getProperty(“dbpassword”);

// Load the

* (non-Javadoc)
* @see oracledb.connection.dao.OracleDB_DAO_Interface1#openConnection()
public void openConnection() throws SQLException {

// get the connection to the database
System.out.println(“Establishing the Connection to the Database”);
try {
connection = DriverManager.getConnection(dbUrl, userName, password);
} catch (SQLException ex) {

* (non-Javadoc)
* @see oracledb.connection.dao.OracleDB_DAO_Interface1#closeConnection()
public void closeConnection() throws SQLException {
if (connection != null) {
// close the connection

* (non-Javadoc)
* @see oracledb.connection.dao.OracleDB_DAO_Interface1#
* getFirstNameAndLastNameFromCustomers()
public ResultSet getFirstNameAndLastNameFromCustomers() throws SQLException, IOException {
// create the prepared stmt
Statement stmt = connection.createStatement();
// assign the query to a variable
// execute the query
ResultSet rs = stmt.executeQuery(sql);
System.out.println(“This print the ResultSet for getPlanByMSISD ” + rs);
PrintWriter csvWriter = new PrintWriter(new File(“sample.csv”));

stmt.close(); // close statement
return rs;

* (non-Javadoc)
* @see oracledb.connection.dao.OracleDB_DAO_Interface1#getDBCurrentTime()
public String getDBCurrentTime() throws SQLException, IOException {
String dateTime = null;
// create the prepared stmt
Statement stmt = connection.createStatement();
ResultSet rst = stmt.executeQuery(“select SYSDATE from dual”);
while ( {
dateTime = rst.getString(1);
// close the resultset
System.out.println(“This prints the dateTime from the DB ” + dateTime);
return dateTime;

The DAO Interface that defines the standard operations to be performed on a model object:

[code language=”java”]
package oracledb.connection.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

public interface OracleDB_DAO_Interface {

* Open the Dao Connection
* @param
* @throws SQLException
* @throws IOException
void openConnection() throws SQLException;

* Close the connection
* @throws SQLException
void closeConnection() throws SQLException;

* Get the resultset from the the select query
* @throws SQLException
* @throws IOException
ResultSet getFirstNameAndLastNameFromCustomers() throws SQLException, IOException;

* Get the Current Time via DB Query
* @return
* @throws SQLException
* @throws IOException
String getDBCurrentTime() throws SQLException, IOException;


12+ must have Atom packages to work in JavaScript | Void Canvas

Source: 12+ must have Atom packages to work in JavaScript | Void Canvas

IE11 and String.prototype.includes() in Angular directives

Just come across an interesting behaviour with Angular directives and E11. Apparently E11 does not seem to work with the function String.prototype.includes(), for example:

[code language=”html”]
<div ng-if="str.includes(‘test’)" class="someClass"><span>Some text</span></div>

where str == ‘Sometest‘ and the generic syntax is as below:

str.includes(searchString[, position])

Browser’s compatibility is an issue with IE11 and generally speaking it is poor across IE, so it is highly recommended to use this, instead:

[code language=”html”]
<div ng-if="str.indexOf(‘test’) >= 0" class="someClass"><span>Some text</span></div>

as per the syntax below:

str.indexOf(searchValue[, fromIndex])

IndexOf method returns the index of the string as passed in.  If the value is not found, it returns -1.

Further documentation:

MDN documentation for includes

MDN documentation for indexOf

Build a Watson IBM conversational bot in 15 minutes

Watson is a question answering system, also know as QA, developed by IBM (named after its IBM’s first CEO Thomas J. Watson) and capable to answer questions posed in natural language. Watson has a variety of applications and domains such as Healthcare , IoT, Education, Financial Services, Marking and Customer Engagement and recently Weather Forecasting. Having come across chatterbots (or chatbots) in the past and always being interested in the long lasting debate around Artificial Intelligence and Thinking Machines (the Turing Test, John Searle’s Chinese Room and many more), I wanted to try out the IBM Watson Conversational Bot and build a simple bot that can have an application in a customer service type of scenario.

Setting up a Free Account on Bluemix

It is possible to set up a free Bluemix account to experiment with Watson Conversation. Bluemix is the IBM Cloud Platform as a Service and signing up here you can build your bot by picking Conversation from the IBM Bluemix Catalog. The Lite Pricing Plan (Free) will cover all you need to get started with the bot, for example up to 5 workspaces, up to 25 intents and entities (we will clarify later in this entry what they are). It also includes 10.000 API calls per months (POST message method calls only).

After selecting the Lite Pricing Plan, a Conversation instance will be created and you will be presented with some info on Conversation and on the right side of the new window the option to launch the instance (via the “Launch tool” button).

Creating a Workspace

The very first step into this journey is to create a workspace where you project will reside. Each workspace corresponds to one and only one bot. The below screenshot shows a newly created Workspace named “My First Bot project”

Screen Shot 2017-10-28 at 20.06.57

Configuring Intents

An intent is a task/goal that the user wants to perform or achieve and is expressed by a particular user’s input . For example, changing their password, downgrading their price plan or making a complaint. When planning the intents in your bot application, it is important to consider what the customer/user would like to do in a specific scenario and, in turn, what the bot itself will be able to handle.

In our example, we will configure 4 classes of intents. 2 for opening and closing statements (greeting the customer’s adviser and parting at the end of conversation) and 2 that would cover requests on the customer’s account.

  • greetings
  • goodbyes
  • account
  • account_changes

This is the overall UI the user will be presented with showing “Intents”, “Entities” and “Dialog”:

Screen Shot 2017-10-28 at 20.08.51.png

Here are (some) intents for the class #greetings:

Screen Shot 2017-10-28 at 20.11.29.png

Here some of those for the class #goodbyes:

Screen Shot 2017-10-28 at 20.15.14.png

Now that we have covered opening and closing statements in a conversation, we can include some intents for the class #account:

Screen Shot 2017-10-28 at 21.00.29.png


Still we need to include some training example for out bot to handle the next step in our conversation/dialog. Here some example under the class #account_changes

Screen Shot 2017-10-28 at 21.02.32.png


There is a last step that in this example will pretty much cover anything else and nothing really specific to what normally a customer would like to ask, but still we need to catch other possible things that can be asked or said. This will be done under the class #anything_else

Screen Shot 2017-10-28 at 20.38.08.png

Configuring Entities

An entity is a term or an object as part of the customer’s input that is aimed at clarifying the intent behind it. When usually intents are verbs (close, pay, change), entities are nouns (an account, a bill, a plan). Ideally, you should group entities that are likely to trigger a similar response throughout your dialog. For example, @customerDetailsChanges, will include all elements in the customer’s address that might need amending or changing as well various operations on the account such as close, pay, change plan etc under the category @accountMaintenance:

Screen Shot 2017-10-28 at 20.47.25.png

Screen Shot 2017-10-28 at 20.50.54.png

Building and Testing the Dialog Flow

After specifying intents and entities, it is now the time to plan our dialog’s flow. From the Dialog Tab, we are going to set a very basic and initial dialog with the #greetings intent. We create a new node called “Greeting response” and let’s add a new response condition that, if matches the existing intents, it will be prompted to the customer.

On the right side of your workspace there is a speech bubble with three dots. When you click on it, it will open a chat window from where you can test the current built dialog. As you can see from the below screenshot, “Hi” is correctly recognised as part of the class of intents called #greetings and the response “Hi, how can I help?”.

Screen Shot 2017-10-28 at 22.59.30.png


Having started off with #greetings, now we need to build the rest of the dialog. We will need to add 3 additional nodes:

  • Account Management.
  • Account Change Requests
  • Goodbye response

#Account Management’s node targets the intent #account and the entity @accountMaintenance as set earlier in this entry.

Screen Shot 2017-10-29 at 20.52.47.png


Furthermore, we will need to create a node for the specific request the customer would like to enquiry about (e.g. change of address), as follows:

Screen Shot 2017-10-29 at 20.48.18.png

We also need to add another node called “Goodbye response” to wrap up the interaction with the customer:

Screen Shot 2017-10-29 at 20.37.54.png

Now, let’s test the dialog Greeting response -> Customer Details Changes -> Goodbye response, as follows:

Screen Shot 2017-10-29 at 20.46.40.png

Finally, let’s try out the bot that consists of Greeting response -> Account Management -> Goodbye response, as follows:

Screen Shot 2017-10-29 at 23.46.15

Next Steps

There are a few directions you can go from here . First of all, the above bot is a very basic one, so you can enrich it by planning some additional potential scenarios and including more potential responses and interactions. You can look at using Jump to actions, add variation to your responses or add response conditions (e.g. using context variables). You can also use the Conversation REST API to modify your dialog programmatically, meaning that you will not need to use the Conversation tool UI. Once you are satisfied with your bot, you can also deploy your application by connecting the workspace to an interface customers will use. For example, you can test your bot on Slack in just a few simple steps. Finally, you can use the Watson SDK to develop your own web application and then your using with your service or integrating with 3rd party services.

(Some) References:

IBM Watson official website

IBM Watson official YouTube channel

Watson API and documentation

Swagger Documentation for the Watson API

Watson Conversation 

Watson IoT GitHub repo

Watson Cognitive Cooking Community