Christian Mayne


Simple MySQL Command line DB dump for cron

If it doesn't already exists, create the file .my.cnf in your home directory. Add the following to it, replacing db_username and db_password with the database username and password. make sure the file permissions are set to 600 (chmod 600 .my.cnf) so it is readable by you alone. [mysqldump] user=db_username password=db_password The following command will dump the database db_name to the db_backups directory with the filename yyyymmdd.sql where yyyy is the current year, mm is the ...

Location of Gnucash Invoice Template on Ubuntu

This is one of those things that drives me mad, that I can never find in the documentation. I'm currently running Gnucash 2.4.11 on Mint 14 (based on Ubuntu) and sometimes need to edit the invoice template. I can never find where the damn thing is. Currently, it's here (along with other templates): /usr/share/gnucash/guile-modules/gnucash/report/invoice.scm

Enabling mod_rewrite on Apache

This is one of those things I often forget to do when setting up Wordpress on a new server, which means pretty permalinks don't work: If you have a problem with permalinks not working on Wordpress, it may be because Apache does not have mod_rewrite enabled. An easy way to check is to make a simple php script, saved in the root directory of your webserver as info.php (or whatever takes your fancy): <?php phpinfo(); ?> This will give you an output of all the various modules and ...

Restart Apache Webserver

To Restart Apache on Ubuntu or Mint (and possibly more): $ sudo service apache2 restart

Get the last rows updated in a database

When debugging applications, it can be useful to see what's going on in the database without referring to the code. In MySQL, you can use the information_schema database to get this information. here's what I do: Select table_name, table_rows, update_time from tables where table_schema = "[database_name]" order by update_time desc

Spliting strings with awk / nawk

I mainly use nawk to extract elements from a string where I know the position (eg to get just the filenames when running a grep and I'm just too lazy to remember the correct grep syntax). so, to extract field number x from strings in where the field separator (FS) is y: $ nawk '{ FS="y"; print $x }'

Checking for a valid domainname

Very quick function to test a domain name is valid:     function validDomain($domain)     {         // Test domain is actually valid         if (preg_match('/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/i', $domain))         {             return TRUE;         }         return FALSE;     } The key here is the regular expression (delimited by the forward slashes at each end): /^[a-z]+([a-z0-9-]*[a-z0-9]+)?(.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/ This basically translates ...