You Are Here Home > October 2008

October 2008

Happy Halloween

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!

Happy Halloween
Comments (0)   Filed under: Fun, General   Posted by: Codehead on October 31, 2008

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.

One Problem With Python
Comments (0)   Filed under: PHP, Programming, Python   Posted by: Codehead on

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.

A PHP Competition
Comments (9)   Filed under: Fun, PHP, Programming   Posted by: Codehead on October 28, 2008

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 :)

I Heart Python
Comments (3)   Filed under: Programming, Python   Posted by: Codehead on October 27, 2008

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

Comparing Programming Languages
Comments (2)   Filed under: C Programming, Fun, General, Programming   Posted by: Codehead on October 25, 2008

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");
Calling a JavaScript function from Actionscript 3 (Flash)
Comments (27)   Filed under: Actionscript, Flash, JavaScript, Web Development   Posted by: Codehead on October 22, 2008

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 ;)

iGoogle uses yui (Yahoo User Interface Library)
Comments (0)   Filed under: JavaScript, jQuery, yui   Posted by: Codehead on October 21, 2008

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

How to move a column’s position in a MySQL table
Comments (2)   Filed under: MySQL, Web Development   Posted by: Codehead on

Fixing libxml, php bug and issues with HTML entities; libexpat

There is another way to fix this issue and I didn’t write about it because I couldn’t make it work at first.
Apparently I was missing one line :)

First you will need to find out where libexpat is located on your server, it’s probably here:
/usr/lib

To find out for sure, open this folder (/usr/lib) and look for the file:
libexpat.so

If you can’t find it, log in as root via SSH and enter:
whereis libexpat.so

This should list the folder in which libexpat is located.

After all this you will need to compile PHP to use libexpat instead of libxml, so go to:
/var/cpanel/easy/apache/rawopts/

And create a file and name it “all_php5″ (no quotes), if there is a file with this name edit it and add these lines to the end of it:
–with-expat=builtin
–with-libexpat-dir=/usr/lib

(lines start with two dashes “-” that are not showing up here for some reason)
Remember that depending on where libexpat is located on your server you might need to edit the second line.

Now compile Apache and everything should work fine!

Fixing libxml, php bug and issues with HTML entities; libexpat
Comments (0)   Filed under: Annoying Stuff, Programming, Server, Web Development   Posted by: Codehead on October 19, 2008

How Small Are We???

How Small Are We???
Comments (0)   Filed under: Fun, General   Posted by: Codehead on October 17, 2008
Older Posts »