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, 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!
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.
Archived under PHP, Programming, Python Comments
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.
Archived under Fun, PHP, Programming Comments (9)
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
Archived under Programming, Python Comments (3)
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
Archived under C Programming, Fun, General, Programming Comments (2)
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()");
Archived under Actionscript, Flash, JavaScript, Web Development Comments
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
Archived under JavaScript, jQuery, yui Comments
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
…
Archived under MySQL, Web Development Comments
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!
Archived under Annoying Stuff, Programming, Server, Web Development Comments
When you parse XML with PHP and libxml 2.7.0, all HTML entities were stripped out and this annoying bug messed up a lot of things and no one seems to care enough to fix this.
This bug is also reported here:
http://bugs.php.net/bug.php?id=45996
http://bugs.typo3.org/view.php?id=9359&nbn=2
From reading these few resources, I knew I had to downgrade to an older version of libxml but since I’m not very good at Linux I had no idea how to.
But I finally figured this out and here is how to do it with WHM/cPanel:
First you will have to install an older version of libxml, I installed libxml 2.6.30.
You will need an SSH client and you will have to login to your server with root, I use Putty:
http://www.chiark.greenend.org.uk/~sgtatham/putty/
Download it, run it, enter the IP address of your server, enter root and enter your password.
Then do:
cd /opt
mkdir libxml
cd libxml
wget http://xmlsoft.org/sources/libxml2-2.6.30.tar.gz
tar xvzf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure –bindir=/opt/libxml/ –sbindir=/opt/libxml/ –libexecdir=/opt/libxml/ –datadir=/opt/libxml/ –sysconfdir=/opt/libxml/ –sharedstatedir=/opt/libxml/ –libdir=/opt/libxml/ –includedir=/opt/libxml/ –oldincludedir=/opt/libxml/
make && make install
Now you will need to update yum.conf to prevent it from updating libxml back, so edit:
/etc/yum.conf
And find the line that starts with:
exclude=
And add libxml* to the end of it so this line should look something like this:
exclude=apache* bind-chroot courier* dovecot* exim* httpd* mod_ssl* mysql* nsd* php* proftpd* pure-ftpd* spamassassin* squirrelmail* libxml*
Now we will have to let WHM know that we want to compile PHP with this new libxml path so go to:
/var/cpanel/easy/apache/rawopts/
There might be a file there named: “all_php5″ (no quotes) if there is edit it if there is not create it and add these lines to the end of it:
–with-libxml-dir=/opt/libxml
–with-libxml-dir=/opt/libxml/
Now go ahead and build Apache and PHP using:
Main >> Software >> Apache Update
You should be all set.
Please note:
1 - Do this on your own risk.
2 - I’m not very good at Linux so please let me know if there is an easier method.
3 - This worked great on my CentOS.
4 - If you have never used WHM’s Apache Update, go ahead and read about it first.
Archived under Annoying Stuff, PHP, Server, Web Development Comments (6)
This is a big issue and broke a lot of our websites unfortunately.
The problem is that the cdata_handler will be called when the parser finds tokens like < and passes nothing to your cdata_handler which it’s suppose to pass things like < or >.
The problem is with libxml 2.7.0 and 2.7.1 and 2.7.2 fixes the issue:
http://xmlsoft.org/news.html
They say 2.7.2 fixes it but it doesn’t really, it’s very disappointing.
Archived under PHP, Web Development Comments
Here is the link:
http://mindview.net/Books/DownloadSites
Use any of the mirror links to download these great books by Bruce Eckel.
I read his thinking in C++ a while ago and it’s really great.
His book on design patterns in Python is the one I’m reading now.
Archived under General, Programming Comments
Here is how to install ffmpeg:
1 - Create a file named “dag.repo” (no quotes) in “/etc/yum.repos.d”
2 - Copy and paste these lines in it:
[dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag gpgcheck=0 enabled=1
You will need a newline at the end of the file.
3 - Then run “yum install ffmpeg ffmpeg-devel” (no quotes)
This should install it with no issues, note that I set gpgcheck=0, if you search for it you will see a lot of people are suggesting: gpgcheck=1 which yields to something like:
warning: rpmts_HdrFromFdno: V3 DSA signature: NOKEY, key ID X
Here is how to fix it:
1 - Right click on Flash’s desktop (or whatever) icon and then click “Properties”
2 - Go to compatibility tab
3 - Check the box “Run this program in compatibility mode for:”
4 - From the drop down select “Windows XP (Service Pack 2)”
5 - Open Flash
And that’s it, it will run smoothly, or at least it did for me.
Archived under Actionscript, Annoying Stuff, Flash Comments