Are you looking for my non-technical blog?

This is now my technical-only blog, my non-technical blog is here.

23 June 2014

Python's Getters and Setters

You can read a better formatted version of this post here.

Just learn a new python feature called @property. Let's say we create a class called Circle as follows.

class Square:
    side = 2
    area = side * side
s = Square()

>>> s.side
>>> s.area

>>> s.side = 3
>>> s.side
>>> s.area

Not cool! How to solve that?

class Square:
    side = 2
    def area(self)
        return self.side * self.side
s = Square()

See now.

>>> s.side = 3
>>> s.side
>>> s.area

09 February 2014

Introduction to Data Science

The AskDeveloper group organized this hangout about Data Mining, and Machine Learning in particular. The video is in Arabic, yet the slides are in English.

،شوية دردشة عن تنقيب وتحليل البيانات والتعلم الآلي، الفيديو بالعربي

إضغط على الصورة لمشاهدة تسجيل الحلقة

10 January 2014

Github Traffic Analysis

Github now shows traffic analysis to those who visit the repositories there.

The new traffic analysis page shows the top referring websites and the top visited files in the repo as well as a time-series chart for the visits and bounce rate.

17 December 2013

We Preach by Spamming

Once upon a time, I stumbled upon an online Quran application, back then I was studying human-computer interaction as a part of my MSc. degree, so I commented on twitter that most of the online Quran readers need to reconsider their design from a usability point of view.

Since then, and I receive dozens of spam tweets each day. They come from different people, yet they all contain the exact same message.

My only interpretation for this is that has an application that those pople trust and it uses their accounts to send those spammy messages to me.

I sent multiple spam reports to twitter, yet they don't even respond. Isn't it strange that some applications think that it is ok to abuse the trust of their users and spam someone in order to grab his attention to give them feedback about their application!? Isn't it disappointing that twitter don't give a shit to my daily spam reports!?

30 September 2013

A Quick Intro. to NumPy

For me, NumPy is a Python list on steroids. You can use it to create multidimensional arrays and matrices.

The convention is to import it as follows:

import numpy as np

To create an array of numbers between 0 and 9, you could use the following command:

x = range(9)

To convert that list into a NumPy array, you can write:

x = np.array(range(9))

And to make you life easier, there is a shorthand for the above command:

x = np.arange(9)

So far, we have been creating one dimensional array. However, there are ways to reshape the arrays. The reshape() method when applied on an array, it returns a reshaped version of it without changing the original object. To reshape the original object itself, then use resize() instead.

y = x.reshape(2,5)

The above command create a 2-dimensional array of 2 rows and 5 columns. You can create a much dimensional arrays as you want. See the command below for a 3*4*5 array.

y = np.arange(3*4*5).reshape(3,4,5)

The mathematical operations '+', '-', '/' and '*' are applied elementwise.

x = np.arange(10)

# To multiply each element of x by 10
y = x + 10

# To multiply each element of x by itself
y = x + x

To do a Matrix Multiplication though:

# Create a 3 * 5 Matrix
A = np.arange(15).reshape(3,5)

# Create a 5 * 2 Matrix
B = np.arange(10).reshape(5,2)

# Dot product gives you a 3 * 2 Matrix
y = y =, B)

Just like lists, you can get parts of arrays

For original lists:

A = range(10)
A[2:5] # [2, 3, 4]

For NumPy Arrays

B =  arange(10)
B[2:5] # array([2, 3, 4])

However, you can set some elements of the array as follows

B[2:5] = 1337

But, you cannot do the same to lists.

A[2:5] = 1337 # TypeError: can only assign an iterable

For statisticians, there are also the following functions

x = np.arange(5) + 1
x.mean() # 3.0
x.max() # 5
x.min() # 1
x.std() # 1.414

You can also access elements of the array using start, stop and a step:

x = np.arange(10)
x[2:7:2] # array([2, 4, 6])

Or access specific elements, let's say elements 1, 5 and 6

x[[1,5,6]] # array([1, 5, 6])

Similar to reshape() and resize(), ravel() converts a multidimensional array into a one-dimensional array, while transpose() turns rows into columns and vice versa.

If you program in R, you will not miss their way of accessing elements of array that meet a certain condition.

x = np.arange(10)
x[x>4] # array([5, 6, 7, 8, 9])
x[x%2 == 1] # array([1, 3, 5, 7, 9])

If you are having an array of elements that are either True or False.

x = np.array([True, False, True, True])

x.all() # Only True if all elements are True
x.any() # Only True if any elements are True

Finally, there is a repeat() that repeats each element of the array n times

x = np.array([1, 2])
x.repeat(3) # array([1, 1, 1, 2, 2, 2])

That's all folks for today.
Check the following tutorial for more information.

26 September 2013

Middle East Relationships Infographics

The Radio Free Europe - Radio Libre (RFE/RL) published an infographic summarizing the political relationships between the Middle Eastern countries. The graph comes after a similar one that was made by the Egyptian blogger, The Big Pharaoh (@TheBigPharaoh), and was published in the Washington Post.

I'd like to discuss the two infographics from a design point of view here. So, let me start with the one made by RFE/RL.

The main point of the graph is to show the relationships between those countries, i.e. friends and foes. However, as you can see, it is not possible to tell this from the first look. All dots are the same, black dots of the same size. Well, may be they are inviting us to interact with those dots by clicking on them.

So, there are messages hidden behind the dots, but this is just text. Hmmm, couldn't those same messages be written in an article then, or in a table? What is the use of the graph then?

Why is it that the United Stated is there on one axis but not the other. Same for Iraq. Also relationships are supposed to be symmetrical, yet the chart isn't. You can track the lines between Iran and Israel, but there are no lines between Israel and Iran. I know, this is a sort of redundancy, however, it is either the graph is to be redesigned, otherwise, this way is confusing.

Here comes The Big Pharaoh's graph then.

This times relations are supposed to be clearer from the first look. Different line colours reflect different relationships. In this graph countries are represented by points while the relationships between them are represented by lines. While on the RFE/RF's graph, it was the other way round. Entities are placed in the form of a matrix where dots represents the relationships between them and the countries are represented by the horizontal and vertical lines.

In Jacques Bertin's paper, The Matrix Theory of Graphics, he explained that the network representation (e.g. The Big Pharaoh's graph) is more useful in representing the topographical structure of the elements and how each pair of them are connected on a micro level. While the matrix representation on the other hand is more flexible in reordering the element in order to show how the relationships between elements on a macro level. You can cluster your elements first to show groups of allies and foes. Changing the dots colours or sizes gives you a third dimension to move in. As you can see in the network graph above, lines are cluttered and a bit hard to follow.

Can you sketch a better representation of those relationships then?

28 May 2013

Git Forking

After our previous guide to github, now, let's say you want to contribute to a project already existing on github, how to do that?

First thing first, you go to the projects repository and fork it using the button shown in the figure below.

After that, you will be redirected to the page of the forked repository. You will also be given a URL for the forked repository as shown in the figure below.

Now, you create a new director, go there and type the following commands:

$ git init

$ git remote add origin [the URL show above]

$ git pull -u origin master

And, that's it!

19 May 2013

Nike+ first time user's experience

I really want to know if those people behind Nike+ running app on iPhone have ever heard of something called HCI/UX or not!?

Nike+ running app

Today I was using their app for the first time, and it asked me to login, giving me two options for that: A normal login with email and password or to login via Facebook. Despite the fact that I hate apps that contaminate my Facebook timeline with their updates once I sign in with Facebook, I chose the Facebook option as I struggle with remembering passwords for the endless apps one use everyday.

Signing with Facebook is meant to save us the effort of entering passwords for each application, right? Well, seems that Nike+ app doesn't agree with that. After signing with Facebook they asked me again to enter my birthdate, gender, and all those information they can simply grab from my Facebook account, and guess what, they asked me to create a new password too. What the eff!!? They didn't stop here, they even gave me a list of 5 criterion I have to adhere to when choosing my password. Choosing a weak password is my own problem, not theirs. They shouldn't tell me how my password should look like. Additionally, come on, I can choose a password that doesn't meet their password policy yet still stronger than the ones meeting it. So, again, I am the only one who have to decide how my password should look like here.

13 April 2013

True or False: Egypt's First Locally Produced Tablet

You might have read the news that the state-owned electronics firm Katron, has produced Egypt's first locally produced smart tablet, under the trademark 'Inar.' However, the debate now is whether the correct term is 'produced' or 'assembled'. There are two camps arguing now. On the one hand, there are those who find it a huge achievement and attacking local media for not shedding the light on such great news. While on the other hand, there are those who argue that it is just assembled from imported components, and it can hardly be called "an achievement". That's why I decided here to give my humble opinion about the issue.

Inar, assembled in Egypt

First of all, let's agree that we are not living in the Industrial Age anymore. We now live in the age of outsourcing and digital disruption. What I mean by this, is that the argument of technical components not made here is not really a valid argument. Apple, Samsung, Dell, Cisco, etc. do not make every single component of their products. Let's not forget that Apple use components made by its competitor Samsung. They may decide to produce a chipset or two, they may rely on home-made Operating System, but they also may decide to just rely software and hardware components made by others. In other words, we are in fact asking the wrong question here. What really matters is the following:

If the Egyptian company succeeded in producing a competitive product that it can use to go to the market and compete against other vendors, then I call this an achievement, even if none of the products' components is locally made. Whereas, on the other hand, if it is 100% locally-made, yet its producers cannot convince anyone to buy it, then I can hardly call this an achievement. The asian  electronics firms are open market to everyone. Any company can go to that market and get off-the shelf components, whether they are processors, LCD screens or any other components. Android, Windows and Linux are also available for any manufacturer to use them if they want to. In such market, where you and your competitors have access to almost the same resources, your competitive advantages can come from your low price, better design, more advanced features, or even brand name. That's why, the question now, whether 'Inar' is an appealing products to tablet customers, from price or features or whatsoever point of view, or it is just assembled for the sake of assembling a local tablet in Egypt? If it is the formet, then let's hurray the Egyptian achievement, if now, let's question the government's unwise spending, since Katron is a state-owned firm.

P.S. The first known tablet user in history was in Egypt, by the way. Hint, hint, Moses! ^_^

29 March 2013

Adjacent vs Incremental Innovation in Digital Age

I've just finished reading a book called "Digital Disruption: Unleashing the Next Wave of Innovation", by James McQuivey. I enjoyed reading it, and that's why I'd like to share a quick review for the book here.

"Instead of asking How can we make a new product that we can successfully sell? the disruptor asks: How can we give people something they really want". Replace "Make" with "Give", "Product" with "People" and "Sell" with "Want".

This sentence summarises the main idea of the book. In digital age, the cost of producing new products is much lower than it was one decade ago. And the author is not only talking about digital products, but analog ones too. Hence, it is all about innovation now. People want experience rather than products. It doesn't matter if you make it, or if you can partner with others and use free tools to give that experience to your users. Your focus should be on what your users want rather than on what you can produce and sell. The two concepts seem to be similar, but if you think about it, you will find them leading to different set of priorities when you are trying to innovate. The author added later on, "R& D teams have a tendency to confuse product features with customer benefits. They assume that more features equals more benefits. This is not true".

One other quote that I liked is, "When companies adopt technology, they do old things in new ways. When companies internalize technology, the find entirely new - disruptive - things to do".

He also set some differences between two concepts of innovation. Incremental versus adjacent innovation. Incremental innovations focuses on the the current product you have, the current customers you target, and the current process you use to make your products. Whereas, Adjacent innovation leads you to explore new markets, and new experiences to offer to new users. To do so, you need to think of competition differently, it is not those who sell the same products as you do, but anyone offering good experience to their users. Take Nike Runner app for example, they did not limit themselves to other shoe-makers, they rather explored new areas, they witnessed the likes of Apple and Facebook, they learnt from them how people want to share their activities, and how gamification is invading social services. Nike is not an app maker, it is not part of their production process, but this didn't stop them from moving to one new adjacency to explore new customers and new experiences to offer to those customers. They may choose to partner with Apple or compete against it in order to offer such experience to their users. It doesn't matter whether they choose the former or the latter. Because in the digital disruptive age, what really matter is offering your customer's value not products.