Wednesday, December 31, 2014

vagrant/machine.rb:153:in `action': wrong number of arguments (2 for 1) (ArgumentError)


Change the line from :

                  def action(name, **opts)

to:
                  def action(name, opts)

in the file located at /opt/vagrant/embedded/gems/gems/vagrant-1.7.1/lib/vagrant/machine.rb line 153.
This will be fixed in later versions of Vagrant after 1.7.1

Tuesday, December 30, 2014

Vagrant: Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available.



This is an issue of older version of VirtualBox. Download the latest virtual box from :
Virtual box Download site

You may need to do the following also if not resolved after upgrading to latest version:
$ vagrant plugin install vagrant-vbguest
More tips to solve the problems:
https://github.com/mitchellh/vagrant/issues/3341
https://www.virtualbox.org/manual/ch04.html#idp54932560

Tuesday, October 14, 2014

Caused by: org.apache.axis2.AxisFault: Address information does not exist in the Endpoint Reference (EPR).The system cannot infer the transport mechanism.



You may get the error as in my case :

<property name="wsdlFilename" value="MyServiceWS20Service.wsdl" />


The axis can not find wsdl somewhere as resource or misspelling.

Friday, August 1, 2014

Get http:///var/run/docker.sock/v1.12/info: dial unix /var/run/docker.sock: no such file or directory


If you are like me running on MAC OSX and you get this error because you have not started the docker and exported the DOCKER_HOST.
$ docker info
2014/08/01 17:34:31 Get http:///var/run/docker.sock/v1.12/info: dial unix /var/run/docker.sock: no such file or directory


Do as following to fix it:
$boot2docker

You will receive something like the following :
2014/08/01 17:34:21 Started.
2014/08/01 17:34:21 To connect the Docker client to the Docker daemon, please set:

2014/08/01 17:34:21     export DOCKER_HOST=tcp://134.155.10.100:2375

Export DOCKER_HOST in your command line:
$export DOCKER_HOST=tcp://134.155.10.100:2375

Check if you d not get the error again or DOCKER is working properly:


$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.15.3-tinycore64
Debug mode (server): true
Debug mode (client): false
Fds: 10
Goroutines: 10
EventsListeners: 0
Init Path: /usr/local/bin/docker


More good tips about docker:
https://gist.github.com/wsargent/7049221


Friday, July 11, 2014

Naive Bayes classifier using Mahout



Bayes was a Presbyterian priest who published "Tractatus Logicus" in 1795. Not far after his dead did anyone appreciate the value of his great work a century later in the scientific community. This is a study of Boolean Calculus (conditional probability).

This classifier is used in supervised learning data-mining.

In order to use Naive Bayes Classifier to classify the dataset and train it you need to use Hadoop to convert the data-set to Hadoop sequence files. Hadoop take the files as input files and generate one chunk-file.The Hadoop command below illustrate the use of Mahout to generate these files:

$./mahout seqdirectory -i ${WORK_DIR}/input_files -o ${WORK_DIR}/new_sequencefiles

This command take as input every files in the directory /input_files and transform them into a sequence  file.
Check the help command of mahout to find out more about the command:
$./mahout seqdirectory --help


The following Hadoop command examine the outcome of the sequence file:

$hadoop fs -text  ${WORK_DIR}/new_sequencefiles | more

A number of machine-learning and data-mining algorithms are based on the calculation of vectors that must be provided.

The naive Bayes algorithm does not work with words and raw-data, but works with weighted vectors associated with the documents. To transform the raw data or text to weighted vectors, the mahout-command provide an convenience way as follows:
./mahout seq2sparse -i ${WORK_DIR}/new_sequencefiles -o ${WORK_DIR}/new_vectorfiles
-lnorm -nv -wt tfidf

Refer to the helper manual for further understanding of -lnorm -nv -wt tfidf like L_2 norm, namedVector.

We now need to train the algorithm, The best approach is to split the vectors into 20-80 which the 20% of the vectors are preserved to test and the 80% is used to train the algorithm.
mahout provide a command line approach to split the weighted vectors:

$./mahout split
-i ${WORK_DIR}/new_vectorfiles/tfidf-vectors
--trainingOutput ${WORK_DIR}/new-train-vectors
--testOutput ${WORK_DIR}/new-test-vectors
--randomSelectionPct 40 --overwrite --sequenceFiles -xm sequential

After this command runned we will have two directories for training and test vectors.
We train first the Naive Bayes algorithm with the vectors from ${WORK_DIR}/new-train-vectors as follows:




Sqoop is an Apache software that is used to acquire data from RDBMS and import data into HDFS to prepare it to Mahout Analysis.


./mahout trainnb
-i ${WORK_DIR}/new-train-vectors -el
-o ${WORK_DIR}/model
-li ${WORK_DIR}/labelindex
-ow

This will generate a MODEL in form of binary file. This represents the weight matrix, the feature and label sums.

We test the algorithm against 20% of the initial input vectors:
./mahout testnb
-i ${WORK_DIR}/new-test-vectors
-m ${WORK_DIR}/model
-l ${WORK_DIR}/labelindex\
-ow -o ${WORK_DIR}/new-testing

After this command you will see a result of accuracy of the training. A result of accuracy at least 80% should be enough.

And use the following command to dump to a text file:
mahout vectordump -i ${WORK_DIR}/new-vectors/tfidf-vectors/
part-r-00000 –o
${WORK_DIR}/new-vectors/tfidf-vectors/part-r-00000dump

Checkout more on :
https://mahout.apache.org/users/classification/twenty-newsgroups.html










Thursday, July 10, 2014

Bitbucket: how to avoid writing password everytime in git to Bitbucket?



This can not be avoided. The only way is to cache it to get rid of typing everytime:

$git config --global credential.helper "cache --timeout=3600"

Wednesday, July 9, 2014

Information Retrieval Tasks

Here is a list of typical Information Retrieval Tasks:



Information filtering 

Remove redundant or undesired information from an information stream in semi or fully automatic methods before presenting them to human users. 

Document summarization
Create a shortened version of a text in order to reduce the information overload.

Document clustering and categorization 
Group documents together based on their proximity (as defined by a suitable spatial model) in an unsupervised fashion.
Clustering is an unsupervised technique that does not assume a priori knowledge: data are grouped into categories on the basis of some measure of inherent similarity between instances, in such a way that objects in one cluster are very similar (compactness property) and objects in different clusters are different (separateness property).
Classification is a supervised technique that assigns a class to each data item by performing an initial training phase over a set of human annotated data and then a subsequent phase which applies the classification to the remaining elements. Learnings are done either unsupervised or supervised. Techniques such as naive Bayes, regression, decision trees, and support vector machines are used in classification problems. Unsupervised learning models require priori knowledge about the classifications. In contrast Unsupervised learning models does not require pre-knowledge about the classifications and intrinsic  similarities in data is used as measurement in clustering of data. K-means is an example of clustering analysis. Objects are tagged to the clustered data once the classes are determined. This is known as labeling. In other words, the labeling is performed by automatically, no human is involved.

Question answering (QA) 
Select relevant document portions to answer user’s queries formulated in natural language.



Recommending systems
A form of information filtering, by which interesting information items (e.g., songs, movies, or books) are presented to users based on their profile or their neighbors’ taste, neighborhood being defined by such aspects as geographical proximity, social acquaintance, or common interests.

Sunday, June 15, 2014

java.io.FileNotFoundException: content://media/external/video/media/


The content://media/external/video/media/ is URI type and you need to query MediaStore to get full path name to the file.
Something like below:

public static String getFilePathFromContentUri(Uri selectedVideoUri,
        ContentResolver contentResolver) {
    String filePath;
    String[] filePathColumn = {MediaColumns.DATA};

    Cursor cursor = contentResolver.query(selectedVideoUri, filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    try {
    filePath = cursor.getString(columnIndex);
    } catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
                //Need this in case the file not exist
    return null;
}
    cursor.close();
    return filePath;
}

Saturday, June 7, 2014

***ERROR*** No Facet of type [interface org.jboss.forge.addon.javaee.jpa.JPAFacet] is installed.



If you are running Forge 2 and get the message below
***ERROR*** No Facet of type [interface org.jboss.forge.addon.javaee.jpa.JPAFacet] is installed.

This can be inconsistency in the pom.xml. Try to remove or move pom.xml to another safe place
from the current directory and try again.

Wednesday, June 4, 2014

Convert from mp4 to mpeg in Ubuntu





Use ffmpeg utility, it's awesome.

1. Install:
sudo apt-get install ffmpeg

2. Convert:
ffmpeg -i input.mp4 output.mpeg

PS: For available formats supported by ffmpeg:
ffmpeg -formats

Monday, June 2, 2014

1099 is already in use on MAC, how to kill


I had an issue with the following error:
localhost:1099 is already in use

To kill the process blocing 1099 run the following:
$lsof -i :1099
COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    19327          user  451u  IPv6 0x305bcf3e90cfdfc7      0t0  TCP localhost:rmiregistry (LISTEN)
$ kill 19327
$ lsof -i :1099



Wednesday, May 28, 2014

Proper use of stand and rand() in c++

I had many issues with stand and rand when trying to generate truly random series of numbers.
I used in for or while loop and this should be written correctly.
Here is the correct way to write randomly generated functions in C++:

            srand(time(NULL));
            while ( j < N ) {
                std::array<int,Tsp::N> genes = {};
                rand();
                index = rand() % N;
                if ( std::find(std::begin(genes), std::end(genes), index) == std::end(genes) ) {
                    genes[j]=index;
                    j++;
                }
            }




Sunday, May 25, 2014

Genetic Programming vs Genetic Algorithms


Genetic Programming vs Genetic Algorithms 
The genetic algorithm has several disadvantages, for example the length of the strings
are static and limited, it is often hard to describe what the characters of the string means
and the meaning of the characters is limited to whatever they are specified to be. These
problems could perhaps be overcome but a better solution brings back the original
question: How can computers learn to solve problems without being explicitly
programmed? Genetic programming suggests the following solution: simply apply the

genetic operations on computer programs to evolve better and better programs.


There are a lot of frameworks that you can start with Genetic Programming immediately however you do not need them to start using Artificiell Intelligence. You simply need to know about a few core knowledge to solve problems like Traveling Salesman Problem known as TSP in computer world.


Selection in Genetic Algorithm
There are different methods to select chromosomes from a population to be parents for crossover to next generation.

Roulette wheel selection


Boltzman selection
Tournament selection
Rank selection
Steady state selection


Crossover and Mutation Probability
This is two parameters of Genetic Algorithms.
Crossover takes place once the chromosomes are selected based on one of the methods above.
This will produce offsprings. A crossover of 100% or 1.0 means that all of the chromosomes will be used for reproduction, i.e. there is no servivors. Empirical studies shows that a Crossover probability of between 0.65 and 0.85 will achieve better results.If it is 0% nothing is changed and the offspring is a exact copy of one of the parent.
Some researchers recommend decreasing the cross-over probability and increasing the mutation probability in depending on the number of performed generations. Others say that it is good if the genetic algorithm has a dynamic cross-over probability that changes in dependence to spread value inside the selection mechanism.

Resources:
http://en.wikipedia.org/wiki/Genetic_algorithm


Behavior Driven Development, BDD for Java


BDD - Behavior Driver Development is an effort to meet the problems faced in Software development described by Eric Evans in his book Domain Driven Design [Eva03]



A project faces serious problems when its language is fractured. Domain experts use their jargon while technical team members have their own language tuned for discussing the domain in terms of design... Across this linguistic divide, the domain experts vaguely describe what they want. Developers, struggling to under- stand a domain new to them, vaguely understand.” 

To avoid any misunderstanding between the domain experts and developer there is a need of a language that can be understood by everyone involved in the project to reduce any misunderstanding.
Gherkin is a such language.

Stateless
Each scenario must be able to be executed independencely of any other scenarios. This is bad practice genereally to have any dependencies to other scenarios. Asume always that the system is in a blank state, hence stateless. In "Given" you can set up all the state you need for the particular state.

The scenario should not contain technical details how to retrive values for example, but what
the system in a given state expected to do things.





Available Behavior Driven Design Framework for Java:

Cucumber-jvm
Spock
JBehave


Link Resources :
Java based bdd with Cucumber
Business Readable DSL by Martin Fowler


GLUT's display func called only once

Suppose you have the following code in your main:

void Update(void){_tsp.update();}
void Display(void){_tsp.DrawCities();}
// your other code here
int main(int argc, char * argv[])
{
...
..
// your other code here
...

glutDisplayFunc(Display);  // callback for draw function
glutIdleFunc(Update);  //callbak for update function

You observe that the Display called only once and Update on all loops.
If you want both Display and Update be called, add

glutPostRedisplay(); 

In yor Update function at the end. This will trigger callback for the display-function.

Friday, May 23, 2014

Absent Code attribute in method that is not native or abstract in class file javax/persistence/GenerationType

When you use JUnit/Arquilian and get the following error when running in maven:
Tests in error:
 .....: Absent Code attribute in method that is not native or abstract in class file javax/persistence/GenerationType

You may have this issue when you have higher Java version and you may not have this issue if you run other Java versions of SDK installed. To  prevent those dependencies add the following in maven:

<dependency>
            <groupId>org.glassfish.main.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>4.0</version>
            <scope>test</scope>
        </dependency>


Find latest version of org.glassfish.main.extras on
http://mvnrepository.com/artifact/org.glassfish.main.extras/glassfish-embedded-all



Sunday, May 11, 2014

Methods to find suitable solution (ie. not necessarily the best solution),

Finding best Solution in Computer Science

There are methods to find solutions that is not necessarily best solution, but can find a best possible solution in a Serach Space (i.e. the space of all feasible solutions).
There are problems that can not be solved by traditional way and such problems are called NP-problems.
Problems that can not be solved in polnomyal time is such problems that need another way to solve problems. NP stands for Non-determinsitic polynomial and we can only "guess" a solution and then check the solution.Nobody today knows if there is fast exact algorithm. Proving or disproving this is a task for future reseracher. To find such algorithm today they use the following methods and Genetic Algorothm is one of them.

Hill climbing
Tabu search
Simulated annealing
Genetic algorithm


Look at Wikipedia to find out more about the finding solutions.

Saturday, May 10, 2014

no matching function for call to ‘glutinit’ error in Xcode


When you create a default project in Cocoa template of Xcode the main function is generated accordion to the following:
int main(int argc, const char * argv[])

You can solve this if you review your main-function and remove "const" from the following main function:
int main(int argc, char * argv[])
and build again.




Why you should use Iced Coffee Script (IcedCoffeeScript) to CoffeeScript


Iced Coffee Script aimed to make programming asynchronous easier and is a superset of CoffeeScript.
The main advantages are using Wait, Defer to make for example parallel searched to Twitter as you can find an example of it at the link: Iced Coffee Script. You can use a fewer lines to achieve your goal with asynchronous calls than in CoffeeScript. Take a look at the code examples provided in the link above.

In Atom Editor from Git there is a support for Iced Coffee if you wan to experiment wit it further.


Thursday, May 8, 2014

java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor



java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

You get this issue if you have profiles-elements in your POM-xml and no one if the profiles are activated.
You can either activate one of the Profile Id using command-line:
$  mvn clean install -Pjboss-managed

or use your favorite IDE to choose one of the profiles to run.


Friday, April 25, 2014

iconv.dll the specified module could not be found

iconv.dll the specified module could not be found
To solve this issue :
       gpg error loading iconv.dll' the specified module could not be found

download iconv.dll from the link below and follow the instructions:
http://www.gnupg.org/download/iconv.html


Thursday, April 24, 2014

Remote Desktop Access problem due to license

If you have problem to access a remote desktop and get error messages that you have to contact system administrator to get license etc. The following steps can solve your access problem:
  • Run the following command in start command box
          regedit
  • Inside Regedit, navigate to the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSLicensing
  • Right click on the key name “MSLicensing” and select DELETE.


Example of CSS-based waiting indicator, an example

Example of CSS-based waiting indicator with Angular JS

In your HTML-file:
<div class="overlay" ng-class="{'ng-hide' : !isVisible }">
                <img ng-show="image"  ng-class="{'ng-hide' : !isVisible , 'myloading' : isVisible }" src="/images/loadingindicator.gif" alt="Spinner">
            </div>

CSS:
.myloading {
    opacity:0.5;
    background-color:#ccc;
    position:fixed;
    top:0px;
    left:0px;
    z-index:1000;
    border: 0px solid;
    margin: auto;
    right: 0;
    bottom: 0;
}

.overlay{
    opacity:0.8;
    background-color:#ccc;
    position:fixed;
    width:100%;
    height:100%;
    top:0px;
    left:0px;
    z-index:1000;
}

Use Broadcast/on concept in Angular to share data between Controllers, something like below:

$scope.$on('globalalertWaitMessages', function(event) {
           $scope.isVisible = true;
      });