/web/development

 

Airy: Sample app

Published:

This is a short post, I wanted to show how to start an Airy project, and add a sample application.

Small intro to Airy, it’s a stack of frameworks and technologies for rapid web development. We’ve started it because there are times when we need some project up and running in less than a day. It uses Tornado web server, Tornadio2 for websockets implementation, mongoDB as a backend, and jQuery and Twitter Bootstrap for the frontend.

One more thing, by default Airy creates only one connection once user opens the url, and then passes all the information and rendered layouts via websockets. This allows creating async live applications, quite handy in web 2.0 world. So, let’s start.

You’ll need nix environment (Mac will work too), mongoDB, Python 2.7+, Virtualenv.

I’ll use ubuntu 12.04, desktop edition, x64, you can use virtual box if you are on windows. Bear in mind that mongoDB has a limit of 2GB storage on 32bit systems.

To install all the tools available:

sudo apt-get instlal python-dev python-setuptools mongodb vim
sudo easy_install virtualenv 
sudo easy_install airy

cd /home/username

airy-admin.py startproject airy-sample
cd airy-sample
python manage.py update_ve
airy-admin.py startapp sample
cd sample
vim handlers.py

add following code:

class SampleHandler(AiryHandler):
    def get(self):
        #do some login here
        variable = ‘assign variable’
        self.render(‘#content’, ‘sample/index.html’, variable=variable)

edit urls.py, add following line to urls list:

(r”/sample”, SampleHandler),

Then add new application to the project

cd ..
vim settings.py

add following line to installed_apps list:

‘sample’,

save, and create “sample” directory in templates folder:

mkdir templates/sample

add following to ./templates/sample/index.html :

<h1>Our sample app</h1>
<div>{{ variable }}</div> 

save it, start mongodb (service mongodb start), and run the server:

python manage.py run 0.0.0.0:8000

That’s it, you should see the result on http://localhost:8000/sample if you are running it locally.

I’ll add more posts with snippets we use at the moment, but note that Airy is still very-very-very fresh, and the direction might change. We will add roadmap of the development soon. 

The code is available on this github repo.

If you feel that Airy is something you are interested in, you can always contribute, Airy repository is on github. 

We are open to any suggestions, or if you have any comments just let us know.

P.S. We are hiring both full time and interns ;) Python developers, and PHP or Ruby developers who want to switch to Python.

P.P.S. If you don’t know how to exit vim press escape few times, type :wq and press enter ;)

It’s been a while…

Published:

Can’t even remember when was the last time I posted something on tumblr. Well, here it goes. 

Lots of stuff changed since. I cofounded a company called LetoLab, and we are lean development agency. We build web and mobile applications and apply lean principles in development, i.e. launch as soon as possible, and pivot.

There will be slight change of the direction of this microblog, I won’t focus much on actual development, but more on management, R&D, and on our internal tools. 

Also, we’ve launched our own framework called Airy, it’s a stack of frameworks and technologies for rapid prototyping. It uses Tornado web server, Tornadio2 for websockets implementation, mongodb for backend, and jQuery and Twitter Bootstrap for frontend (it’s Foundation CSS in PIP, but we’ve migrated code to Bootstrap in master).

Symfony2. “Label ‘not_fos_user_profile_show’ already defined”

Published:

If you get following error when running PHPUnit:

PHP Fatal error:  Label 'not_fos_user_profile_show' already defined in /Users/gera/WebDevelopment/ProjectName/app/cache/test/apptestUrlMatcher.php on line 287

Check your routers configuration, you might have the same route defined twice.

Symfony2. Using Nginx environment variables.

Published:

There are two parts: 

  1. Setting the variable
  2. Accessing the variable

Let’s look at the simplest example - setting up Symfon2 environment variable (I have 3 different possible environments: dev, stage (for staging server), prod (for live site).

When you are passing php scripts to fastcgi, in the same block add:

fastcgi_param    SYMFONY__ENV    stage

So the whole block looks something like that:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   app.php;
    fastcgi_param   SYMFONY__ENV    stage;
    include         /etc/nginx/fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME /var/sites/ProjectName/staging/project/web$fastcgi_script_name;
}

And finally, in web/app.php replace

$kernel = new AppKernel('prod', false);

with:

$kernel = new AppKernel((getenv('SYMFONY__ENV')?getenv('SYMFONY__ENV'):'prod'), true);

So even if the Nginx variable is not set it falls back to ‘prod’ environment.

Nginx documentation on fastcgi_params.