abidibo.net

Weblog

Deploy django applications with nginx, uwsgi, virtualenv, south, git and fabric, part 1

deploy django nginx programming virtualenv

After googling for a while, asking my guru and some tests I was able to setup a deploy environment for django projects.

The web server is nginx, the database server mysql, I use uwsgi as wsgi server, all the code is versioned using git, the python libraries are installed in a virtualenv, db migration is assured by South and the deploy is automated using fabric.

While writing this post the whole environment is working but I think it may be adjusted in some ways, so let's take what follows as a guideline to improve in many aspects.

I assume we are working in locale and deploying directly to a production server, ignoring the staging phase.

Installing some packages (locale and remote)

To set up the environment we need python >= 2.6, python-dev, python-setuptools, pip and virtualenv, so (in a debian/ubuntu os):

$ sudo apt-get install python python-dev python-setuptools
$ sudo easy_install pip
$ pip install virtualenv

Ok that's all, the other python packages will be installed in the virtualenv, so now let's continue installing git and mysql

$ sudo apt-get install git ...

read the full post


Private static and instance members in mootools classes

javascript mootools patterns programming

Let's see two patterns that may be used to have private members in mootools classes.

Private static members

Here is quite simple, it's enough to use a single execution function and js closures and provide the setter and getter methods to change and retrieve the member's values.

var myclass = (function() {
  var _name = null,
      _age = null;
  return new Class({
    initialize: function() {
      // do some stuffs
    },
    setName: function(name) {
      // do some checks here
      _name = name;
    },
    setAge: function(age) {
      // do some checks here
      _age = age.toInt();
    },
    getName: function() {
      return _name;
    },
    getAge: function() {
      return _age;
    }
  });
}());
var myinstance = new myclass();
console.log(myinstance.name); // undefined
myinstance.setName('jack');
console.log(myinstance.name); // undefined
console.log(myinstance.getName()); // jack

So what happens here is that the two variables

_name and _age

are in the scope of the single execution function, and so not accessible from outside. But their value is retained by the returned object which yes can access them since it is ...

read the full post


The importance of semantics in html documents

html5 semantics webmaster

Wow, the first post of the last year of the world...

In the last weeks I've discovered the importance of the semantics rules applied to the web documents (well, really I knew it before, but I had never given it the importance it has).
The html5 specification introduces some new interesting html elements which plays a leading rule in this sense. Here I speak about some of them since many and many articles may tell you the same story and probably in a better way, look at this for example.

With the older html4 and XHTML the semantic structure of the page was determined essentially by the title tag in the head of the document and by all the h1..h6 tags in the body, which all represents an headline in a descendant order. In particular if you wanted to have a semantic structure with only one external root element you had to use only one h1 element. Then you had to use the others (in descendant order) to create semantics subsections.

The html5 specification introduces some semantic elements which may be used to create more complex semantic structures, and solve some situations that couldn't be managed earlier ...

read the full post


Vim for php programmers

php programming vim

Il succo è questo:
ho scritto due post sul blog della otto (la tanto cara azienda in cui lavoro), in cui illustro come si possa fare per rendere vim un editor perfetto per sviluppare codice php. Allora siccome sarebbe inutile ripetere qui le stesse cose e soprattutto non ne ho voglia, vi linko semplicemente i due post in questione, buona lettura.

Vim for php programmers parte 1

Vim for php programmers parte 2


jeff-flatpages, html page module for jeff framework

jeff php programming webmaster

jeff-flatpage is a jeff module that lets you store simple "flat" HTML content in a database and handles the management for you via jeff’s admin interface. It is the right module to use for the creation of "About" or "Privacy Policy" type pages, which don't need a specific module and implementation.

So it's ready! The first jeff module for the management of HTML contents is available for the download in the otto github account, release v1.0.

Let's see the main features:

  • Management of html pages (date, title, subtitle abstract, text, images, videos, visualization privileges)
  • Visualization through customizable templates
  • Translations availables for english and italian
  • Error pages 404 (not found) and 403 (forbidden)
  • Possibility to restrict the access to contents to a set of chosen system groups.

Please for complete instructions about the module installation refer to the README file of the github repository.

Please comment here for general considerations, use the proper github area for bug reporting.

Enjoy it ;)


Development of undo and redo functionality with canvas

canvas html5 javascript mootools webmaster

Sometimes I like playing with html5 and javascript. Today I was playing around with a sort of paint project for mootools. Clearly I used the html5 canvas element and I wrote some tools (pencil, rectangle, ...) to draw in it.

Well, one of the first problems encountered is the need for a undo/redo functionality. Let's see a way to implement such thing.

Essentially when drawing we can imagine we pass through a series of different states. Each state represents the canvas aspect at that time. Clearly we have a continuous set of states, but it would be to "expensive" to consider and implement this way.

So we may consider a discrete set of states, where a new state is created consequentially to a user action (and not time dependent). Let's consider the creation of a new state consequent to a mousedown-mouseup action of the user, in other words a new state is created when the user draws something in one move.

Now imagine to consider three categories: past, present and future.

The present category includes only the present ...

read the full post


Welcome mooTree

javascript mooTree mootools plugin webmaster

E' online la release 0.1 di mooTree, un plugin javascript che inserisce automaticamente i controlli per espandere/comprimere i rami di un albero infinito rappresentato tramite una lista html non ordinata (ul tag).

I controlli possono essere facilmente personalizzati con poche righe di css. Il behavior iniziale, ovvero quali rami espandere/collassare inizialmente è controllabile tramite opzioni di classe, data-attributes e classi css (per l'item selezionato).

Per saperne di più vi invito a leggere la pagina del progetto, per capire subito meglio di cosa si tratta, visitate la pagina demo.



Change the user agent in android default browser

android tips

Se anche a voi sta sul cazzo il fatto che molti siti che dispongono di una versione mobile la rendano "limitata" e soprattutto rendano disponibili a pagamento la maggior parte dei contenuti che sono gratuiti  per la versione desktop, allora potrà tornarvi utile questa semplice procedura.

Il dispositivo mobile viene "intercettato" andando a leggere lo user agent fornito dal browser, pertanto non ci resta che modificarlo in modo da fingere di essere un browser classico che gira su sistema operativo "tipo desktop".

Ecco come fare:

  1. aprite il browser
  2. Nella barra degli indirizzi digitate about:useragent
  3. Si aprirà una view con scelta multipla, potete selezionare lo user agent che intendete impostare, in questo caso "desktop"
  4. Andate a leggervi la gazzetta o la repubblica senza pagare una mazza

Jeff Tutorial - Installazione

jeff php tutorial

In questo tutorial vediamo come installare Jeff e creare un ambiente vergine pronto per aiutarci nello sviluppo di una qualunque applicazione.
Qui suppongo che si lavori in ambiente LAMP, ma con altre configurazioni non è che le cose siano molto diverse.

Scarichiamo Jeff

Per scaricare Jeff possiamo visitare la pagina https://github.com/otto-torino/jeff e premere il pulsante download (sono disponibili 2 formati: tar.gz e zip), oppure utilizzare il comando git:

git clone git://github.com/otto-torino/jeff.git ./jeff

A questo punto ci ritroveremo con la cartella jeff che include tutto il codice necessario. Mettiamo la cartella all'interno della document root, tipo

/var/www/jeff

e passiamo alla creazione del database...

Creiamo un db

All'interno della cartella principale troviamo il file jeff.sql, il quale contiene le istruzioni SQL per creare le tabelle di cui Jeff ha bisogno nella sua configurazione base. Allora dobbiamo:

  • Creare un database, ad esempio db_jeff
  • Creare un utente che possa eseguire statements sul database creato, in fase di sviluppo ed in locale solitamente questo non si fa e si utilizza l'utente root senza password
  • Eseguire tutte le query contenute nel file jeff.sql per creare le tabelle, questo si ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured