A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Add-ons for Thunderbird

  • Lightning = a calendar
  • Mailbox Alert = pop up a message for important emails (first set a rule to copy them to a folder, then right click on the folder to set the Mailbox Alert)

Pop up a message box in Ubuntu

Try gmessage, xmessage or zenity (in that order)
But none of them force the window to always appear over other windows.

Display upcoming code in Perl debugger

Type this after the debug session has started:
> @DB::typeahead=('v')
or
{{v

See also these questions and perldebug.

How to install perl modules into a local directory

instead of:
perl Makefile.PL
try:
perl Makefile.PL PREFIX=/path/to/your/directory/perllibs
or:
perl Build.PL PREFIX=/path/to/your/directory/perllibs

Delete a file starting with a dash

You accidentally created a file called "-.log"

To delete it, instead of
rm -.log
try
rm ./-.log

Reasons to split up a very long subroutine into several more subroutines

  • Repetition
    • If the same or very similar code is being called several times, it should be put into a subroutine to avoid code duplication.
    • This is the most obvious reason.
  • Clarity
    • You should be able to read the code like English
    • Reading the code in a top level subroutine or script should give an overview of what it does, without going into detail
    • Each subroutine should be able to be easily described in one or two sentences
    • Comments are not sufficient for this, as you would still have to scan through many pages to gain an understanding. 
    • This reason is controversial; Some people say repetition is the only valid reason (see 'dangers' below)
  • Testing
    • You should be able to test each conceptual part of the system separately.
    • It should be obvious to which part of the system a unit test applies.


Dangers of the second two reasons:
- Too much abstraction, difficult to understand and follow code flow
- Code is slow because of overhead of creating and managing subroutines

Allow your customers to contact you easily

Live chat
olark is designed to let your customers chat to you. It works great on spoofcard.com.
It's also possible to use adium or pidgin in this manner.

Feedback
getsatisfaction is free, uservoice isn't. Maybe there are other services, too.

Web scraping with Ruby

In order of goodness:

  • Nokogiri
  • Hpricot
  • Scrapi

Dedupe lines in place

in vim, select a list of values with shift-V (visual mode), and then type :sort u to sort them and remove duplicates.

Password protect a directory in Apache

Put a .htaccess file in the directory you want to protect, containing:

AuthUserFile /full/path/to/your/htpasswd_file
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic



require valid-user


Then use an online htpasswd generator to create the htpasswd_file at the location you specified for AuthUserFile above. Make sure this is outside your public webspace.

Add to breadcrumb trail in phpBB

Do this before loading the template:

$template->assign_block_vars('navlinks', array(
    'FORUM_NAME'    => "link display text",
    'U_VIEW_FORUM'  => "http://url-of-page"
));