Categories
Python

Compiling Python Apps to Exe on Windows

Python is shipped by default in Linux and Mac. So deploying a python app is quite easy on these platforms. But it remains a pain in you-know-where when you try to distribute your app among Windows users. Windows people are usually habituated to getting exes. So, with a little effort and a very useful tool, we serve them what they desire.

There’s this PyInstaller utility which converts python scripts into exes. You can create a directory installation (one single executable and other necessary files in a directory) or just a plain exe everything embedded into it. If UPX is available on your system, you can take advantage of that too. So, how do we achieve this?

# First get Python from http://python.org [Probably you already have it]

# Get Pywin32 package. You must match the version of PyWin32 corresponding to your Python version. I am using Python 2.5, so in my case, I must use the pywin32 package which has been built for Python 2.5.

# Get PyInstaller from http://www.pyinstaller.org/

# Extract the pyinstaller content and add to path. You have to right click on My Computer, Go to Properties. Go to Advanced System Settings > Environment Variables. Modify the “PATH” variable and add the location of the extracted pyinstaller directory. Now we’re ready!

# When we first time use PyInstaller, we must generate the configuration by typing this command:

It will generate a configuration file in the pyinstaller root directory.

# Now to compile a python script, use this command:

You can find full documentation under the “docs” folder of the pyinstaller directory. Please note the different options to pass to the Makespec.py file to change the behaviour of the executable. For example: I do like this

The -F parameter makes it a single executable with everything embedded inside. The -w parameter makes it a windowed app so no console is displayed. I need it specially when compiling a GUI app written in PyQT 🙂

So thats it, quite simple! Have fun 🙂

Categories
PHP Work

PhpTube: A PHP Class to get download links from Youtube Watch URLs

THE API HAS BEEN BROKEN FOR A LONG TIME, AND I DON’T WANT TO FIX IT SINCE THERE ARE BETTER ALTERNATIVES LIKE “youtube-dl”.

Let me get to it straight: I wrote a php class that takes a youtube watch url (the typical url to watch a video, the url has a “watch” GET parameter in it) and returns the download links for different available formats of the video. Please note that these links will be valid for the requesting IP address. That is you can not download the videos from other IP addresses except the only one IP adress that actually originated the download request. So if you put it on your server and send these links to your users, they’ll certainly not be able to download from these links since their IP addresses will be different from your server IP address. In that case, you should first download it to your server and then link to those downloaded videos.

You can download the source codes from my github repo: https://github.com/masnun/phptube 🙂

An example:

Output:

Categories
PHP

My LAMP Environment

Today, I am gonna share a short overview of my work environment. I’m gonna detail on how you can setup yours too. First lets get to the L part. I am running Ubuntu Linux 11.04. Well, I do hate the default Unity UI. But good lord, we have the fall back options like “Ubuntu Classic” which is Gnome I believe. After installing Ubuntu, I installed the LAMP server using the “tasksel” utility. I love it because it’s handy and lets me do all sort of package management and software installation based on the nature of task. By default, in Ubuntu 9.10+ versions, we no longer have “tasksel” installed by default. So, open your terminal and get the utility from the repository by executing the following command:

Now that we have tasksel installed, we can install all the packages necessary for LAMP server using another handy command:

Man, I love this terminal and command line geekery! It’s just feels like magic! We’re done setting up the LAMP server. Visit : http://localhost/ and you’ll get the local web page 🙂

Now, the www folder is located to “/var/www” which is owned by the user “root”. So, we take the ownership :

Aha! Now you can create files and directories in the www directory and enjoy!

Well, now if we need to enable a custom apache module, we do this:

It’ll display a list of available modules, type in the ones you need and press enter. After selecting the modules, type this command to reload apache:

Now that we have apache, mysql and php running, lets install some GUI tools for mysql. Here goes the commands:

So far we have installed the basic tools, now lets install PEAR 🙂

Now that you have PEAR, we can install a nice utility – “pman”.

Pman is handy for command line php documentation. Just try like this:

It’ll give the docs for the strlen function on the terminal just like the linux man utility 🙂 Press “q” to quit the man page.

By default, php doesn’t come with curl and gd in linux. Install them like this:

Now that we have a working LAMP setup, lets get some additional tools: SVN, Git and Filezilla.

Ubuntu has Gedit, a text editor with Syntax highlighting. While Gedit can be used for PHP development, most of the popular PHP IDEs have their Linux version. I have used both Netbeans and PhpStorm on Ubuntu. And I know Eclipse run on Linux as well. So fire up your favorite IDE and storm the LAMP arena! 🙂