Archive for July, 2009

Python recursion performance test

July 15th, 2009

That’s really shocking, I even tried several ways to optimize performance without touching the code and still performance sucks!

Fibonacci simple recursion solution takes 3 seconds to execute with C code and about 2 minutes in python!

Here is the code I used for the python version

def fib(x):
    if x == 0 or x == 1: return x
    return fib(x-1) + fib(x-2)

if you called fib(40) it will take about 2 minutes! the C code is exactly the same and it’s compiled with normal optmizations (-O0)

I compiled the python to pyc and used the pyc and still around 2 minutes (slightly less)

the impressive thing is that the dynamic programming solution works perfectly in no time, try this

def fib(x):
    t = [0, 1]
    for i in xrange(x):
        t.append(t[-1] + t[-2])
    return t[-2]
 

call it for fib(40) and see the performance gain.

the bottomline is that you shouldn’t use recursion in python.

If you have any suggestions to make this goes faster (I thought about trying stackless python here) I’m really happy to discuss them.

Etisalat USB Modem on Fedora 11

July 12th, 2009

This is how to get Etisalat USB modem working on Fedora 11.

“Etisalat Masr” new USB modem that supports HSDPA is based on Huawei E1550 USB Flip-Flop stick, so you need to get usb_modeswitch first to be able to switch the device from being a storage usb device to USB modem mode and this can be done easily by:

yum install usb_modeswitch

Then you need to add the following to the configuration file /etc/usb_modeswitch.conf  (add the following in the end of the file)

# Huawei E1550
DefaultVendor = 0x12d1
DefaultProduct = 0x1446
MessageEndpoint = 0x01
MessageContent = "55534243000000000000000000000011060000000000000000000000000000"

I got those information by sniffing USB on windows and you don’t have to do that because probably your MessageContent is the same as mine if the device is the same as mine and you can check if things are working or not by running

lsusb

and you will see a line like that

 ID 12d1:1446 Huawei Technologies Co., Ltd.

and then run

usb_modeswitch

you should see output like


* usb_modeswitch: tool for controlling "flip flop" mode USB devices
* Version 0.9.6 (C) Josua Dietze 2009
* Works with libusb 0.1.12 and probably other versions

Looking for default devices
Found default devices (1)
Prepare switching, accessing latest device
Looking for active default driver to detach it
OK, driver found ("usb-storage")
OK, Driver "usb-storage" successfully detached
Setting up communication with device
Trying to send the message
OK, message successfully sent.
-> See /proc/bus/usb/devices (or call lsusb) for changes. Bye

and please note that usb_modeswitch MUST be run as root, otherwise you will get an error.

if you got a message like the previous one then you can use the device directly from NetworkManager and you can check if the device has switched or not from the output of lsusb, it should be something like that now:

ID 12d1:1001 Huawei Technologies Co., Ltd. E620 USB Modem

Have Fun :)

Lessons We Learned From H4ck3rZ Online Systems

July 3rd, 2009

We have been using forums and CMS systems for long time now to run all CAT websites on the internet starting from the ancient CATReloadedt website that was based on Drupal and ending to this amazing and extensible system “H4ck3rZ Network” that’s based on Buddypress and we have faced hunderds of problems that we didn’t really spend the right amount of efforts to learn from and to solve.

We in H4ck3rZ have spent sometime thinking about that and studying how to stop falling into the same problems and how to engineer a system that is really scalable without the loss of users information that is the most precious piece of our software and we could really design a system that can fix most of our problems in a granular manner, so we can fix things as we go and with minimum users intervention. But because we are engineers and our H4ck3rZ community is engineering community, we decided to share you some of the internals and details of what we have done.

The Ancient Problems

For long long time a faced a problem that we didn’t learn from it, that’s having accounts of our members stored inside the system and we didn’t feel the problem until we faced the problem of migration from drupal to phpBB and the booming fact is that migration might not be possible and people have to register again, we also had a mailing list that had its accounts stored in it and it’s a completely isolated island and we had no easy way to check if both systems are in-sync or not. More problems was arisen when we started the foundation system because each foundation started building its own website and again we lost the user base and people started new registrations on each website independently and moreover people used several e-mails and usernames and that was really a hit because now you cannot identify people by username anymore a good example is that I used the username h4ck3r in H4ck3rZ Foundation online systems while I use the username ‘linuxawy’ in PixiCat and please don’t ask me why :D

read the rest of this article in my blog Soliman n H4ck3rZ

H4ck3rZ Duo

July 1st, 2009

السلام عليكم و رحمة الله و بركاته

sp_image-472447071-12463907822-sml

نتشرف بدعوتكم لحضور اهم مؤتمرات الهاكرز التقنية و الذي سيستمر لمدة يومين متتاليين “هاكرز ديو” و سيبدأ المؤتمر يوم السبت القادم 4/07/2009 بإذن الله تعالى الساعة التاسعة صباحاً في مدرج 21 في كليه الهندسة جامعة المنصورة و الذي يتم تحت رعاية منظمة مشروع فيدوراالجدول موجود على: موقع الهاكرز و سيتم الأعلان عن تفاصيل أكثر قريباً جداً إن شاء الله

هذا الحدث بدعم من مشروع فيدورا و مجموعة مستخدمي اوبن سولاريس مصر

Assalamu A’alaykum,

We are thrilled to invite you to one of the most important events of the H4ck3rZ Foundation during the year, the one which will take 2 days and is called “H4ck3rZ Duo”.

The sessions will start next Saturday 4/7/2009 and will end on Sunday 5/7/2009.

The event will be held in 21 Lectures hall in faculty of engineering, Mansoura university and the event is sponsored by the Fedora Project Organization.

The schedule is on the H4ck3rz website and more details will come soon isA.

This event is sponsored by Fedora Project and the Egyptian OpenSolaris Users Group