Call CGI script from SSI
Values of CGI Variables
Serve Images via CGI
Serve Images via CGI
Use Regular Expressions to Substitute Non-Constant Values in Python
Use Regular Expressions to extract the title from HTML using Perl
Get just the text of a HTML string using Perl
How to manipulate dates
Faster Laptop - Powercfg.exe

Call CGI Script from SSI:
This is not a complete discussion, just how to do this with cgiwrap.

Without debugging:
< !--#include virtual="/cgi-sys/cgiwrap/username/filename.cgi?query=lcd tv" -- >

With debugging:
< !--#include virtual="/cgi-sys/cgiwrapd/username/filename.cgi?query=lcd tv" -- >

Values of CGI Variables:
Say you want to know what variables are available in a CGI script? Best to print it out. Try this perl snippet:
foreach (sort keys %ENV) { print "$_ = $ENV{$_}\n";}

Serve Images via CGI:
If you use ebay to serve your images, it might happen that you want to use a nice mod-rewrite script to serve images after calling cgi. Well I did anyway. The trouble was that I couldnt get the

IMG src=url-that-mod-rewrite-fixes

to get "fixed" via cgi. What was wrong??? Frankly many things. But the key is that unlike most cgi files that have a first line of content-Type: text/html, to serve an image you need to print (from cgi)

Location: ebay's-image-that-the-cgi-program-fixed\n\n.

See What's Going On With Redirects:
So, let's imagine you're trying to write some nasty mod-rewrite with many redirects. How can you see what's going on without writing a spider? Use

Web Sniffer

How to Construct more Complex Python Substitutions in Regular Expressions
OK, let's say you need to substitute something more complex than a fixed string; how do you specify the variable you might build up/calculate?! All the examples show simple contants, or use regex meta-characters.

In Python you can specify a function for the pattern. That function must take exactly one argument (except for self if needed as part of a class).

Here's a crude example:

def linkRep (self, matchobj):
   return (' </a>')

def addLinks (self, str, pattern, target):
   _p = re.compile (pattern, re.IGNORECASE)
   self.replPrefix = '<a href="' + target + '"> '
   _ret = _p.sub (self.linkRep, str)
   return (_ret)

How to manipulate dates:
Coming soon

Use Regular Expressions to extract the title from HTML using Perl

   if ($htmlfile =~ /<title>/i ) {
       $title = $htmlfile;
       $title =~ /<title>(.*)<\/title>/ ;
       $title = $1;
       # Less efficent solution:
       # $title =~ s/^.*<title>//i;
       # $title =~ s/<\/title>.*$//i;
       print "title: $title \n";
Get just the text of a HTML string using Perl
use HTML::Parse;
use HTML::FormatText;
$plain_text = HTML::FormatText->new->format(parse_html($htmlfile));

Faster Laptop - Powercfg.exe:
OK, I got my snazzy new Dell Laptop Workstation and when I ran Monte Carlo simulations on it the performance was pathetic. Sure with two processors at least I could still read my email, but geez, get a life, this is a very cool machine I should get a result in under 10 minutes. I killed it after 3 hours.

There's a little known command called powercfg.exe that you can access via the cmd prompt in Windows XP. There's some documentation for this command on the web, but it's pretty confusing about exactly how to execute the commands. Here's the tricks I needed to figure out:

1. c:\>powercfg.exe /list
- shows all the power configurations

2. c:\>powercfg.exe /query
- Shows current power configuration. Change the selected one with the power window settings:

control panel:display properties, then select the Screen Saver tab. Click the Power... button

3. powercfg.exe /QUERY "Maximum Performance (QuickSet)"
- Shows the settings for the power configuration called maximum performance. Notice the double quotes to deal with the spaces. The text typed matches the text returned by the /list command.

4. powercfg.exe /change "Maximum Performance (QuickSet)" /Processor-Throttle-AC none
Changes the setting for the Processor Throttle when the machine is plugged in. Notice the same double quotes and copying for the power configuration. Notice that the parameter is a copy and paste of the parameter you want to change with the spaces replaced by dashes and the parens removed.

The sensible choices for Processor-Thorttle-AC are:
None: - Always run at the hightest perforance state
Constant - Always run at the lowest performance state
Adaptive - Run at a performance state that is chosen automatically according to demand
Degrade - Always run at the lowest performance state, and use additional linear performance reduction as battery discharges

Last Modified: September 3, 2008
Sandra Carrico
scarrico(put an at here)