Monday, April 13, 2009

Ldaptor, Python List, Django

LDAPtor - The king who never made it

I wanted to deploy ldap server on windows. Apache DS with a 200 simulated user environment went kaput and need frequents restarting/backup. Openldap on Windows via the berkeley db was prone to corruption as well. Nothing seems to work robustly under Windows for some of these open source projects, no matter how popular it was. 

Then i found Ldaptor, written completely in python via the Twisted framework. Wasn't really a big fan of the Twisted framework, heck, the only book on Twisted i saw by Oreilly, had examples that are "badly" coded in my personal opinion, works though. One can't doubt the benefit of having such a large ready made framework. 

After just 5 minutes trying out ldaptor, it bombs out, won't even run, turns out that some modules are referencing the previous Twisted "components.interface" and should be replaced with "zope.interface.Interface", then it runs. Now just have to figure out how to import the Ldif into it...documentation seems to be scarce on ldaptor..."Ldaptor will one day rise to world domination" 

Thats the problem with a LOT of open source projects, abandoned or left dying prematurely when the Initiator found something more profitable to do...

> Switch Channel ....

I am really grateful for some of python default implementation and behaviour, especially on its container. 

I wanted to get a list of files in a directory and process it according to its "creation time". i did a "glob.glog" on a directory, the return result  was anything but sorted.  The normal procedure would be something like this :-

1. get each of the files creation time
2. sort based on the creation time
3. process the file

In python that translates to :-

ActualFiles = [(os.stat(x).st_ctime,x) for x in GetFilesListing(path))]
ActualFiles.sort()
for x in ActualFiles : 
# do something with already sorted x[1]

When i wanted to remove some items from a list and yet continue to process the list :

for x in MyList[:] :
if x.value == "whatever_i_am_looking_for" :
MyList.remove(x)


If this was translated  to C++ it would be something like this  (warning: it won't work!)

for (ptr = listcopy.begin(); ptr != listcopy.end(); ptr++)
{
if  (ptr->value == "whatever_i_am_looking_for") 
{
listorg.erase(ptr)
}
}

Thus, someone who starts on python would probably find it hard to move to C/C++ but
someone who starts from C/C++ would  easily addicted to python and appreciate its fun way of working (lazy).


> Django

I wonder how does Python web building such as Django matches against premium platforms like ASP.Net. Just the other day some people working on PHP was amazed to see how building cool working websites was done in ASP.NET. All those ajax coding are so automated it makes similar offering in PHP looks primitive not to mention the state of the art Visual Studio IDE.

Frankly developing website is something that is out of my reach but it would be great to see how Python fare in this area. Better than PHP? Ruby on rails? Come on, it has to do better. 


 







Saturday, March 28, 2009

Programmer's Mind vs None Programmer

There are basically two types of jokes among the elite programmers when it comes to people who are non technically inclined or non-programmers.

#1 :
Sometimes people in Malaysia here thinks that they can just pump in a few million, start a team and expect to get a project done. Little do they know of the various traps and software pitfalls that awaits such a team. Unless its a crony project that don't mind accepting substandard deliveries, most of these projects often end up in the drain. Sure there are some big companies here that hire top Chief architects whom never deliver any projects to a real competition, all inhouse or cronies companies deliveries. Little do these self deceived Architects are aware of how weak their skill and proficiency are in that area. When you are the Chief Architect of such big corporations, everyone wants to kiss ur ass, no matter what ur true capabilities are.

This phenomena is so common that over here, the local folks have a name for it. Its called "Jaguh Kampung". In english it means "Village Champion". What happens when a few village champions join an international competition? They learn the meaning of "Village".

Each year in local software Awards here we see various Sofwares being conferred the "Software of the year", often these Software are either developed for its own use or for its branches. If you look at the track record, almost all the winners have ran out of business or no longer using it.

#2 :
There are Sales and Business people who don't know how dumb they look when saying something to the technical team or when accepting a business proposal whom they know nothing of in programming terms. When the technical team rejected the proposal, they have the impression that their team is incapable or does not have business sense, where in actual fact, the 
problem is in the mirror.

Someone i knew once asked me to write a local chat software, i asked him "what is the sales forcast?" He replied "well i am sure there are many, let me call up this ABC company and see if they want it". (This is a clear sign to "reject" the idea, no proper thoughts given to the project and just do a blind jab by asking some programmers to commit to it).
Anyway, to deter him i ask him further "what are the specifications?". He replied "Oh, its very simple just do exactly what Skype can do and make it work in LAN".

** If you are not laughing already, you should stop reading this post.

Another story i heard is about this lady, who has many connections and "cables" to VIP people. Often she would try to get some projects from these people and her technical partner would reject it. She would then be very upset and gave some lectures on "How important is business and why nothing is impossible to code". A very sad partnership that is destined to end up in the gutter. What most of these "business" people don't understand is that, What you see on paper and in request is VERY different when its translated to actual coding. It can be so different that its actually supernaturally unrealistic to take it up. For example would you commit a team to write a product in 6 months and due to economics of scale, you would need to pay USD 1000 for an appliance/embedded system while out there, there are similar products retailing at USD 400 that is doing exactly the same thing?

If you have such a boss or partner , you should use this statement to bring enlightenment to him/her by saying "Actually if we want to make money we should just get a team to write an OS what works exactly like Vista but with a budget of USD 100k." or "Lets write a Windows 2008 replacement in 6 months, that sounds easy too isn't it?" or "Lets write a replacement for MS-Exchange and make it cooloer in 6 months"













Sunday, March 8, 2009

Windows Mobile : The evolution of O2 -> Dopod -> HTC (its HTC all along)

The Windows mobile has always been manufactured by HTC. Many years ago, its called
O2, sleek looking Phone PDA that usually sells well on first launch and turns out to be very buggy devices . The cycle repeats when new versions are launced. This is because out there, there are many people who love Windows and used to the Windows Experience, the option of having a mobile that has outlook and other familiar apps working is a big motivation for the purchase.

However, O2 really took the bulk of the fall as people began to wake up and identified it as an unusable device. Guess what? After the demised of O2 brand in Malaysia here, Dopod came up, with some brand new units and exciting offerings . Again, same forgiveness and embracement by the community, good sales and popularity of Dopod began to soar....only to be greeted by the same negative feedback and buggy usage.

The problem really lies with Windows mobile and cheap plastics production that easily wear off and scratches for usage that was never designed to last. Windows mobile started off as Windows CE hacked and rush into a market that is dominated by Nokia and Symbian. When it comes to phone usage, it sucks and is buggy.
I remember the O2-XPhone, boy, i must say i can't find a dumber smartphone than that one and yet, it was sold presumtiously to the community with no sense of responsibility and accountability. 

Now that dopod is dying due to the same reasons that O2 went down, HTC decides its time to use its own name and produce units and avoid mistakes that was bourned by its previous two brands. 

Will i buy an HTC? No way, i pity those companies who are associated with the prev two brands and if history prove itself well, HTC units will go the same cycle. 















Monday, February 23, 2009

Switching away from Streamyx...or use together with Maxis

The last few weeks have been pretty frustrating for me.
I can't access public servers in an acceptable speed and some anti-virus websites and even my online banking was crawling to a halt. I notice the problem is affecting all streamyx users as i tried in office, in my house and confirmed with other collegues in areas like Damasara, Ampang and Puchong. Even trying out kids games like http://www.bigfishgames.com/ for my kid and http://www.standardchartered.com.my/ was slower than a 28.8 modem.

I did notice there are some "cheats", access to google.com and youtube.com is fast however try something else it drops dead. Seems like Tm.net is using somekind of packet shaper, one that is implemented in a very very bad way.

But there is this happy guy in my office that seems to be talking greek when we complain about Streamyx woes lately and he is using Maxis broadband. Heck, i thought give it a few more days maybe it will improved after all nothing beats experience and that is what Tm.net is, a veteran in Malaysia as an ISP.

While we oogled over his fast connection response in the office the inconvenience of terminating the Streamyx and trying out something new kept me unmoved.

Finally today, the last straw broke so to speak... I needed to prepare a demo and that particular site is slowing to a crawl when accessed by streamyx.

2 hours later and RM 100 poorer (for the wireless modem), i connected it to my exising wifi modem/router which i am using for streamyx, pulled off the phone line, some simple configuration and wahla! Everything works normally, my wife wont even know i switched when she comes home and use her other notebook.

^_^

There is ONE big catch though :

http://www.maxis.com.my/personal/broadband/termncon.asp
Excessive Usage
5.3.1
Each customer’s total usage per month shall NOT exceed 3GB of data volume transmitted (total upload and download usage). This is to ensure that no individual hogs the bandwidth at all times.

5.3.2
If a customer wishes to use more than the volume permitted,
a written request should be made to Maxis.
5.3.2
Maxis reserves the right to reject the said application or charge for any additional data volume transmitted from what is already allocated.


This is the only part that makes streamyx still the most popular choice. 3GB is nothing as you and i know for today's internet need. Heck even free emails has 10GB free volume.
Did i read this policy? NO, the promoter never talked on this problem nor show you the policy.
So I was right, Maxis is inexperience on this area, but for now, It will have to be or lets hope Maxis will have some sense and make a more realistic limitation.

**** Latest update ******
A technical guy from TM has informed me that there is a MAJOR problem on their international link that will affect many access outside of Malaysia. The problem is promised to be fixed by
5th March 2009.
Well, i guess i will keep both ...until a super isp emerge.


Since most servers in Malaysia is under streamyx and if you are in IT you will need to support these servers or remote in etc, i suggest you use the following "batch" file so that you can access out of malaysia servers via Maxis and local servers via Streamyx to alleviate the current problem :

Assuming your Streamyx router is 192.168.1.1 and your Maxis is 192.168.2.1, point ur gateway to 192.168.2.1 and put the following into a *.bat file which u need to execute whenever u want to connect to local malaysia servers.

route add 219.0.0.0 mask 255.0.0.0 192.168.1.1
route add 118.0.0.0 mask 255.0.0.0 192.168.1.1
route add 218.0.0.0 mask 255.0.0.0 192.168.1.1
route add 60.0.0.0 mask 255.0.0.0 192.168.1.1
route add 202.0.0.0 mask 255.0.0.0 192.168.1.1

Monday, January 5, 2009

Keeping and Switching Multiple Python Version on Windows

Assuming you have python 2.5 and python 2.6 installed.

Here is what you need to do :-

1. Right click on My Computer, under advance, environment variables.
Change all c:\python25 or c:\python26 path that u can find here to C:\python2x.
That includes c:\python2x\scripts, c:\python2x\lib, c:\python2x

2. Rename your c:\python25 (or whatever it is) to c:\python25.bin
Rename your c:\python26 (whatever it is) to c:\python26

3. type this to your command prompt (admin rights) :
ftype Python.CompiledFile=C:\Python2x\python.exe "%1" %*
ftype Python.File=C:\Python2x\python.exe "%1" %*

4. Create 2 batch file :
batch file 1.
xcopy c:\python25 c:\python2x /s /I

batch file 2.
xcopy c:\python26 c:\python2x /s /I

5. Fixup all the scripts dependencies.
For eg, goto c:\python25.bin\scripts, open up easy_install-2.5-script.py
Change the first line to : #!C:\Python2x\python.exe

You can repeat step 5 for other modules like nosetests, coverage etc. Else you will get the dreadful message "Cannot find Python executable ....."


Now, if you want to use python 2.5, just run the batch file 1 in your command prompt.
If you want to use python 2.6, just run batch file 2 in your command prompt.

There you go....

Tuesday, December 16, 2008

Python 2.6 : ez_setup and setuptools, pylint on Windows

After i installed 2.6 i notice there is no setuptools windows installer in the python.org site.
So to manually install it you need to :-

1. Download this egg file :
http://pypi.python.org/packages/2.6/s/setuptools/

2. Make sure u have download ez_setup.py from
http://peak.telecommunity.com/dist/

3. ez_setup setuptools-0.6c9-py2.6.egg
**
PJ Eby :
Actually, you can just download the source, unzip it, and do "setup.py bdist_wininst" to build your own .exe installer.
**

Now you need to download the pylint for checking /integrating with ur ide.
And again, u notice that u will fail to get it installed via "easy_install pylint", so here
is the manual way.

http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20848
http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20856
http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20857
(all the download links are at the upper right hand corner)

Download and unzip to all the folders, then goto each of them, common, astng, pylint and run :
python setup.py install


Case close.




.py association in Vista/Windows Missing

I was playing  with version 2.6 Python without uninstalling version 2.5. 
And for some reason i realize that when i execute a module without specifying the python.exe, the module could not get the arguments that was passed in.
For eg.

test.py argument1 argument 2
(argument1 and argument2 is missing from the sys.argv)

But
python test.py argument1 argument2 : works

Initially i tried "assoc .py" followed by "ftype Python.File" and the association was CORRECT!
It shows : Python.File="C:\Python26\python.exe" "%1" %*

Later i found out it was because there is still a registry key that is mapping wrongly.
Changing that registry key solves the problem.

Refer to the picture.