Tuesday, April 22, 2014

What is Data Science?

Like many other technical terminologies, data science has also become a buzz-word that everyone seems to be using it and at the same time no one really knows what it means exactly. I came to this definition a while ago, thought it is nice to blog about it.

The data science terminology was (kind of) invented by Cleveland W.S. (2001) as part of an action plan that focused on technical areas of statistics. Data science was defined by its action, as the single biggest stimulus of new tools and theories of data science is the analysis of data to solve problems. Cleveland stated that historically, the field of data science has concerned itself only with one corner of this large domain — computational algorithms posed in terms of the subject matter under investigation.

Provost F. and Fawcett T. (2013) define data science as a “set of fundamental principles that support and guide the principled extraction of information and knowledge from data. Possibly the most closely related concept to data science is data mining—the actual extraction of knowledge from data via technologies that incorporates these principles“. According to F. and Fawcett T (2013), main application areas of data science include targeted marketing, online advertising and recommendations for cross selling.


  • Provost, F., & Fawcett, T. (2013). Data Science and its Relationship to Big Data and Data-Driven Decision Making. Big Data, 1(1), 51-59.
  • Cleveland, W. S. (2001). Data science: an action plan for expanding the technical areas of the field of statistics. International statistical review, 69(1), 21-26.

Wednesday, April 16, 2014

Python Developer Interview Questions: Fizz-Buzz

Fizz-buzz is a very basic interview question mainly asked to see if a developer/programmer can actually code or not. Nothing too sophisticated.I was asked to code a FizzBuzz today for the second time in my life and I thought why not to blog about it, since it seems to be getting popular to ask from developers. To make it a bit challenging for myself, I coded it in Python, since I have the least skill in coding Python, although I think it is a sexy language.

Interview Question: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."

__author__ = 'amir'

for x in range(1, 100):
    if x % 15 == 0:
        print 'fizzbuzz'
    elif x % 3 == 0:
        print 'fizz'
    elif x % 5 == 0:
        print 'buzz'
        print x

Remark: Just remember that a number that is both divisible by three and five is also divisible by 15. Another note is that you need to check if the divisible by 15 condition first of all, if not they end up in divisible by 3 and 5 condition. Makes sense, right? :)

Saturday, February 8, 2014

How to debug Maven Applications in Intellij IDEA

Before I start, I would like to emphasize that this article is based on a Java console application and you need to make minor justifications in order to make it work for web apps in general.

I am assuming that you have a maven project (check out Getting Started with Maven) to make sure that project structure is valid.

To be able to debug a maven application, you need to set a Maven Debug Configuration in your Intellij IDEA project. If you do not know anything about existence of such thing, do not be scare as I will follow you through the steps.

First, in order to create a maven debug configuration, go to Run and click on Edit Configurations:

After that the Run/Debug Configuration window will pop up. Click on the "+" sign at the top-left part of the window, find Maven and click on it:

Now, you will see your Maven Configuration window. You can set a name  for it based on the goal of this debug or even name of the project. Just right below the name textbox, there are three tabs: Parameters, General and Runner. For this tutorial, we stick with the project settings options for the last two tabs and just consider the options inside the first Tab. As you can see in the following screen capture, the project directory has already been set for you. The most important task here is to set the command line of this configuration plus the profile of which you would like to debug your application.

Since we have a console application here, we will use Exec Maven Plugin which exists in Maven version 1 onwards.

exec:java -Dexec.mainClass=MainClass -Dexec.args=args

The -Dexec.mainClass will be set to the entry point of the application, here is the class with the main method, and -Dexec.args will be a set of arguments which will be passed to that main method. Here is an example:

exec:java -Dexec.mainClass=TopologyMain -Dexec.args=src/main/resources/words.txt

Now after you have set your debug breakpoint, set your Maven configuration in the dropdown of Select Run/Configuration and click on Debug (Or alternatively, go to Run and click on Debug and in the new window, select your Maven Config file):

After that, the Exec Plugin will compile your code and detach to the debugger process, like the following:

Happy Debugging your Maven Code!

Thursday, December 26, 2013

Write to a prettified JSON file in Python (with least number of lines of code)

import json

jsonData = ['foo', {'bar': ('baz', None, 1.0, 2)}]
with open('sample.json', 'w') as outfile:
    json.dump(jsonData, outfile, sort_keys= True, indent=4)

Monday, December 23, 2013

Remove duplicates in an array in Javascript

If you follow this approach, you need to create another array and if you have performance limitations you need to consider that.

This algorithm will be o(n)complexity in which n is the length.

With jQuery:

 var newArray = []; 
 var array=["amir", "amir", "rahnama", 1, 1]; 
 var newArray = [];

 $.each(array, function(i, element) { 
   if ($.inArray(element, newArray) === -1) {

 console.log(newArray); // ["amir", "rahnama", 1];

Vanila Javascript:

 var newArray = []; 
 var array=["amir", "amir", "rahnama", 1, 1]; 
 var newArray = [];

 array.forEach(function(i, element) { 
   if (newArray.indexOf(element) === -1) { 
 console.log(newArray); // ["amir", "rahnama", 1];

Sunday, December 22, 2013

How to resolve XCode's “valid signing identity not found” error

Generally, this error is caused because of a mismatch between a provisioning profile and a private key. It can also be that you even do not own a private key that makes your identity identified to the provisioning profile which are you working with.

First Resolution
Double-check that the profile that you have got from Apple Developer Program is the correct one that you are supposed to have. Sometimes organizations have multiple profiles for each team and although you have a correct private key, you own the wrong provisioning profile.

Second Resolution
You do not own the private key of the provisioning profile and/or identity that you are using. You need to own a private key file with .p12 extension in order for your identity to be validated. Whoever have created your identity (in case you work in a  team of developers, it could be someone else), has it on his/her machine when he has created the profile and/or identity. you need to get this key from that person or reissue a new private key (which takes some time) in order to resolve the issue.

If this sounds too confusing and does not make any sense for you, follow my step-to-step guide to How to sign your MacOSX application code with codesign?

Saturday, December 21, 2013

How to sign your MacOSX application code with codesign?

A Brief Preface: I recently realized that the documentation for signing your Mac OSX applications with codesign is distributed across many documents which is extremely hard to find (You can find those documents in the "more to read" section of this post). Also, in the documentation it has been assumed that you will sign your code with XCode which is not always the case. As you may know, XCode is mainly used for development with Objective C for MacOSX and iPhone but a lot of Mac OSX applications are written in C/C++ and Java which XCode does not support any feature for those project types and makes the signing process extremely hard.

Now, let us start:

1. Go to Apple's Developer Program's Member Center. Go to member center. Write your credentials and enter.

NOTE: If you have not registered in Apple's Developer Program, you need to do so before you can sign your code.

2. Under Developer Program Resources, click on Certificates, Identifiers and Profiles. Under Mac Apps Click on Certificates. Then go to your certificate and then Click on Download. Now you have downloaded the Certificate.

3. Find the certificate file that you downloaded, and run it.
Keychain Access program will be opened by default and will put your Certificate under login keychains and certificates category:

4. Download your private key from the Apple's website: In the downloaded folder you will find a key file with .p12 extension which is Mac’s public key (PKCS12) format. Again, open the file and automatically it will be attached to the certificate you just downloaded.

Check whether it is already there as you expect it.

5. Next Step is to get Developer’s ID. Right click on the certificate of Mac developer profile which you want the code to be signed with and click on “Get info”. On the new windows, scroll down and get the SHA1 fingerprint of the certificate:

Remove the white-spaces and put it under $DEVELOPER_ID in your sign command or if you have one, in your build script. Also, you need to add the requirement for signing. Read about it on Mac Developer Documentation: Apple's Codesign Requirement Specification

Remark: One example of requirements can be of following (This example uses Mozilla's XULWrapper platform):

CODESIGN_REQUIREMENTS="=designated => anchor apple generic  and identifier \"org.webapp.xulwrapper\" and ((cert leaf[field.1.2.840.113635.] exists) or ( certificate 1[field.1.2.840.113635.] exists and certificate leaf[field.1.2.840.113635.] exists  and certificate leaf[subject.OU] = \"FOO123BAR1\" ))"

/usr/bin/codesign -s "$DEVELOPER_ID" -v \
   --requirements "$CODESIGN_REQUIREMENTS" \

6. You can sign the code now. Run the above command and you should be good to go.

Further References: