Tuesday, August 28, 2007

Perl scalar assignment

The difference between:


my $var = EXPRESSION;


and


my ($var) = EXPRESSION;


is in whether EXPRESSION returns an array...

Of course in list context an array produces a list of the items in the array, but in scalar context it produces the number of items in the array...

By putting the parentheses around the scalar you are populating an array, and $var is asking for the first element of EXPRESSION if it returns a list, so:


#!/usr/bin/perl

use warnings;
use strict;

my @array = ('a', 'b', 'c');

my $var1 = @array;

my ($var2) = @array;

print "var1: [$var1]\nvar2: [$var2]\n";


returns:


var1: [3]
var2: [a]


Thus if your expression unexpectedly returns an array you at least get some useful value rather than a mysterious number. :-)

Thursday, August 23, 2007

Dumping all param values with mod_perl

It's as simple as:




use strict;
use CGI ( );

my $cgi = new CGI;
print $cgi->header('text/plain');
print "DEBUG:\n", join('', map({"$_: [".$cgi->param($_)."]\n"} $cgi->param)), $/;


From: http://modperlbook.org/html/ch10_01.html#pmodperl-CHP-10-EX-11

Tuesday, August 21, 2007

Using netcat to run a port listener.

If you want to have a port listening on a machine just so another host can test connecting to it (e.g. you want to see whether your "Connection refused" message is caused by your socket application failing to serve, or if it is serving but the connection is being blocked by a firewall)...

First make sure that the application that would normally listen to that port is stopped, then run up netcat:

nc -l -p 1234

where 1234 is the port you want to listen on...

Now from the other host:

telnet hostname.domain.com 1234

where hostname.domain.com is the machine you're running netcat on.

This is a failure:

$ telnet hostname.domain.com 1234
Trying 10.11.12.13...
telnet: Unable to connect to remote host: Connection refused

This is a successful connection:

$ telnet hostname.domain.com
Trying 10.11.12.13...
Connected to hostname.domain.com (10.11.12.13).
Escape character is '^]'.

If you get a connection then the network probably isn't the problem...

Once you're connected you can then either use ^D (<Ctrl-d>) to get out, or use ^] (<Ctrl-]>) to get a telnet prompt, then type close:

$ telnet hostname.domain.com
Trying 10.11.12.13...
Connected to hostname.domain.com (10.11.12.13).
Escape character is '^]'.
^]

telnet> close
Connection closed.

Monday, August 20, 2007

Permanently setting font and theme for gvim

To set the font permanently:

set guifont=Fixed\ 9

or try:


set gfn=fixed
set guifont=courier\ 8


( see http://www.troubleshooters.com/linux/vifont.htm )
( nice: http://www.proggyfonts.com/ )

To set the colour scheme permanently use:

colorscheme

In your .vimrc

(or color )

When in command mode type :help colorscheme for some help on this subject.

and:

syntax on

to make use of it.

(or:)


" have syntax highlighting in terminals which can display colours:
" > if has('syntax') && (&t_Co > 2)
syntax on
" > endif


I also have a post on toggling search highlighting...

Tuesday, August 14, 2007

How do I find the version of my current (running) bash or ksh shell?

If you just want to check from the command line:
bash --version
is OK, but that's not interactive - if you do that you're starting a new bash
which isn't necessarily the same version the current shell instance.

ksh:

In ksh you can display the version of the shell interactively by typing ^V

bash:

In bash you can do ^X^V (C-x C-v)

NB:
This works in set -o emacs.
If like me you prefer to live in the set -o vi world you may need to change to set -o emacs to check it and then back again.

There are also the BASH_VERSINFO array and BASH_VERSION variables

BASH_VERSINFO is immutable so you should be able to rely on it,
but BASH_VERSION could be set somewhere else so don't rely on it.

http://www.gnu.org/software/bash/manual/bashref.html#SEC110
has:

display-shell-version (C-x C-v)
Display version information about the current instance of Bash.

(thanks to jm_ on #debian for help with the research)

Monday, August 13, 2007

How to change the Theme in Firefox

Problem:

You have found a cool Firefox theme on the web and want to download and try it,
but have never used another theme in Firefox before...

You download it and can install it OK, but now how the heck do you switch it on?

You go to Google and search and up comes spam in the form of a www.surveymonkey.com survey, ever so helpfully titled "Firefox Theme Tutorial" asking questions like:

1. Describe your experience with Firefox Themes.
-> I only use the default because I can't figure out how to change them.

2. Would you be interested in a detailed step by step how to guide for (*snip*) Firefox themes?

3. Would you be willing to pay for this guide?

4. How much would you be willing, if any, to pay for this guide?

Just damn cruel when that's the only thing that's in your face when you're looking for help!


OK, so you go to Help in Firefox and search for "theme"... you get:

Add-ons (extensions and themes)
Switching Themes
Using a High Contrast Theme


Hmm... "Switching Themes" is clearly the one I need... *click*:

Switching Themes

To switch between your installed themes, select the Themes panel, select the
theme of your choice, and click its Use Theme button. You need to
restart Firefox for changes to take effect.

Oh great... so I just need to select the Themes panel...
Click "Tools -> Options" - nope, not in there...
Check all the other menus:
File (didn't really think it would be there)
Edit (why would it be there?)
View (COULD be there... nope)
Tools (SHOULD be there, but can't see anything about themes)

the really helpful (NOT!) bit is that without scrolling backwards and forwards in the help page
there's no indication of where you FIND this "Themes panel"!

So after a bit more Googling I went to Intranet Exploder and tried out some of the YouTube tutorials...
(I don't install Flash in my Firefox - because I prefer not to have flash spam in pages...
the only time I start up IE is for something I *need* that uses Flash,
or for broken pages I have to use for work that don't validate and won't work in Firefox)

Yay! the answer \o/
http://youtube.com/watch?v=NvU4D-Buseo
http://youtube.com/watch?v=kykO8J0XA5c
http://youtube.com/watch?v=JjnCIRO9Jg4

I don't think I'd ever used YouTube to learn something technical before - but it certainly works!

In summary - the Themes are Add-ons - as are Extensions...
so the "Themes panel" is found under "Tools -> Add-ons"

I hadn't looked in there because I use Tools -> Add-ons quite regularly (for Extensions)
so didn't bother to look in there because I didn't remember noticing the Themes panel icon before.