Categories
Linux Python

Python and Django on Vagrant

Well, this is going to be another straight forward post with loads of shell commands. The background is simple, I love OS X for the many apps it offers but at the same time I always had the joy of developing on a Linux machine. I decided to use Vagrant to have one central box for my projects. I use separate vagrant boxes for complicated projects. But didn’t like the idea of having individual boxes for simple ones.

I work on Python and Django a lot. So in this post I am going to document my setup.

Vagrant File:

# I have assigned a private IP to the box
# I have assigned a hostname to it.
# I am using Ubuntu Precise Pangolin 64 bit as my base box (which I already have added)

Hosts File (/etc/hosts):

After I setup the box, I logged in using SSH:

Now, the usual Ubuntu setup.

Bash Profile in the Ubuntu machine:

# To make the Django built in server available from outside the box I need to run it on 0.0.0.0 so that it listens on all interfaces. So I added a handy alias.

# Added the virtualenv stuff to the profile

Bootstrapping a project:

Now the app would be available on: http://tardis.dev:8000

I also modify the ~/.virtualenvs//bin/postactivate script to cd into the project source directory. Saves time when I hit “workon env_name”

That’s it 🙂

Categories
Bangla PHP Screencast

Debugging & Profiling PHP Apps with xDebug – Bangla Screencast

Video is available in HD

Categories
PHP

Laravel 4 Development on PHPStorm

Laravel & PHPStorm – the best of the two worlds. Laravel is the most popular PHP web framework today. PHPStorm is the best PHP IDE that money can buy. What’s sad is that there is still no built in support for Laravel in PHPStorm. I created an issue on YouTrack (Jetbrain’s issue tracker) a long time ago which has received quite a good number of votes by today. I do hope Laravel support will come soon on the IDE. Meanwhile, there are workarounds to get things done smoothly.

Auto Completion

Thanks to the massive class aliasing (& use of Facade) in the framework core, PHPStorm can’t provide true autocompletion for Laravel by default. But there are excellent packages like Laravel IDE Helper which can generate phpdocs from the framework source. It generates a file which the IDE can parse and use the generated codes to provide autocompletion.

Installation and usage is simple. First modify your composer.json to include it in the require section:

Run composer update:

The package should be installed if everything goes right. Now, you need to make sure the package is loaded in Laravel (so that artisan can execute the commands it provides). Add this to the providers array under app/config.php – ‘Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider’. It should look like:

Now you can do this in command line:

The command should generate a file named “_ide_helper.php” with the necessary codes. You might want to recreate the code cache from “File” > “Invalidate Caches / Restart”. When the IDE restarts, you should get code completion for most of the Laravel code.

Blade Syntax

This one could be a bit tricky. But if you have installed Textmate bundles into Jetbrains IDEs, it’s actually simpler.

(1) Download the textmate bundle here – https://github.com/outofcontrol/Blade.tmbundle. If you download the zip, uncompress it to somewhere on your harddisk.

(2) From PHPStorm’s Settings window, go to TextMate Bundles. Add the bundle and apply the changes.

(3) Go to “File Types” settings. Select “File types supported via textmate bundles”. Add “*.blade.php” to that list. Apply the changes. Now try and open a blade file. It should work.

(4) Additionally, if there’s horrible color scheme on blade files, go back to “Settings” > “TextMate Bundles”, assign the color schemes to Darcula. (In my case, I switched all to Dracula under the “TextMate Color Scheme” column. If you click an item under that column, you should get a pop up to select.)

Now the blade syntax should work fine with nice color scheme.