Vim perl-support error: “Global template file ‘/usr/share/vim/vimfiles/perl-support/templates/Templates’ not readable”

Recently I’ve installed the perl-support plugin for vim.  However having installed as instructed I got the following error:

“Global template file ‘/usr/share/vim/vimfiles/perl-support/templates/Templates’ not readable”

As I don’t really want to mess with settings for everyone I pointed vim at the local version by added a line in .vimrc to set the global variable:

let g:Perl_GlobalTemplateFile=’/home/YOURLOGINNAME/.vim/perl-support/templates/Templates’

Note that ~/.vimrc didn’t seem to work for me.

Perl convert RGB to hex HTML color

Converting RGB to hex just involves understanding the decimal representation of RGB. See below for a small perl procedure.

sub RGB2Hex
{
my $r = shift;
my $g = shift;
my $b = shift;
my $dec = 0;

$dec += 256*256*$r;
$dec += 256*$g;
$dec += $b;

return sprintf(“%.6x”, $dec);
}

Remove ^M with vi AKA bad interpreter: No such file or directory

Got a script with ^M at the end of each line because the file came from a dos machine?  With perl you’ll get something like:

/usr/bin/perl^M: bad interpreter: No such file or directory

First of all open this file in vi in binary mode:

vi -b yourscipt.file

Then after typing colon type the following:

%s/^M//g

NOTE. To get the ^M do NOT use ^ and M.  Use control+V then immediately control+M.

Then [enter].  Then to save and exit:

:wq [enter]

Job done!

MySQL [lack of] performance

I certainly don’t profess to be a MySQL performance tuning expert. What I am is a long-time MySQL lack of performance sufferer. In fact, writing this I’m in the process of waiting for several table deletes and MySQL WorkBench has frozen (again).

Anyway, here’s some thoughts:

  1. If you have heavy writes bear in mind this severely affects locking for MyISAM tables.  One thing that sucks with MySQL table engines is you trade off performance (MyISAM) against granular locking (InnoDB).
  2. Try to avoid tables getting too large to manage.  If you’re storing historical data write an archive / cull script early on to keep the database manageable.
  3. Use SHOW PROCESSLIST to see what’s running if you’re experiencing problems.  Processes marked ‘locked’ or ‘freeing items’ are bad.
  4. If you get into trouble and need to delete all the rows in a table, use TRUNCATE TABLE [tblname] rather than DELETE FROM.  This is significantly quicker.  (Thanks Rainer for that one.)
  5. Most obviously – use indexes judiciously.  Adding indexes slows down insert speed to allow better retrieval rate.  If the tables are too index heavy the insert speed will slow down such that it causes more locking.