snippets Articles



Convert a Mercurial repository to Git

As you may know Bitbucket is sunsetting Mercurial support, so this is a perfect time to understand how to convert a Mercurial repository to Git. Here I’ll show how to do it very quickly on Ubuntu 18.04.


A Django custom command to write model fields on an Excel file

Suppose you need to write down your model fields on an Excel file, for example to complement the documentation of your code. Django has built in functions to introspect models and fields of an app, and you can leverage this API to have the information you need. You can use …

Drop all tables in a database

Sometimes it can be useful to completely drop all tables in a database, for example to reset a DB to a previous version from a backup. After checking that you are doing this on the right database and that you know what you are doing, you can do this: SET …

Batch resize JPEG images with maximum resolution and size

Just discovered a quick and dirty way to resize a bunch of jpeg files to a maximum resolution and size: mogrify -resize 1024x1024 -strip -define jpeg:extent=200kb *.jpg This command will resize all jpg images in the current directory with a maximum resolution of 1024px for each side (maintaining …

A simple script to update a DB migration in Django 1.7+

During the development of a Django model on your local machine is it often necessary to refine the most recent migration to cope with updates to the model, without polluting the migrations of the app with a new migration for each local update. South had the update flag for the …

Why I love Python – Expressiveness

Here is one of those little things that make me love Python: d = {'a': (1,2), 'b': (3,4)} for k, (a, b) in d.items(): print k, a, b Prints: a 1 2 b 3 4 How cool is that? 😉

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!