Posts Tagged ‘programming’

Design Patterns Course

September 25th, 2009

I’m planning to launch a software design patterns course in Mansoura on Fridays for 5 days that would introduce the most important patterns (8 Patterns) to those who are interested in software design.

The course is comprehensive and will have hands-on example using Java 5. The course is also considered the first professional design patterns course in Mansoura, if you are interested please post because I’m collecting votes.

Mercurial 2

September 16th, 2009

Session 2 of Mercurial Tutorial in Arabic

http://www.vimeo.com/6597676

التسجيل كان قبل الافطار بنص ساعه فعذراً لو كان فيه لخبطه بسيطه في الكلام :)

Introduction to Mercurial

September 12th, 2009

This is an introduction to mercurial distributed SCM published as part of my contributions to CAT H4c3krZ, the video is in arabic and all the next sessions will be in arabic also.

http://www.vimeo.com/6519247

Let me hear your opinion….

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.

Python or Java

May 10th, 2009

I’ve been enjoying working with C++ and Python for 6 months now in a very interesting project that might change the way people look at storage in data-centers and the mix of using such extremes is because sometime you want fine control over memory and CPU instructions and sometime you just want to get things to work with less headache.

I’ve also been using Java for quite sometime now and I’m using java these days in my project CAT-SCMP that I’m really happy with it and with its progress, and I was thinking about the differences between python and java and when/where to use any of them, after some thoughtful thinking and practical experience, I’ll tell you :)

Java is quite amazing and I like lots of things in Java as a C++ programmer, the language has small vocabulary and consistent thinking in almost all of its API and the performance is stunning even if you are writing I/O programming you can still achieve performance that can really compete with what you can do with C++, especially, while using Java NIO.

Also, it’s platform independent so compile-once, run-any-where is a bless specially for people like me who take care of the differences between operating systems behaviour and different system calls / API. Java is excellent in portability and does lots of healthy emulation for things that are not available in the operating systems and uses the direct calls to the system calls if they are available.

Python is really amazing too but for different reasons, it’s an amazing language for prototyping in general, so you can get something that can really work in one third the time  you will spend on Java doing the same thing, and the dynamic typing is really cool, you don’t have to worry much about types and you can hackingly use the duck-typing that is pythonic, easy, and fast.

However, python will really encourage you to break the rules and does encourage design-less programming which I don’t really like, some people say that iterative programming means that you don’t have to design before you start, this is WRONG, you might want to read the legendary article from Martin Fowler (Is Design Dead?)first before you say that again.

Python will also help you to do more while typing less, but the performance is 1/50 of java, it’s not bad if you are writing something that is small but I really can’t see that it’s good for large systems, Java is really superior in the overall performance compared to python.

Also, python is not so much compile-once, run any-where thing, because some of its standard library methods are not even available on all platforms, so you have to be sure that you write code that is portable (it’s your responsibility) or you may want to involve a continuous integration system to make sure that you have your system running all the time on all the systems that you are targeting.

Conclusion:

  • Java is for larger, well designed, portable, and highly scalable systems.
  • Java achieves excellent performance for overall system performance.
  • Python provide much faster development and allows less thoughtful designs.
  • Python is really excellent for small systems, Gui’s, system administrators.
  • You can still do some enterprise work with python, but you have to create your own boundaries and enough documentation.
  • Java is not very good in GUI and generally slower than python in that particular area because of the platform independent windowing it’s using, while Python is much faster because it has no windowing and it uses whatever native library you choose like PyQt, or PyGTK for example.

Talk to GTalk from Python

April 27th, 2009

Some friend of mine asked me today if I can help him to communicate with google talk from python as he wants to send notifications about some network usage over the chat service. In fact, that was pretty interesting and it just inspired me with tons and zillions of ideas that you can do with that, things like getting security alters, usage logs, any simply feedback that you want to receive while being online and without being irritated with the fact that you have to refresh what you are monitoring every while.

It’s not a hard trick at all, but looks like all of the scripts on the internet are written wrong! and he have been trying to use all of them with no luck, so I helped him as I have some good experience with python-xmpp (xmpppy) module in python.

The idea is that we want to send a message to a Google Apps. User and use another account on the same domain to chat and here comes the trick about it and of course this script is released under the BSD License so you can do whatever you want to do with it :)

import xmpp

client = xmpp.Client('ahmedsoliman.com')
client.connect(server=('<a href="http://talk.google.com/" target="_blank">talk.google.com</a>', 5222))
client.auth(user='myUser', password='myPassword', resource='myResource', sasl=0)

client.send( xmpp.Message('anotherUser@ahmedsoliman.com', 'Hello World'))

Of course you can download the python-xmpp package manually or if you are using fedora, simply use the magical yum install python-xmpp

New Antinetcut 0.25

December 29th, 2008

Dear All,

Today I would like to announce the launch of the new Antinetcut 0.25 with major enhancements like,

  • Now it with alll Unix/Linux and Mac OS X support.
  • Remote management using XMLRPC.
  • Now antinetcut run as daemon, no longer in a terminal with comprehensive logging to a separate log file.
  • No more shell scripts, pure Python code.

The code-base is smaller, lighter and alot easier to maintain and versioning has changed to allow better indication to work done

The project page now contains several pages that explain how you can use the new antinetcut under Linux/Unix and Developers’ Guide to use XMLRPC to control antinetcut.

Download directly from the project page http://code.google.com/p/antinetcut/

AntiNetCut v2

August 13th, 2008

At last, I’m very happy to announce the release of the long-waited Anti NetCut version2.

Main Features:

  1. Works on Ubuntu/Fedora/RHEL..
  2. Written in Python so it’s easy to maintain and update.
  3. Automatic detection of almost everything (you might need to supply the interface name as illustrated below)
  4. Works perfectly with NetCut 2.8…

The usage instructions are too easy, just download and edit the antinetcut.py file (change “device=eth0″) to your interface name and run the script…


Notes

  • You must leave the script running in the background, stopping the script means that you might get attacked again.
  • After starting the script, it might take a few seconds before you get your connection back, so please be patient.

Anyone wants to join development, please see the official page http://code.google.com/p/antinetcut/

Download from here: Download Here

It’s Efficiency Not Speed!

May 5th, 2008

I know that this topic might look weird, that’s because it is. :)

While exploring new programming languages and frameworks I discovered a really important rule, that efficiency is the main thing that really matters, not speed. Let me tell you the complete story.

For the last year I spent too much time studying my programming performance and how can I finish tasks as fast as possible with maximum output performance possible. I thought that I’m slow and my programming speed is getting slower and slower while I see people finish complete applications in half the time I spent writing something. so I quickly started to search for new technologies for agile development and I found really great things, things like “Ruby On Rails”, “Django”, “GWT”, “ExtJS” and many many web development frameworks for agile development.

I quickly read about Ruby On Rails and I became a fan of it, also I wrote a project using GWT-Ext “Java” and wrote some samples using Django. They were/are great.

I’ve always had a philosophy regarding programming performance, that it is speed is very important, because time is money and when you spend more time writing code you are spending more time. That’s why using such frameworks is very nice.

But after sometime I discovered that I write code efficiently not fast!, how is that?

Efficiency is the output compared to the input, and for constant input increasing output increases efficiency proportionally, but if we are decreasing input that would enhance the efficiency more.

Writing code fast is a very nice thing and would greatly help, but writing a well-thought code slowly is more efficient because you generally write less code and you decrease the potentials design-errors you might see later on. so the best thing is to control both, try to increase the output as you can and decrease the input as you can without sacrificing output quality.

In programming this can happen if you have learned the programming basics correctly, things like Algorithms and data structures can really help you write more efficient and error-calculated code. you would write great code in much less time that can perform better. Thus increasing your programming efficiency.

So the result is the efficiency is what matters most. Not speed, it’s OK if you are slow programmer but make sure that you write code efficiently because that will make your final performance better.

Increase your efficiency by reading more about academic programming basics and performance-tuning books so you can think more efficient and use inputs more efficiently and generating high output.

حاجة مالهاش علاقة بالموضوع خالص بس متغاظ منها قوي، كوكاكولا عاملة سلسلة اعلانات عن كوكاكولا زيرو و بتقول كوكاكولا عملت المستحيل و انت كمان ممكن تعمل المستحيل

انا عايز اقول ان لو حد عمل المستحيل يبقي هو مش جامد او اي حاجة، كل ما في الأمر ان الموضوع ما طلعش مستحيل و لا حاجة، لأن المستحيل هو الشئ اللي محدش يقدر يعملو و لو حد عملو يبقى مش مستحيل من اساسة، صح؟