15 April 2010

The Ultimate Multiple Desktops App for Win7

I've recently upgraded my OS to Win7, and I've to say it seems pretty nice and fast. However, it does not support multiple desktop (Very useful for a student-employee), so after searching the web for such an app I found WindowsPager, a very useful simple portable-app works smoothly on Win7. It has a config file (windowspager.ini) to determine how desktops you want, hot-keys, and multiple desktops modes.

2 desktops: one for study, the other for work


05 June 2009

جراري

جراري مليئة بدموع رجال
أحببنكِ قبلي
لكنني لا أبكي
مشغولٌ بملء سلال الضحك
لسيّدٍ سيضحك بعدي

أحلام مستغانمي - مُعدّل

18 April 2009

Why always use virtaul D'tor in C++

I've been asked more than one time this question, and I faced some problems when programming in C++ that using virtual D'tor was the solution of them. So here is why...

1. In order to create virtual table.

Explanation:
Sometimes we need to try dynamic_cast<> or use the typeid() in order to know the object type, both of these operator succeed ONLY if the object has virtual table, therefore, if the class type of the object used has no virtual function in his definition, using these operators will fail (dynamic_cast<> will always return null and typeid() will always return the base class).

Solution:
add virtual D'tor to create the virtual table and then both operators will succeed (class will be polymorphic type)

Example:
//this will fail
class A {}
class B : A {}
A a;
B b;
if( typeid(b) == typeid(B) )
   //typeid(b) will return A, while typeid(B) will return B.
{ cout << "success"; }
else
{ cout << "fail"; }

//This will success
class A { virtual ~A(){} }
class B : A {}
A a;
B b;
if( typeid(b) == typeid(B) )
   // both typeid(b) and typeid(B) will return B.
{ cout << "success"; }
else
{ cout << "fail"; }

2. Call the suitable D'tor.

Explanation:
In some cases, dynamic dispatching of the D'tor is needed (call the dynamic type d'tor of the object)

Solution:
Add virtual D'tor for dynamic dispatching

Example:
//A::~A() will be printed
class A{ ~A(){ cout << "A::~A()"; }
class B{ ~B(){ cout << "B::~B()"; }
A *a = new B();
//end

//B::~B() will be printed
class A{ virtual ~A(){ cout << "A::~A()"; }
class B{ ~B(){ cout << "B::~B()"; }
A *a = new B();
//end

3. call operator delete with the suitable size.

Explanation:
For most programming tasks, the default implementation of operators new and delete is sufficient. In fact, many C++ programmers get along without even knowing that they can override these operators. So, operator delete (which differs from operator delete!) can be overridden.
Note: delete operator is a keyword in C++ (the one turn into blue color when typed), and operator delete is the operator called automatically when we use delete operator. What happens is: when delete operator is called, first the D'tor is the object is called and then operator delete is called.

This operator has two possible overrides, the first, which is the common one, is:
    static void operator delete (void *p);
and the other is:
    static void operator delete (void *p, size_t size);
The second option is needed when operators new and delete are overridden in base and derived classes, so the implementation of operator delete can know what's the object type called it (using sizeof(size) ).
The problem is: if the class D'tor is not virtual, the size passed to the operator delete is base class size and not the dynamic class size (which can be the derived one). And then, wrong flow of operator delete implementation can happen.

Solution:
Use virtual D'tor, that assures the size passed to operator delete is the size of the dynamic type of the caller.

Example:
class base{ public: void operator delete(void *, size_t); };
class derived : base{};
base *ptr = new derived();
    //This will be compiled to the following:
    // base::operator new(ptr, sizeof(derived));
    // ptr->base();
/*
do whatever you want with ptr...
...
...
*/
delete ptr;
    //This will be compiled to the following:
    // ptr->~base();
    // base::operator delete(ptr, sizeof(base));

/*
Note that the size passed to new operator is the sizeof(derived) class and the size passed to delete operator is the sizeof(base) class
*/

For these three reason, I always use Virtual D'tor although it don't solve any of the solution above. Who knows, one day you may need it.

 

23 August 2008

لما ألحزنُ في عينيك؟

سألتني: "لما ألحزنُ في عينيك؟", لم أجبها, ولكن قلبي كان يصرُخ: "حُزني أنت!".
ما أعظم أن تشتاقَ لشخصٍ لا يشتاقُكَ, علمتهُ ألحنانَ وينكره.. علمتهُ الأمان ويتركه.. أعطيتهُ ما في باطن جسدك, ليأكله.
أنا لا اُنكِرُ أني اِعتدتُكِ, وعاشرتُكِ, فلست جباناً.. ولكني أنسان. أنسانٌ يستصرخ الألم والكيان.. والأغرب ما في ذلك, أني لا أزالُ أخافكِ وعليك.
كنت دائماً ذلك الأنسانُ الذي ربطوا أيديه بحبلٍ يمتدّ الى عربةٍ يجرّها حصانٌ تمتطيه... لم أبه أبداً من الألم, من العذاب, لم أبه أبدا من اللون الأحمر... فكنت على يقين, أنك الى القصر ستصلين. أن بقيتُ على قيد الحياة فليكُن, وأن متّ فقد وصلتي الى حيثُ تريدين

21 August 2008

Michael Phelps, Usain Bolt and Yelena Isinbayeva

As you probably know, Beijing 2008 Olympic Games is full of history and world records; But there are 3 athletics made this Olympic Games the most special one I've seen till now, and what they did in the Olympic games, I'll never forget.

Michael Phelps: Best swimmer in history (although he had learning disabilities when he was a kid), earned 8 (!!!) Gold medals in Beijing Olympic Games, more than anyone else. I cannot forget his fabulous finish in 100M butterfly preceeding his competitor Chavich in 0.01 second, or when he made fun of his competitors in 200M mixed leaving them far far away from him.



Usain Bolt: Fastet runner in the world! breaking his own world record in 100M and Michael Johnson's 12 years old world record. Reaches 46KM per Hour!. Everyone had been in shock when he celebrated his win 20 meters before the end line in 100M run, end with first gear AND getting new world record!



Yelena Isinbayeva: This girl breaked her own world record 24 times (!!!) in pole high jump, and the most delicious one was the last, when she competed herself (and although she assured her gold medal) and succeeded jump 5.05M. I like isolating relaxing herself moment before getting started.


Links (videos):
Phelps - all way to 8 gold medals
Bolt - 100M world record
Bolt - 200M world record
Isinbayeva - the unbelievable jump

These were the most outstanding athletics in Beijing 2008, but how about the Hottest female athletics in Beijing 2008? :-) seems interesting? click here for the nice thread.

12 August 2008

Randy Pausch Last Lecture

Professor Randy Pausch (Oct. 23, 1960 - July 25, 2008) gave his last lecture at the university Sept. 18, 2007. In his moving presentation, "Really Achieving Your Childhood Dreams," Pausch talked about his lessons learned and gave advice to students on how to achieve their own career and personal goals.
Some people change my life when I hear them, and he was on of them, although after he passed away... The lecture is 76 minutes, but worth every one.



Article(Hebrew):
http://www.nrg.co.il/online/43/ART1/765/525.html

שונא שדות

אני לא חשמלטור, אבל את השיר אהבתי

Asi & Guri - Best hebrew show ever!!!

I've to say, these guys are too crazy, intelligent and very funny... I've seen their show thousands times and every time I laugh even more... here are the best of their show







09 June 2008

Asus Eee PC

As part of the Project in Parallel/Distributed Programming (236371) in the Technion I got an Asus Eee PC and I have to say: it's really easy to learn, easy work and easy play. The Eee PC with 4GB surf is a small nice laptop, with Linux Xandros OS, 7" compact design and less than 1kg has -without a doubt- delivered the goods.







For more info: Asus Eee in wiki

31 May 2008

Birthday Google Calendar

When I was at High-School I never forgot my friend's and family birthdays, I even remembered their cellular numbers and IDs. But now, I don't remember anything about dates and almost forget all my friends birthdays :( , therefore, I decided to put them all on my Google Calendar. I've a huge mass of event that I need to add to the calendar and adding them manually one by one wasn't an effective idea, so I developed a a simple gadget which receives a URL that has a list of birthdays and converts it to a text in iCal format which can be imported to Google Calendar. In order to use the gadget please click here to add the gadget (or press on the button below) and then read general description to use it.

Add to Google