how to setup pinax with nginx

Tonight I spent sometime getting PinaxDjango swiss army knife – to work on nginx via fastcgi on my Ubuntu 9.10 box. Here is a step by step guide.

First of course we need to install nginx, pretty easy with Ubuntu:

sudo apt-get install nginx

Create a new file called <appname> in /etc/nginx/sites-available/ like the following:

upstream djangoserv {
    server 127.0.0.1:8801;
}

server {
    listen   80;
    server_name  alkemic;

    access_log  /var/log/nginx/appname.access.log;

    location ^~ /site_media/  {
        alias /home/nick/dev/projects/pinax07/appname/site_media/;
        autoindex on;
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)   {
        #access_log   off;
        expires      30d;
    }

    location / {
        # host and port to fastcgi server
        fastcgi_pass 127.0.0.1:8801;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
    }
}

Link it to sites-enabled so that we know it’s going to be started up (meanwhile you want to remove the default one):

sudo ln -s /etc/nginx/sites-available/appname /etc/nginx/sites-enabled/

Startup nginx with:

sudo /etc/init.d/nginx start

Activate your pinax installation (change the path to where you have installed your Pinax virtual environment):

source /home/nick/dev/projects/pinax07/bin/activate

Install flup (required to have manage.py run as fastcgi) in your virtual env:

pip install flup

Symlink all the static assets into the site_media folder:

css -> /home/nick/dev/projects/pinax07/appname/media/css/
img -> /home/nick/dev/projects/pinax07/appname/media/img
js -> /home/nick/dev/projects/pinax07/appname/media/js
pinax -> ../../lib/python2.6/site-packages/pinax/media/default/pinax/
snd -> /home/nick/dev/projects/pinax07/appname/media/snd
swf -> /home/nick/dev/projects/pinax07/appname/media/swf

Launch the python fastcgi process:

python ./manage.py runfcgi method=threaded host=127.0.0.1 port=8801

Or:

python ./manage.py runfcgi method=prefork host=127.0.0.1 port=8801

Note that you might need to move your development environment to use a proper db like MySQL because otherwise the app will have problems finding your sqlite db file.

You should have now your app running on the blazing fast nginx.

how many times did I listen to this?

I love staring at branches and shuffle, reorder and squash commits

I don’t know what it is. Maybe it’s inherent to human nature to strive for and to create order. Maybe it’s just me.

But I love staring at branches and I love cleaning up my commit history until it shines. This is of course possible and encouraged with git and it’s only possible if you haven’t shared your code with anyone else publicly (pushed to a shared remote repository). So how does a shuffling cleaning frenzy look like? Here: (The screen-shot below is from GitX just for eye candy).

staring at branches

How do I work? Before I share my work with other developers I commit stuff to local branches furiously and in very small increments, I branch away like crazy. Then after a while I realize things are messy and commits are not elegantly divided per feature. So I stop coding and start cleaning the history of commits until they fit into a clean list of recognizable units of work. At that point I can merge the work back into the mainline, say the master branch or some shared topic branch.

Tools of the trade ? git branch, git reset, git cherry-pick and the very powerful git commit –interactive.

If you’re wondering why I like git and why I don’t use x (where x could be svn, hg, bzr or perforce) a good collection of reasons can be found at Why Git is Better Than X .

link dump from a conversation: entrepreneurs, social media, cool products, random awesomeness

Every once in a while I have wonderful conversations about life, technology and everything. Many times I end up talking about a myriad of topics. For example today I had lunch with Jonathan Greenwood (you should follow him on twitter here) and learned a great deal about many interesting things. I am always intrigued and delighted to rediscover that not everyone has my same brain, interests, browsing habits. Not everyone keeps track closely of the same spaces and same people I do.

So here is a random mesh of interesting links that I recurrently mention in my conversations, the common thread being – well it’s quite a broad one I’ll admit – entrepreneurship, social media, cool people and products, online videos, friends. You might have seen some of these already, but then again, maybe not.

Seedcamp

Seedcamp is a Micro seed fund that invests in start-up companies. I want to participate in the August selection round with my friend nocivus.

Vibram 5 fingers

The product site

Tim Ferris review

Gary Vaynerchuk inspiring videos

“The” online wine guy and entrepreneur Gary Vaynerchuk, pioneer of video blogging is quite a personality. Totally love him:

  • His video blog on wine is here
  • Personally I liked this of his keynotes. All his other keynotes here.

The story of Parrot Secrets

The story of Parrot Secrets, fascinating recount about a very simple (though controversial) e-book business.

Sorapot, a cool teapot

Sorapot, the teapot developed by a young designer and manufactured in China. Good video interview by Kevin Rose from digg.

Paul Graham essays

Really insightful essays about startups and innovation.

This is one of the first I read and it made a deep impression on me, years ago.

Tim Ferris on improving your blog

Video of Tim Ferris giving advice on improving your blog, very practical and analytical as always.

Diggnation

Kevin Rose’s video show about popular news stories on digg.

Two guys and a beer

Pedro picked up video blogging. Non politically correct, alcohol consumption, cursing. Promising!

Geeky and Entrepreneur news sources that I visit daily

http://news.ycombinator.com

http://programming.reddit.com

Equalway

Mirko Calvaresi’s site about grassroots italian buying groups – in Italian.

By the way

You should follow me on twitter here.

*lol*

Wow that’s a few links and videos. Enjoy and take your time.  I’ll be delighted if you want to chat about any of the above or if you found anything interesting.

And if you are any of the people mentioned above and are reading this, you rock and are an inspiration for me.

how to integrate compass into your default pinax project

Lately I’ve been really impressed and experimented joyfully with
Compass and Sass. They make css/layout design fun again for me. Even if the whole tool chain is in Ruby you don’t have to touch any Ruby to use them – don’t misunderstand me: I like Ruby and I’ve been a Rails early adopter; my brain is very well tuned in with Python, that’s all -.

Compass makes the creation of a semantic layout using any of the
popular css frameworks (blueprint, 960, etc.) a breeze.

There’s ton of documentation around, for example this is what got me into it a while ago.

So today after a furious coding spree I achieved what I wanted. I integrated Compass into a default Pinax project.

To prove that I could quickly change the layout in an elegant way I tried to alter the default theme to have the menus vertically aligned instead than horizontally.

I know people love pretty pictures and screenshots so here is a taste of the end result:

default theme of pinax with vertical menus

And another one:

vertical menu in pinax theme

And if you find any of this interesting be my guest and peruse the newly created github project:

  • The master just plugs in Compass without changing anything in the default theme. You can alter the layout by working in the media/sass folder and running compass -u in the media folder.
  • The vertical branch includes the changes needed to come up with the vertical menu you see above. By looking into the media/sass/base.sass file you should see how to use Compass directives to include a 960 grid into Pinax.

Please note, this is nothing fancy nor hard, but I expect this integration to be a life/time saver in all my next projects.

my desktop during an intense coding session using xmonad

Here is what a coding session of mine looks like when I am in full swing. This is specifically the coding screen. That’s a 1920×1600 resolution screen-shot :D . I obviously also have a browsing screen not shown.

coding session using xmonad

In the image above I am immersed into integrating Compass into Pinax (full post on that will follow).

When developing under Linux (Ubuntu 9.04 at the moment) I have settled for a long time now on the ultra-productive tiling window manager Xmonad. Nothing I tried beats it. My fingers and my brain now are one with the keyboard short-cuts and the concept of mouse-less zen.

Yes I use vim extensively and yes I use screen with the new ubuntu screen-profiles. It rocks.

vim mind share soaring: roundup of 10 vim articles, recent and older gems

Am I the only one to notice that there is a lot of vim love in the airwaves recently?

I saw the trend very clearly, spanning from reddit to news.yc and let me say that the material that came up recently is very good; those neat posts prompted me to improve my vimrc dramatically and I really like what I learned.

In this installment, instead than annotating my vimrc (another one? not that interesting, I’ll refrain) , I want to compile a roundup of the best vim articles I saw recently.

I’ll also add a few classics that changed me from a hater to a vim lover and will conclude with some minor tips out of my bag.

So here we go with the roundup.

Recent Vim Articles Roundup

Jamis Buck

Vim Follow Up

Coming Home To Vim

Jamis Buck switches back to vim from a period using TextMate and talks about his experience and his configuration. Many useful tips in there.

Stephen Bach

Configuring Vim Right

Sensible defaults for your vimrc, recommended.

Learnr dev blog

Configuring Vim Some More

Some additional configuration options that totally make sense and I incorporated in my config too.

Swaroop C H

A byte of vim

A new free e-book on vim, worth reading. Covers also advanced topics like writing your own plug-ins.

Effective Vim

This ends the recent vim trend spotting. But there are some older links that are worth sharing in my opinion.

Older Vim Gems

Jonathan McPherson

Efficient Editing With Vim

This is a true gem, an intermediate level tutorial that will convert you from a beginner vim user to a way more proficient one.

Jerry Wang

vi for smarties

Very good beginners guide to vim.

David Rayner

best of vim tips

Raw tips from a very long time vi/vim user

Vim is also great for Python development, 3 ideas…

vim omnicomplete awesomeness

How to make vim a modular Python IDE

How to replicate SLIME in vim

Finally a few tips from myself

vimperator: If you’re a heavy vim user you might want to checkout the great Firefox extension vimperator. You’ll find yourself browsing mouse-less with familiar vim keystrokes in a matter of minutes. I love it.

viPlugin for Eclipse: If you’re a Java developer (been there, done that) and you’re stuck with Eclipse, you definitely want to have viPlugin. It makes the Eclipse experience something much more pleasurable for one who has vi keystrokes embedded in the fingers.

cool color scheme: If you’ve seen “some” screen-casts and you have just a subterranean TextMate envy and you can’t stop thinking at that cool color-scheme, well think no more, you can use this one or my humbly tweaked version.

For delicious users here is the page of my bookmarks that made me notice the trend.

Ending note

For full disclosure I have to say that I have been – and still am sometimes – an Emacs user. One of the rebel ones daring enough to use Viper mode. So now you know.

idea for a useful tool for a web entrepreneur/developer

This is the scenario I was thinking about: I want to interact with a graphic designer remotely, who is very very good with Photoshop and HTML/CSS but who might have trouble setting up the Linux environment needed to run my web app.

What I would like to build (or find if it already exists) is a custom CD that when inserted into a Windows or Mac OSX box does the following:

  • Start a virtualbox/vmware instance with my Linux distribution of choice.
  • Inside the virtual machine the web app is started automatically in debug mode.
  • Proper networking is in place so that the web app is accessible to the host operating system on a specified port.
  • The template/media folder of my web app is shared via SMB with the host OS.

This way the graphic designer could work on the templates/design of the application having (almost) zero knowledge of the technology behind and no access to the code.

I have already developed a solution like this for myself using colinux. But the process required quite some fiddling and was all but automatic. :D

Automated is the keyword.

That’s it.

testing out tuttivisti widgets

One of the first things I implemented for tuttivisti – to add just a hint of viral marketing to the project – was a widget that you can import on your own blog, maybe on the sidebar, to show the latest movies you either want to see or just watched. Let me test it here for you (and for me :D ):

How does it work? Just go to the goodies page (well login first) select how many columns and how many movies you want to show, click preview, copy the short Javascript snippet into your blog, website, myspace,etc. and you’re done.

I don’t think anybody is using this yet, but it’s understandable, tuttivisti has only a little above 100 users at the moment, most of whom never came back.

We’ll see if adding the next level of viral-ity will improve things: think posting your movies to twitter, pwnce, plurk, friendfeed, facebook, etc… :D . I’ll try. I think I’ll start from twitter this week. Pinax supports it out of the box (together with openmicroblogging which is way cool).

a webapp in 1 week (part 2): the source of data

In the first installment of this series I’ve spoken about a set of technologies that can speed up the time to market quite a bit. Read about it here if you missed it.

This time I want to talk about where to get the content for your niche web app – if you need a source of content, that is.

Leverage the Semantic Web

I apologize if you all know it and I am late to the news. But really, the semantic web is alive and here and I think one of its most promising incarnations is Freebase.

What is Freebase?

Take the whole of Wikipedia, in it’s unstructured – well I should say semi-structured – mass of data, structure it properly creating schemas on schemas of semantic relations amongst articles, and expose a clean API on top of it. Keep the openness part, allow anyone to create new domains (called bases) and to contribute structured content by hand or programmatically. That is freebase as I understand it.  Beautiful.

How did I use it

So the secret is out, that’s exactly what I used to present cool thumbnails and basic movie data for my tiny tuttivisti – now at the second week of life (check it out by the way, the new release is out).

Let me go into deeper depth here because I realize the audience requires it.

The Freebase folks have extensive documentation on how to interact with their service. In addition to that they publish two very nice Python libraries, freebase-suggest and freebase-python. The first to add a cool, jquery based autocompletion dropdown to your forms, the second to query Freebase programmatically from a Python program.

freebase-suggest example

Using the freebase-suggest library is very easy. To achieve this:

I just had to add this jquery snippet to the bottom of the page:

<script type="text/javascript">
var options = {
soft: false,
ac_param: {
type: '/film/film',
category: 'instance',
disamb: '1',
limit: '10'
}
};

$('#searchbox')
.freebaseSuggest(options)
.bind('fb-select', function(e, data) {
$('#searchbox').val(data.name);
$('#freebase_id').val(data.id);
$('#freebase_image_id').val(data.image.id);
$('#search_movie_form').submit();
return false;
});
</script>

And mark the text input of the search with id=”searchbox”.

The freebase-python library is also very easy to use and I encourage you to take a look at the documentation, here.

So in conclusion, before your app gains traction and your content is produced by your users, leverage the Semantic Web if you can, use freebase!