Posted by Codehead on November 14, 2008 at 2:17 am
Try this:
class stdoutflip:
def __init__(self, sys):
self.stdout = sys.stdout
sys.stdout = self
def write(self, txt):
txt = list(txt)
txt.reverse()
self.stdout.write(''.join(txt))
class stdoutupper:
def __init__(self, sys):
self.stdout = sys.stdout
sys.stdout = self
def write(self, txt):
self.stdout.write(txt.upper())
To test it do this:
out = stdoutupper(stdoutflip(sys))
Now try printing stuff:
Archived under Fun, Programming, Python
Posted by Codehead on November 12, 2008 at 3:31 pm
A while back, I wrote two posts about Microsoft and I wrote them when I was upset so it might have offended people.
To be honest with you, I was a fan of Microsoft and their products up until Internet Explorer 7 came along.
I installed it on two computers and I had to disable all the addons other than the essentials in order to make them run smoothly and without so much issues.
Right now, my Internet Explorer process grows until it’s 1GB in size!!! and it then gets so slow or crashes and I loose all my open tabs and what ever I was doing.
It also crashed every once in a while for some reason and it’s still not standard compliant.
About Windows Vista; we also bought four computers with Vista and every single one, without an exception had issues right out of the box, big issues that I think Microsoft should have known about but shipped the product anyway.
Honestly, this is disappointing for me, because I liked Windows and it’s openness and the ability for everyone to write great applications for it and it’s huge documentation on Microsoft website.
I also think that Microsoft contributed a lot to the industry and I hope that this is not the end of it.
I’m a software developer and I don’t consider myself to be the best one but I know one thing, we don’t EVER ship until we fix all the obvious bugs, if we did, we wouldn’t have any clients right now.
Good Luck
Archived under Annoying Stuff, General, Programming, Web Browsers
Posted by Codehead on October 31, 2008 at 4:53 pm
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
Posted by Codehead on October 28, 2008 at 4:24 pm
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
Posted by Codehead on October 27, 2008 at 8:53 pm
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
Posted by Codehead on October 25, 2008 at 3:21 pm
Archived under C Programming, Fun, General, Programming
Posted by Codehead on October 19, 2008 at 6:36 pm
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
Posted by Codehead on October 6, 2008 at 2:07 pm
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