How to add a Password reset link on user login block in Drupal

In Drupal 7, adding a link to allow users to reset their password (a “forgot my password” link) is quite easy through the hook_form_alter() hook.

 * implements hook_form_alter().
function mythemename_form_alter(&$form, &$form_state, $form_id)
    case 'user_login':
    case 'user_login_block':
      $form['links'] = array(
        array('#markup' => 'Forgot your password?'),
        '#weight' => 100,

CSS3 box-shadow on left and right sides only

It is possible to have inset shadows on both left and right sides of a block. It is a matter of showing only one side of the box-shadow at a time, and so you need two box-shadows (one for each side of the block you wish to have shadows, and we can put both CSS codes in the same property).

Here is an example that should be compatible with Firefox, Chrome and Opera.

box {
        inset 5px 0 5px -5px #333,
        inset -5px 0 5px -5px #333;
        inset 5px 0 5px -5px #333,
        inset -5px 0 5px -5px #333;
        inset 5px 0 5px -5px #333,
        inset -5px 0 5px -5px #333;

Here is the result:

Lorem ipsum…

Inspired from Playing with CSS3 box shadow []

How to optimize all tables from all databases

The following command will optimize all of your databases’ tables within MySQL.
It is important to optimize tables to reduce data fragmentation.

mysqlcheck -Aop -uroot

If you are not using root replace it with your username.

-A : Check all tables in all databases. This is the same as using the –databases option and naming all the databases on the command line.
-o : optimize the tables.
-p : Prompts for a password to use when connecting to the MySQL server.
-u : The MySQL user name to use when connecting to the server.

Inspired by this article.

Putty and tree – how to avoid weird characters (squares)

Character encoding is always a problem when communicating between Windows and Linux. And using the “tree” command is affected by this problem if you are connected to a Linux box using Putty on a Windows box. You will certainly get weird characters, probably squares.

For those who are not sure about what tree is. It is a command-line tool to list contents of directories in a tree-like format.

A solution to this problem is to force using plain ASCII characters:

tree --charset=ASCII

You can also have an alias for this command, so that every time you type “tree“, it will force tree to use the ASCII charset automatically.

alias tree='tree --charset=ASCII'

And this is an example of what you will get as an output:

|-- claws-mail-1000
|-- keyring-x803mg
|   |-- control
|   |-- pkcs11
|   `-- ssh
|-- orbit-gdm [error opening dir]
`-- virtual-user

How to work around “prerequisite RT 0 not found” on Ubuntu

You installed Request Tracker 3.8 on Ubuntu 10.04 using apt-get, aptitude, or synaptic, and then you needed RT::Authen::ExternalAuth.

What you naturally did is:

sudo cpan -i RT::Authen::ExternalAuth

But you will get the following error:

prerequisite RT 0 not found

This is because you did not install request-tracker through CPAN.

An easy solution for this is to force the installation using the “-f” flag:

sudo cpan -fi RT::Authen::ExternalAuth

How to backup MySQL users except root on Ubuntu

When you want to backup your mysql databases, you usually do mysqldump … –all-databases or mysqldump … –databases mysql … but you end up with the whole mysql table which is a pain to insert back when you need it because it can mess up the root password or the debian-sys-maint user…

If you wish to just backup all the users and privileges other than root and debian-sys-maint, you can use this command:

mysqldump -nt -uroot -p -w"User NOT LIKE 'root' AND User NOT LIKE 'debian%'" mysql user db > users_privs.sql

Here’s an explanation of each of the options:

  • -nt: Do not add “drop table” and “create table”.
  • -uroot -p: Connect as root and ask for a password
  • -w…: Add a “WHERE” condition to each query. We exclude everything related to root and debian-sys-maint.
  • mysql user db: Dump the user and db tables from the mysql database.
  • > users_privs.sql: Store the sql dump into the users_privs.sql file.

diff and ignoring spaces and end of lines (unix, dos EOL)

Possibly you will need to either do a diff between files where they don’t use the same new line character.

Because the new line character is OS-dependant, there are issues when doing a diff on these files when you are not using that same OS.
And there are also times where you just want diff to ignore all spaces and new lines…

The –ignore-all-space option for diff is really useful in these two cases. It will check for differences between the given files ignoring spaces or new lines whether there is none, one or more

Continue reading “diff and ignoring spaces and end of lines (unix, dos EOL)”

[Ubuntu] Spell-check from command-line using hunspell

If you are a developer or simply a command-line geek/fan, there are times where you type some documents using the command line, like for README’s or for documentation. It is also important to have a very good writing in English if you wish to distribute those files.

Hunspell can help you with spell-checking. It is based on MySpell and contains a nice terminal interface to spell-check your files.
Continue reading “[Ubuntu] Spell-check from command-line using hunspell”

scanerrlog – Generate summaries/reports from Apache error logs

scanerrlog offers the possibility to generate a summary or report about Apache errors and sort them depending on how frequent they are.

To install it (for Ubuntu users):

sudo apt-get install scanerrlog

or use Synaptic and search for scanerrlog.

It’s written in Python, and it is very easy to use it. (type ‘man scanerrlog‘ in a terminal to see the manual page)

I tested it with Apache2 log files using the following command:

scanerrlog -f text -o /tmp/log.txt /var/log/apache2/*.log
  • -f : format (text, pdf, html, xml)
  • -o : output file
  • args : log files

Continue reading “scanerrlog – Generate summaries/reports from Apache error logs”