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 (1) »

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 »

How to build a pretty Excel timesheet using Toggl API and Python

Since some months I’m using Toggl to track my work time, and I find it awesome! Toggl features a very powerful reporting system to have your timesheets filtered in many ways and exported in csv or pdf format, but I did not found the way to have an Excel timesheet as I like it.

But wait! Toggl features a very nice public API to access your time entries (and many more), so I wrote a simple Python script using the wonderful Requests and Xlsxwriter libraries.

Read the rest of this entry »

Comments (1) »

Django on windows: how to make Django run in CherryPy as a Windows service

Recently a client asked me to investigate the possibility to have a Django application hosted in a Windows environment. I looked around a bit and there are many ways to achieve this goal. I found the “pure Python” approach described here simpler to deploy and configure, yet very powerful and production ready for my needs.

I will explain how to install Python, CherryPy and Django on Windows, and how to configure them to serve a Django application from the CherryPy WSGI server, running as a Windows service. Read the rest of this entry »

Comments (2) »

Follow

Get every new post delivered to your Inbox.