Create unique username before user_save

When using user_save to create new user, you want to have username unique, if you are importing data or just want to be safe that someone hasn't have chosen username you already have in DB (and not to get nasty error PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry...). Here is some nice code to run on that username variable before saving an object.

Krumo/Devel output in watchdog

If you want to have Krumo/Devel style output in watchdog, just do this.

watchdog('debug',kprint_r($var, TRUE, NULL));

$_SERVER['HTTPS']='on' on reverse proxies - nginx and SSL

When using nginx and SSL and you have a problem that CSS or JS files are using HTTP in their urls and everything else is in HTTPS. The thing you need to do is use this magic

$_SERVER['HTTPS']='on';

put it in settings.php and also if you have wordpress, do the same, put it in wp-config.php it will do the same and solve the same problem.

Attaching Extra or Pseudo Fields to any Entity in Drupal

This thing is so cool and only recently I found about it. You can create pseudo fields with your entites, most often content types. So you can make some add, edit, delete buttons or any kind of forms on your entites or nodes. And it is pretty quick and straight fwd solution.

Update and insert only specific fields of your entity

TO not need to use hook_entity_presave and save whole entity try this

//Get the id of your field
$field_name = 'name_of_your_field';
$info = field_info_field($field_name);
$fields = array($info['id']);

//Execute the storage function
field_sql_storage_field_storage_write($entity_type, $entity, 'update', $fields);

Running mysql on mamp localy

If you have more then one mysql installed on your computer and in your path is not proper MYSQL, you should run

?/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

Can't find a string to translate in drupal

This is kind of odd solution as it will confuse people.

"The t() function, to save on performance for single-language sites, won't store the string in the database until it is requested from another language. View the page in one of the non-default languages in order to populate the database (t() calls locale() to do this), thus making the string available for translation."

Enable errors and logging with drush or with settings.php

You have error, your site is not accessable and you need to see what is the problem but logging and errors are set to none.
Type this with drush

drush vset error_level x

Where x is 0/1/2, depending on what you want

0: none
1: errors and warnings
2: all

You can also do the same with settings.php, adding to it this