cheatsheet

>> plambeck.org >> cheatsheet




























2002
Cheatsheet

A random of collection of things I've forgotten or had to look up multiple times.

No more (I hope).
Including a Postscript file in a LaTeX document via the special command

 \begin{figure}
 \special{psfile=drawingtest.eps
        hscale=25 vscale=25}
 \end{figure}

Examples using scp and ssh
scp -i user@www.whatever.com mydata.tar user@www.whatever.com:i.tar

ssh -l user user@www.whatever.com 'mv mydata.tar html; cd html; tar xvf i.tar'

How I succeeded converting typewritten manuscripts into searchable PDF documents using Acrobat Paper Capture with a Scanner

1) Equipment: HP Scan Jet 6200C scanner and Acrobat 5 with the "Paper Capture Plug In," which is not included with Acrobat 5 (I had to get it from Adobe web site, but for free), OS=Windows 2000. Acrobat 5 is not the freely downloadable "Reader," though, you have to buy it.

2) From Acrobat 5, File->Import. May have to educate Acrobat about the scanner first (I didn't).

3) Scanner runs. Preview of page shown in the scanner application (on my laptop, this app is "HP PrecisionScan Pro"). It wasn't clear what to do next here.

4) Here's what to do: Choose "OutputType->Black and White ->Bitmap (raster)" in the scanner application. [This is important].

5) Choose Scan->Place Image in scanner application. Page is rescanned and via some Win32 or TWAIN magic in the scanner and/or Acrobat, is automatically brought into Acrobat. If step 4 is not done first, the image will still be brought into Acrobat, but not in a form suitable for "paper capture". (Ie, OCR will fail at paper capture). The image is now in Acrobat, but text hasn't been recognized yet.

6) Choose Tools->Paper Capture in Acrobat. It will ask you if you want to do current page or all pages.

7) To add pages, reopen document, and start at File ->Import again

8) To correct text, use the "Text touch up tool" in Acrobat (rightmost "T" icon in Acrobat 5 toolbar)
Not too bad on the doc sizes, only about 35K per page. Here's an example of two pages from a technical document whose original electronic format has been lost. I scanned and captured them using the steps above.

My IBM laptop's machine type and model number

2647-M6U. Useful at the IBM support web site.
Using awk, uniq, and grep to filter files

For example for a file web.log with entries that look like
216.103.110.18 - - [27/Mar/2002:03:59:14 -0500] "GET /people/index.htm HTTP/1.1"
 304 - "http://www.plambeck.org.com/index.htm" "Mozilla/4.0 (compatible; MSIE 6.0; Win
dows 98; Q312461)"
Use the command
cat web.log | awk -F- '{print $1}'
to display the first word on each line that comes before the - sign (ie, the IP address in the example above).

Then use some combination of use 'uniq' and 'sort' to achieve your goal; for example
 cat web.log | awk -F- '{print $1}' | sort | uniq -c
to print out number of log entries per IP number.

To get grep to print out lines that don't match a pattern, use the -v option:
 cat web.log | grep -v 216 

Telephone Numbers

800 241 6522 United Airlines
408 441 8764 Caroline Brenneise
650 321 7722 Michael Taymor
415 255 6975 loft vmail
650 326 5751 Beth and Greg
630 566 6884 eFax Number. Note the area code is not 650.
Faxes sent to this number are eventually emailed to thane@kothreat.com. I don't pay for this any more, but the eFax people have never turned it off.
Counting distinct objects under a group action

Suppose G is a group of permutations of a set X and let F(g) be the number of objects fixed by a group element g. Then the next theorem says that the number of orbits is equal to the average size of the set F(g).

Theorem: The number of orbits of G on X is
            1   ----
          ----- \    |F(g)|
           |G|  /___
                g in G

Show the listing of last logged in users on a Linux box

The 'last' command.
An extremely good article on how use perl references

Here. I copied it from The Perl Journal, which is an excellent source for looking up information on Perl.
Passing command line options to a perl program

This also came from the Perl Journal.
At URL http://www.samag.com/documents/s=1286/sam03020005/:

THE SIMPLEST WAY

Perl directly supports the single-character style of options with the -s switch. If you start Perl as

perl -s script.pl -foo -bar myfile.dat

Perl will remove anything that looks like an option (-foo and -bar) from the command line and set the variables ($foo and $bar) to true. Note that the options are words preceded with a single dash. When Perl encounters an argument without the dash, it stops looking for options.

THE EASY WAY

Perl comes with two modules that handle command line options: Getopt::Std and Getopt::Long.

Getopt::Std provides two subroutines, getopt() and getopts(). Each expects a single dash before option letters and stops processing options when the first non-option is detected.

getopt() takes one argument, a string containing all the option letters that expect values. For example, getopt ('lw') lets your program be invoked as program -l24 -w 80 (or program -l 24 -w80), and it will set $opt_l to 24 and $opt_w to 80. Other option letters are also accepted; for example, program -l24 -ab will also set both $opt_a and $opt_b to 1.

When you don't want global variables defined in this way, you can pass a hash reference to getopt(). The keys are the option letters, and the values will be filled with the values (or 1 if the option doesn't take a value).

getopts() allows a little bit more control. Its argument is a string containing the option letters of all recognized options. Options that take values are followed by colons. For example, getopts ('abl:w:') makes your program accept -a and -b without a value, and -l and -w with a value. Any other arguments beginning with a dash result in an error. As with getopt(), a hash reference can be passed as an optional second argument.
How to use 'cron'

Suppose you have a command you want to run automatically at 5 minutes past 4 o'clock every Sunday, with its output mailed to some email address.

There are two steps to make this happen:

You create a file myCronInput (or whatever) that looks like this:
SHELL=/bin/sh
MAILTO=somebody@company.net
5 4 * * sun (put the command here)
Note that the fact that the output of the command is mailed to the MAILTO variable is implied. If you wanted the command to run every day instead, change the 'sun' to a *.

Next you 'submit' the job to the cron daemon using the crontab command:
crontab myCronInput
You can see what the cron daemon thinks of what you did by doing this:
crontab -l

Settings for saving a transparent GIF picture from Adobe Illustrator 8

Move the artwork to the upper left hand corner. Check to make sure there are no stray art work blobs that will make the image too big.

Choose File->Export->GIF89a

Use these settings:
Palette: Exact
Colors: 256
Halftone Dither: Yes
Interlace: No
Transparent: Yes
Anti-Alias: No
Image Map: No
In particular, don't forget to turn Anti-Alias off. If it's on, you'll get bleedthrough on non white backgrounds.