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

Jump to

Quick reference

Install postgres on Ubuntu 16

How to do it:

  • sudo apt-get install postgresql postgresql-contrib
  • sudo -i -u postgres
  • psql

What is a professional attitude to software development?

Professional attitude:

  • Confidence without arrogance
  • Humility without self-pity
  • Politeness, approachability
  • Communicative, hard-working
  • Competence and reliability above all
Doesn't seem too hard does it!?

Documentation formatting, presentation and distribution

Points relating to formatting and presentation (not content):
  • Documents need version numbers. This comes for free with a wiki-based system.
  • Need a "changes" section at the top, including dates & authors.
  • A table of contents with clickable (and bookmarkable) links
  • Code samples to be in a consistent style, monospace font, and limited to a single page
  • Web page or PDF, not .docx because .docx will be formatted differently by every application, and might appear corrupted or unreadable on some computers.
  • Host the document on company servers and send around a link to download it. Don't email as an attachment because it will become out of date quickly.

Add Javascript to a security protected page

If you want to run some JQuery (or any other script) on a page that doesn't have it already, you can load it like this in the web browser console:

var script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);

But on pages with a strict security policy, you may get an error:

Refused to load the script '......' because it violates the following Content Security Policy directive: .....

Solution: Edit the DOM and replace the security policy with this one:

<meta http-equiv="Content-Security-Policy" content="default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;">

(source)

Breakdown of policy from that guy:
  • default-src * self                 blob: data: gap:;
  • style-src   * self 'unsafe-inline' blob: data: gap:;
  • script-src  * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:;
  • object-src  * 'self'               blob: data: gap:;
  • img-src     * self 'unsafe-inline' blob: data: gap:;
  • connect-src self * 'unsafe-inline' blob: data: gap:;
  • frame-src   * self                 blob: data: gap:;
Hmm, that doesn't look quite right. Seems inconsistent.

Devel::Cover patterns for Perl

One:
cover -delete PERL5OPT=-MDevel::Cover=-ignore,^local/ prove -r t cover -report html_basic

Another:
perl -MDevel::Cover=+ignore,.*,-select,^lib/,-select,^t/,-silent,on t/path/to/test.t cover

Or:

for file in `find t -name '*.t`; do perl -MDevel::Cover=+ignore,.*,-select,^lib/,-select,^t/,-silent,on $file; done

In full:

unset PERL5LIB; unset PERL_LOCAL_LIB_ROOT; eval $(perl -Mlocal::lib=./local)

export PERL5LIB="/home/will/alt/cpan/devel-cover/local/lib/perl5:$PERL5LIB"

PERL5OPT=-MDevel::Cover=-ignore,^local/ prove -I t/lib -lr t

perl -I /home/will/alt/cpan/devel-cover/local/lib/perl5 /home/will/alt/cpan/devel-cover/local/bin/cover