Happy Halloween, I still have to go get some treats
I have so much work too but I decided to work on Saturday too, it’s great to be a freelancer!
October 2008
Happy Halloween
One Problem With Python
I think one problem Python has is the lack of a great online manual, with great I mean like PHP’s:
http://www.php.net/manual/en/function.ftp-alloc.php
Every single function is documented with examples and I think this is one of the main reasons why PHP is so popular.
A PHP Competition
OK, here is the competition:
Write the shortest piece of PHP code to convert:
Lorem_ipsum_dolor_sit amet,_consectetur_adipisicing_elit
Into this:
Lorem_Ipsum_Dolor_Sit amet,_Consectetur_Adipisicing_Elit
There is no prize other than I will write a post about you ![]()
Leave a comment.
Update:
Chris wrote a perfectly working line of code for the first string I posted, but you will have to write one that will still work if there is a space in one of the words. I fixed the example.
I Heart Python
I always knew about this language but I was so busy with PHP and daily work that I didn’t really get to learn it and whenever I looked at the syntax, it scared me, I didn’t want to learn another syntax so I decided to learn it later.
About a month ago, I came across Python and got a chance to play with it and I have to say WOW!
It is one of the coolest languages I’ve ever seen, the syntax is cool, the laziness is cool.
It has a great library and you can do anything you want basically.
To see some cool things, go ahead and download the Python interpreter here:
http://www.python.org/download/
Get the latest version and after you are done, run it and type these:
(Note: You will have to hit enter/return twice at the end of last line.)
import urllib2 def get_url(url, num): contents = urllib2.urlopen(url) print str(num) + " done!"
Tabs are important!
Then go ahead and type these:
for i in range(0, 100): get_url("http://www.yahoo.com/", i)
Note how clean this is, the code speaks for itself.
As you can see the output looks like this:
0 done!
1 done!
2 done!
3 done!
4 done!
5 done!
6 done!
7 done!
8 done!
9 done!
…
Now I will show you some of Python’s powers, go ahead and type these:
import thread for i in range(0, 100): thread.start_new_thread(get_url, ("http://www.yahoo.com/", i))
Wow! This is so great, imagine how much you can do with this language.
Also note that, I’m not an advance python programmer and I’m still learning but this language will take over the world one day.
The only thing about PHP is that it can be embedded inside web pages but it would be very easy to write a template engine in Python to do this.
It could be like PHP’s Smarty but with Python syntax and could compile the templates into Python scripts and run them instead of compiling every time. It would then check for the mime time of the file and would recompile if there were any changes.
I’m having so much fun playing around with Python and have never been this excited about a programming language
Comparing Programming Languages
I just found this great tool and I thought I’d share it, it compares performance and memory usage in any two programming languages, it has a good list of languages too.
For example, this is the comparison between PHP and C:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gcc&lang2=php
PHP vs Python:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=python&lang2=php
Python vs Ruby:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=python&lang2=ruby
C vs Java:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gcc&lang2=java
And finally C vs C++:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gcc&lang2=gpp
Calling a JavaScript function from Actionscript 3 (Flash)
It’s very easy:
import flash.external.ExternalInterface; ... ExternalInterface.call("your_javascript_function()");
You can even get a return value:
var x:int = ExternalInterface.call("get_x()");
To pass an argument try:
var retval:int = ExternalInterface.call("some_js_function()", "the-argument");
iGoogle uses yui (Yahoo User Interface Library)
Funny, I would imagine that they have developed an in house JavaScript library by now but this is great, using a well maintained and good library is a great programming practice.
You can check it out here:
http://www.google.com/ig
(Right click and view the source)
Yes, I have to see the source code for everything I can find
I personally can’t imagine living without jQuery, I used yui for a long time but jQuery is a beautiful piece of engineering.
yui is still great and has so many components but it’s not my type, I’m lazy
How to move a column’s position in a MySQL table
You can move a column in a MySQL table to another position like this:
ALTER TABLE name_of_the_table MODIFY column_to_move tinyint(1) DEFAULT '0' AFTER column_to_move_after
Note: the part with: “tinyint(1) default ‘0′” is necessary and it should be the exact definition of your column.
For example yours might be:
int(10) unsigned NOT NULL auto_increment
or
int(10) unsigned NULL default ‘0′
or
…
Hamid Alipour is a partner in Codehead, LLP with his wife, Tess. Hamid speaks 12 markup and programming languages [Yes, 12: PHP, CSS, Ajax, JavaScript, HTML/XHTML, Java, Python, C/C++, ASP, Visual Basic, Scheme and Action Script]; has a penchant for solving the unsolvable; an affinity for clean, hand-written code and is a Zend Certified 