Categories
PHP

Power of PHP: Resizing Images on Command Line

I’m too busy to explain the script now. In short, it scans the current directory for all the JPG images and converts them into smaller image files hardly compromising the quality. I managed to convert a 211 MB album into a 5.8 MB collection with this script. Modify the $dir varible which holds the location of target directory. Make sure the target directory already exists. Also change the $percent inside the resize function to control the output quality.

Thanks to PHP for such powerful image processing. I just ran the following command on my Ubuntu terminal:

I was done! Here’s the source code:

Categories
Python

Building A Proxy Scraper with 15 lines of Python

Yes, Python is great! It’s beautiful and so on…. I have described the power of Python many times. For now, just the codes 🙂 Here’s a proxy scraper I built a few moments ago. It scrapes the web page at proxy-hunter.blogspot.com and lists the available open proxies.

It uses the BeautifulSoup package for parsing HTML. On ubuntu install it with this command:

On other platforms, grab the package from its homepage. Google is there to find the URL for you 😉

Categories
Python

Using Python on Hostmonster, Umbrahosting And Other General Shared Hosting

I’ve a hostmonster and umbrahosting shared hosting where my sites are running smoothly in PHP. I’m perfectly happy with both UmbraHosting and HostMonster. Additionally both the hosting providers have Python support. Being a Python enthusiast, I decided to check out.

On both Hostmonster and Umbrahosting, you can execute Python scripts as CGI scripts. But you must take care of these points:

— They must be placed inside the cgi-bin directory.
— Permission should be 755. (777 triggered server error for me)

I didn’t find the latest version of Python anywhere on these two hosts. Let alone Python 2.5, they have Python 2.4. 🙁 But still I’m happy that I can run Python. The only thing that I didn’t like was the obligation to put my scripts in the cgi-bin directory. So, I couldn’t have URLs like https://masnun.com/hello.py 🙁

Later today afternoon, an idea clicke in my mind. Can’t I target a subdomain to the cgi-bin directory? The answer is: YES! Just use a .htaccess file to map certain urls to your cgi-bin directory.

Putting the .htaccess in your domain’s root directory will allow you to put a python file inside your cgi-bin directory and visit it from http://example.com/example.py 😀