Optimize Django memory usage

Recently I had a problem of memory usage in Django: when I accessed an apparently innocent view I saw the memory usage of my server grow without rest. The problem turned out to be very trivial to solve, but I think the process I used to find the leak is worth a blog post. ;)

Read the rest of this entry »

Leave a comment »

How to add a group choice combo box in a Django user profile form

Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both.

You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name, Email and the user group.

This task can be accomplished very easily! What you need is a customized ModelForm to add the possibility to edit the user group together with the other fields, and a customized UpdateView to let you set the form initial data for the group field, and to save the changes correctly.

Read the rest of this entry »

Leave a comment »

PUT and DELETE HTTP requests with Django and jQuery

Sometimes it could be useful and elegant to have a Django view responding to more that GET and POST requests, implementing a simple REST interface.

Read the rest of this entry »

Leave a comment »

How to turn your Raspberry PI in a Google Cloud Print device

Google Cloud Print (GCP) is a quite useful Google service, allowing you to print in a GCP compliant printer from everywhere and from every device of yours, be it a desktop, a tablet or a smartphone. There are quote a lot of printers out there supporting GCP out of the box, but here I will explain how to turn every Linux supported printer in a fully functional GCP printer. As a bonus you’ll have a cheap Linux based print server in your local network, which is alone a nice thing to have. All this thank to the amazing Raspberry PI ARM GNU/Linux mini PC.

Read the rest of this entry »

Leave a comment »

How to reset mysql root password on Ubuntu 12.04

Fast and easy!

$ sudo stop mysql
$ sudo -umysql mysqld_safe --skip-grant-tables &
$ mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;
$ sudo kill `cat /var/run/mysqld/mysqld.pid`
$ sudo start mysql

Enjoy your new mysql root password!

Leave a comment »

How to protect your Joomla instance from brute force attacks with Fail2ban

If you administer at least one Joomla instance you’ll be subject to brute force attacks before or after. Fail2ban is a very nice service written in Python which periodically scans your log files looking for signs of brute force attacks and perform some actions when an attack is discovered. The most common actions is to ban the attacker IP at firewall level and send an email to the server administrator.

Fail2ban comes bundled with filters for many common services (ssh, apache authentication, etc.), but it lacks a built-in Joomla integration. Anyway it’s easy to add a Joomla filter to Fail2ban, here I explain how to do it.

Read the rest of this entry »

Comments (4) »

Howto correct sitecopy bash autocompletion in Ubuntu 12.04

If you like me use sitecopy to easilly maintain remote websites over FTP, you also find annoying that bash autocompletion doesn’t work as expected in Ubuntu 12.04.

Say you have a website configured in your ~/.sitecopyrc named mywebsite. If you try to update it remotely, by issuing:

$ sitecopy -u myweb

and then pressing TAB expecting the word mywebsite to be autocompleted, you’ll see something like this in your terminal:

grep: Unmatched [ or [^

And no completion will occur.

To correct this wrong behavior you can edit the file /etc/bash_completion.d/sitecopy (you’ll need root access to the file to do that).

Find the line:

COMPREPLY=( $( compgen -W "$(command grep '^["$'\t '"]*site' \
~/.sitecopyrc | awk '{print $2}')" -- "$cur" ) )

And modify it like this

COMPREPLY=( $( compgen -W "$(command grep '^site' \
~/.sitecopyrc | awk '{print $2}')" -- "$cur" ) )

You’ll lose the possibility to have whitespace, tabs, etc before sites configuration in your ~/.sitecopyrc, but in my case this was not a real issue.

Please let me know if you found a more elegant solution to this issue. :)

Leave a comment »

Follow

Get every new post delivered to your Inbox.