> Sford wiki > Sford cheat sheets

I may fix the wikitext and break this into separate pages some day.


This document contains misc info that sford always forgets.

The latest version of this document can be found at http://wiki.geeky-boy.com/w/index.php?title=Sford_cheat_sheets

This document contains misc info that I always forget. I do not guarentee that any of this information is correct or even useful to anybody except myself. See http://geeky-boy.com/standard/ for my standard disclaimer and copyright.

Linux stuff I always forget

Signal stuff

Signal-safe functions: http://man7.org/linux/man-pages/man7/signal-safety.7.html

#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <semaphore.h>

sem_t sleep_sem;

void sig_handler(int signum)
  static char sig_name[] = "alarm\n";
  write(1, sig_name, strlen(sig_name));

int main(int argc, char **argv)
  sem_init(&sleep_sem, 0, 0);

  struct sigaction sa;
  sa.sa_handler = &sig_handler;
  sa.sa_flags = SA_RESTART;
  sigemptyset(&sa.sa_mask);  /* Allow other signals to interrupt this one. */
  sigaction(SIGALRM, &sa, NULL);

  alarm(3);  /* Wake up in 3 sec. */

  return 0;


Advanced Package Tool (APT): higher-level package manager than dpkg and . Aptitude: ncurses front-end.

 sudo apt-get install pkgname  # install individual package (and its dependencies).
 sudo apt-get update    # update available packages list.
 sudo apt-get upgrade  # get latest versions of packages.
 sudo apt-cache search searchpat  # good for finding which package contains a command.
 sudo dpkg -i PathToDotDebFile.deb  # install .deb file

Debian package

 sudo apt-get install debhelper   # if not installed.
 cd chip-power/chip-power
 sudo dpkg-buildpackage -us -uc  # build .deb package file.
 cd ..
 sudo dpkg -i chip-power_0.6_all.deb  # install .deb package.

Git stuff I always forget

First-time git init

$ cd ~
$ git config --global user.name "Steve Ford"
$ git config --global user.email sford@geeky-boy.com
$ git config --global core.editor vim
$ git config --list
core.pager=less -r
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\	 => \2/' | sort
user.name=Steve Ford

Clone Semlit

$ cd ~
$ mkdir src
$ cd src
$ git clone https://github.com/fordsfords/semlit
Cloning into 'semlit'...
remote: Counting objects: 133, done.
remote: Total 133 (delta 0), reused 0 (delta 0), pack-reused 133
Receiving objects: 100% (133/133), 122.83 KiB | 0 bytes/s, done.
Resolving deltas: 100% (71/71), done.
Checking connectivity... done.
$ cd semlit
$ ./bld.sh
$ cp -v bin/* ~/bin/
bin/semlit.pl -> /Users/sford/bin/semlit.pl
bin/semlit.sh -> /Users/sford/bin/semlit.sh
$ cd ..

Clone UMExamples

$ cd ~/src
$ git clone https://github.com/UltraMessaging/UMExamples
Cloning into 'UMExamples'...
remote: Counting objects: 122, done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 122 (delta 42), reused 110 (delta 32), pack-reused 0
Receiving objects: 100% (122/122), 71.65 KiB | 0 bytes/s, done.
Resolving deltas: 100% (42/42), done.
Checking connectivity... done.
$ cd UMExamples
$ ./bld.sh
bld.sh: Info: c/check_flight_size_ewouldblock.sldoc: building semiliterate doc
bld.sh: Info: c/context_create.sldoc: building semiliterate doc
bld.sh: Info: c/minsrc.sldoc: building semiliterate doc
bld.sh: Info: java/minsrc.sldoc: building semiliterate doc
bld.sh: Info: c/source_create.sldoc: building semiliterate doc
bld.sh: Info: building html index files
$ $ git log --pretty=oneline
ed695dfc52b83b189f6fac24f476039abb3874dc Merge branch 'gh-pages'
b2659718cd487f907041eae3d2444f1eef870881 Minor change
6775ff050044a27b2ddae90a466fa47075b8d55b Merge branch 'master' into gh-pages
b7a3bc43e624001be7a35c6e13f61c103a531a1c Changed everything.  :-)
de9118714c98dd1f4c282f97620db116dd093dcb removing weird \ file
a3d45704e959e19f713f2e429f64ef47e94b910b adding link the example html pages
9a797c7d0951f3a3177f825de976fe66ead02e21 initial commit of UMExamples with 4 samples and directory structure
1ab2ce36abd37b542f8140dde7fe059dad23febf Initial commit
$ cd ..

Minor change

$ cd ~/src/UMExamples/
$ vi minsrc/c/minsrc_c.slsrc

(in line 21, change "program" to "macro")

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   minsrc/c/minsrc_c.slsrc

no changes added to commit (use "git add" and/or "git commit -a")
$ git add --dry-run --all
add 'minsrc/c/minsrc_c.slsrc'
$ git add --all
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   minsrc/c/minsrc_c.slsrc
$ git commit
[master 7cc16f2] Fixed comment
 1 file changed, 1 insertion(+), 1 deletion(-)

(could have skipped the "git add" and instead used "git commit -a" to stage and commit)

$ git remote -v
origin	https://github.com/UltraMessaging/UMExamples (fetch)
origin	https://github.com/UltraMessaging/UMExamples (push)
$ git push origin master
Username for 'https://github.com': fordsfords
Password for 'https://fordsfords@github.com': 
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 427 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
To https://github.com/UltraMessaging/UMExamples
   ed695df..7cc16f2  master -> master

Make it live

$ git checkout gh-pages
Switched to branch 'gh-pages'
Your branch is up-to-date with 'origin/gh-pages'.
$ git merge master

(a bunch of earlier changes are listed)

$ git push origin gh-pages
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/UltraMessaging/UMExamples
   b265971..c63cd86  gh-pages -> gh-pages
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

Merging remote change

$ git fetch origin
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 10 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
From https://github.com/UltraMessaging/UMExamples
   7cc16f2..385846b  master     -> origin/master

(this fetches to local repo, but does not merge into my current work area)

$ git merge
Updating 7cc16f2..385846b
 .../c/check_flight_size_ewouldblock.slsrc.html     | 247 +++++++--------------
 .../check_flight_size_ewouldblock_store.slsrc.html | 133 ++---------
 setting_attributes/README.txt                      |   5 +
 3 files changed, 110 insertions(+), 275 deletions(-)
 create mode 100644 setting_attributes/README.txt

(could use "git pull" instead of "git fetch"/"git merge")

Wiki stuff I always forget

Grammar stuff I always forget

The following is stolen, lock, stock, and barrel, from http://grammar.ccc.commnet.edu/grammar/marks/quotation.htm

Quotation Marks

Use quotation marks to set off material that represents quoted or spoken language. Quotation marks also set off the titles of things that do not normally stand by themselves: short stories, poems, and articles. Usually, a quotation is set off from the rest of the sentence by a comma; however, the typography of quoted material can become quite complicated. Here is one simple rule to remember:

In the United States, periods and commas go inside quotation marks regardless of logic. Click HERE for an explanation (sort of).

In the United Kingdom, Canada, and islands under the influence of British education, punctuation around quotation marks is more apt to follow logic. In American style, then, you would write: My favorite poem is Robert Frost's "Design." But in England you would write: My favorite poem is Robert Frost's "Design". The placement of marks other than periods and commas follows the logic that quotation marks should accompany (be right next to) the text being quoted or set apart as a title. Thus, you would write (on either side of the Atlantic):


Further, punctuation around quoted speech or phrases depends on how it fits into the rest of your text. If a quoted word or phrase fits into the flow of your sentence without a break or pause, then a comma may not be necessary:

Following a form of to say, however, you'll almost always need a comma:

If the quoted speech follows an independent clause yet could be part of the same sentence, use a colon to set off the quoted language:

When an attribution of speech comes in the middle of quoted language, set it apart as you would any parenthetical element:

Be careful, though, to begin a new sentence after the attribution if sense calls for it:

Convention normally insists that a new paragraph begins with each change of speaker:

In proofreading and editing your writing, remember that quotation marks always travel in pairs! Well, almost always. When quoted dialogue carries from one paragraph to another (and to another and another), the closing quotation mark does not appear until the quoted language finally ends (although there is a beginning quotation mark at the start of each new quoted paragraph to remind the reader that this is quoted language). Also, in parenthetical documentation (see the Guide to Writing Research Papers), the period comes after the parenthetical citation which comes after the quotation mark" (Darling 553).

In reporting "silent speech".noting that language is "said," but internally and not spoken out loud.writers are on their own. Writers can put quotation marks around it or not:

Some writers will set such unspoken language in italics or indent it in order to set it off from other "regular" language. That's probably not a good idea if there is a lot of it because the indents can be confusing and italics can become tiresome to read after a while. The decision will probably depend on the amount of silent speech within the text. Probably the best way to handle silent speech is to find an author whom you like who does a lot of this.Graham Swift in his novel Last Orders, for instance.and copy that author's style. Consistency, of course, is very important.

Some interesting things can happen with verb tenses when we report action in indirect or reported speech ("The president said that he was going to Egypt tomorrow"). For help with this issue, we would refer to you Professor Mary Nell Sorensen's Web site at the University of Washington.

Be careful not to use quotation marks in an attempt to emphasize a word (the kind of thing you see in grocery store windows.Big "Sale" Today!). Underline or italicize that word instead. (The quotation marks will suggest to some people that you are using that word in a special or peculiar way and that you really mean something else.or that your sale is entirely bogus.)

The American Medical Association Manual of Style (9th ed, 1998) calls misused quotation marks like this Apologetic Quotation Marks and says:

Quotation marks used around words to give special effect or to indicate irony are usually unnecessary. When irony or special effect is intended, skillful preparation can take the place of using these quotes. Resort to apologetic quotation marks or quotation marks used to express irony only after such attempts have failed, keeping in mind that the best writing does not rely on apologetic quotation marks. (p 220)

Refer to Guide to Writing Research Papers and, especially, the English faculty's Suggestions for Writing Papers for Literature Courses for further help in handling quotations.

We do not enclose indirect quotations in quotation marks. An indirect quotation reports what someone says but not in the exact, original language. Indirect quotations are not heard in the same way that quoted language is heard.

Double Punctuation with Quotations

Occasionally - very occasionally, we hope - we come across a sentence that seems to demand one kind of punctuation mark within quotation marks and another kind of punctuation mark outside the quotation marks. A kind of pecking order of punctuation marks takes over: other marks are stronger than a period and an exclamation mark is usually stronger than a question mark. If a statement ends in a quoted question, allow the question mark within the quotation marks suffice to end the sentence.

On the other hand, if a question ends with a quoted statement that is not a question, the question mark will go outside the closing quotation mark.

If a question ends with a quotation containing an exclamation mark, the exclamation mark will supersede the question and suffice to end the sentence.

A single question mark will suffice to end a quoted question within a question:

Authority for this section: New York Public Library Writer's Guide to Style and Usage HarperCollins: New York. 1994. 277. Cited with permission, examples our own.

Single Quotation Marks

In the United States, we use single quotation marks to enclose quoted material (or the titles of poems, stories, articles) within other quoted material:

British practice, again, is quite different. In fact, single-quote marks and double-quote marks are apt to be reversed in usage. Instructors in the U.S. should probably take this into account when reading papers submitted by students who have gone to school in other parts of the globe.

In newspapers, single quotation marks are used in headlines where double quotation marks would otherwise appear.

One further use, according to the Chicago Manual of Style: in philosophical discourse, key concepts may be set apart with single-quote marks. When such concepts are set off in this way, periods and commas go outside the single-quote marks:

Docbook stuff I always forget

Ref: http://www.docbook.org/tdg/en/html/docbook.html

More doc: http://www.sagehill.net/docbookxsl/

"Include" files:

<!ENTITY ch01 SYSTEM "ch01.sgm">

Socket stuff I always forget

http://www.madore.org/~david/computers/connect-intr.html - Blocking connect socket call can get EINTR and it's a pain to deal with.

PHP stuff I always forget

 class XClass {
     public $xcolor;
     private $xorientation;
     static $num_instances = 0;
     public const RIGHT = 1;
     function __construct($orient = 2) {    // default value for parameter
         $this->xorientation = $orient;    // $this-> == $instance_var->
         $this->num_instances ++;
     function __destruct() {
         if ($this->num_instances <= 0) throw new Exception("Oops");
         $this->num_instances --;
     private function set_orientation($orient) {
         $this->orientation = $orient;
     public function turn_right() {
         $this->set_orientation($this->orientation + self::RIGHT);    // self:: == ClassName::
     static function instance_count() {
         return $this->num_instances;
 $x = new XClass;    // could also include (5)
 print XClass::instance_count();

Java stuff I always forget

JMS docs: http://java.sun.com/products/jms/docs.html

CPU stuff I always forget

Unix stuff I always forget

"Rosetta Stone for Unix" http://bhami.com/rosetta.html

Normal file protection: file mode. chmod. Linux extended file permissions: attributes. lsattr and chattr. See https://wiki.archlinux.org/index.php/File_permissions_and_attributes#File_attributes


http://www.faqs.org/faqs/Solaris2/FAQ/ - Solaris 2 FAQ (master ftp://ftp.wins.uva.nl/pub/solaris)

Library stuff: env var "LD_PRELOAD": http://uberhip.com/godber/interception/html/slide_5.html and http://developers.sun.com/solaris/articles/lib_interposers_code.html#malloc_interposer.c Shared libraries: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

HPUX - no /var/adm/messages file, see instead "/var/adm/syslog/syslog.log". No /etc/rc.d directory, see instead "/sbin/rc*". Also, "/usr/lib/netsvc/fs/autofs/automountd".

Signal handling - if writing a library routine that needs to handle a signal (e.g. SIGPIPE in a function that writes to a socket), then it should save and restore the caller's signal handler. Use sigaction (SVr4) or sigvec (BSD) so that extra flags can be saved and restored. But having lib routines do that is not recommended. For one thing, there is only one signal handler for an entire multi-threaded process. By having the lib routine set it's own handler, even temporarily, leaves a potential race condition where the wrong handler will catch a given signal. Also, if an application thread establishes a signal handler during our execution, then *we* won't catch *our* signal. And we could restore the "wrong" handler, especially if both the applic and the lib do save/restore.

Random Snoop Facts

Snoop is solaris-only. It normally requires root privilage to run it, but I've modified systems to allow anybody to use it (set ownership to root and set the "set-uid" bit: "chmod 4555 snoop").

Linux has a similar tool: "tcpdump". (It is located in /usr/local/sbin, which is not normally in the PATH, so you need to explicitly call it out.)

I don't know tcpdump very well, so I'll concentrate on snoop.

Snoop normally outputs to the screen, but over the years I've kicked myself over and over again for using it that way. I don't know how many times I've run it and the interesting stuff scrolls off the screen and it's hard to reproduce what I'm looking for. So now I use it's storage mode. Use the "-o outfile" instead of STDOUT redirection! It saves more info that way.

The output file generated by "-o" is not ascii. You need to use snoop to read and display its contents ("-i infile"). This is actually a Good Thing, because you can use all of snoop's selection and filtration when displaying packets. And you can change your mind as often as you like as to how much info to display.

As a result, always capture more packets than you want. Cast your net wide, and then use snoop's packet selection power during the display phase. It's easy to display less than you capture; it's impossible to display more than you capture.

The easiest way to use it is "snoop -o ofile". This will capture every packet transferred. Unfortunately, that will include telnet traffic. So, in spite of my warning to cast your net wide, I usually do restrict the capture to packets between the two systems you're interested in. (Also, make sure your telnet session is not nested through the remote host. I.e. I might telnet to host1, and from there telnet to host2. If I then snoop host1 from host2, it will capture all that stupid telnet traffic.)

So, if you're running your client on the local system, and server is running on host1, enter:

  snoop -o ofile quad001

This will capture packets both sent and received. You will need to use "ctrl-c" to stop it.

Then, to display it, enter:

  snoop -i x -x 0 -t r | more

The "-x 0" tells it to dump the contents of the packet in hex, starting with offset 0 within the packet. The "-t r" tells it to display timestamps relative to the receipt of the first packet (by default it displays time *between* the packets).


Cygwin is a UNIX environment for Windows. See http://www.cygwin.com/ for more info and the latest download. The Cygwin user's guide is at http://sources.redhat.com/cygwin/cygwin-ug-net/cygwin-ug-net.html and the FAQ is at http://www.cygwin.com/faq/

"/usr/doc/Cygwin/inetutils*.README" for more info.


The FreeBSD handbook: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/index.html

Downloaded "4.3-install.iso" from ftp://ftp9.FreeBSD.org/pub/os/FreeBSD/releases/i386/ISO-IMAGES/ and cut a CD on phoebus ( as root with:

    cdrecord -v speed=2 dev=0,1,0 4.3-install.iso

(Created user on hagar with "/usr/sbin/useradd -u 1009 sford", then added "/opt/schily/bin" to PATH and "/opt/schily/man" to MANPATH.)

Installed devel system "thor" with mostly defaults for everything. When I create the "sford" account, I added it to the "wheel" group so that it has "su" capabilities.

RedHat Linux

Some doc:

Install RedHat as follows:

  1. Boot to the 7.1 RedHat CD (disk 1) and enter "text"
  2. Select: "English", "US", "Custom System"
  3. For Auto Partition, select "Continue"
  4. For LILO Config, select "OK", "OK", "OK"
  5. For Network Config, de-select "DHCP" and enter "", "", "", "", ""
  6. For Hostname enter "thor"
  7. For Firewall, select "No Firewall"
  8. For Mouse, select "generic - 2 button PS/2"
  9. For Language, select "English (USA)"
  10. For timezone, select "Hardware clock set to GMT" and "America/Chicago"
  11. For Root Password, use old vaisya
  12. For User Accounts, create "sford" and "dcrpt"
  13. For Authent config, select "OK"
  14. For package groups, select "Networked Workstation", "NFS Server", "SMB Server", "IPX/Netware Connect", "Web Server"

Then reboot, log in, "su" to root.

To enable apache and prepare it for DCReporter development:

    mkdir /var/www/perl
    cd /etc
    for F in 3 4 5; do mv rc${F}.d/K15httpd rc${F}.d/S85httpd; done
    vi /etc/group           <em>(add "dcrpt,sford" to end of "dcrpt" entry)</em>
    chgrp dcrpt `find /var/www -print`
    vi /etc/httpd/httpd.conf
        <em>(Add "PerlSendHeader On" to "<Location /perl>" after "PerlHandler".
         Also change all "AllowOverride None" to "AllowOverride All".
         Also set up "ServerAdmin" and "ServerName".)</em>

Internet stuff I always forget

Good place for RFCs: http://www.faqs.org/rfcs/rfc-activeT.html

Protocol overhead byte counts (TCP/UDP/IP): http://sd.wareonearth.com/~phil/net/overhead/

Private networks (unrouted IP addresses) from http://www.faqs.org/rfcs/rfc1597.html    -  (class A network, or CIDR  -  (16 class B networks, or CIDR - (256 class C networks, or CIDR

Html stuff I always forget

HTML 3.2 spec: http://www.w3.org/TR/REC-html32.html

Trademarks: &#8482;=™ &#153;=™ &reg;=®

To include username/password in FTP urls: ftp://usr:psw@host/...

auto-refresh page:

<b><meta http-equiv="refresh" content="</b>num-sec<b>; url=http://</b>full-url<b>"></b>

Basic table:

<b><table</b> <b>border=0</b> <b>bgcolor=0</b>
<b>    cellpadding=3</b><em>(spacing-within-cell)</em>
<b>    cellspacing=3</b><em>(spacing-between-cells)</em>
<b>    align=LEFT</b>|<b>center</b>|<b>right</b>
<b>    width=</b><em>pixels</em>|<em>percent-of-window</em><b>%</b>
<b><tr</b> <b>bgcolor="#FFFFFF"</b>
<b>    align=LEFT</b>|<b>center</b>|<b>right</b> <b>valign=top</b>|<b>MIDDLE</b>|<b>bottom</b>
<b>    nowrap</b> <b>rowspan=</b><em>num-rows</em>
<b>    align=LEFT</b>|<b>center</b>|<b>right</b> <b>valign=top</b>|<b>MIDDLE</b>|<b>bottom</b>
<b>    colspan=</b><em>num-cols</em>

To make a nice colored box with text:

<table bgcolor="#000000"><tr><td>
<table bgcolor="#C0C0C0" cellpadding="3"><tr><td>
blah blah blah...

To make a link that spawns a new window:

<script language="JavaScript" type="text/javascript">
function vw(url) {
  page=window.open(url, 'vw', 'toolbars=0,directories=0,menubar=0,status=0,location=0,scrollbars=1,resizable=1,width=350,height=290');
  page.focus(); }
<a href="javascript:vw('../')">Up</a><br>
<a href="javascript:vw('../')">Up</a>
<a href="javascript:vw('http://www.geeky-boy.com/')">Geek</a><br>
<a href="javascript:vw('http://www.geeky-boy.com/')">Geek</a>

Apache stuff I always forget

Indigo Perl

Indigo Perl is a binary build of Perl for Win32 with an integrated Apache web server configured for mod_perl. See http://www.indigostar.com/ for more info and the latest download.

To install it, perform the following steps:

  1. Extract "indigoperl-5_6.zip" to "c:\indigo" and run "setup.bat". Hit "enter" to install in current directory.
  2. Extract "indigo_icons.zip" to "c:\indigo".
  3. Edit "c:\indigo\conf\httpd.conf" and make the following changes:
            old                                    new
        ServerAdmin you@your.address           ServerAdmin steve_ford@geeky-boy.com
        ServerName localhost                   ServerName
        ScriptAlias /perl-bin/ "perl-bin/"     ScriptAlias /perl/ "c:/indigo/perl/"
        PerlSendHeader On                      PerlSendHeader On
        <Location /perl-bin>                   <Location /perl>
  4. Edit "c:\indigo\htdocs\index.html" and globally substitute "perl" for "perl-bin".
  5. Rename "c:\indigo\perl-bin" to "c:\indigo\perl".
  6. Make copies of "Stop Apache" and "Start Apache" shortcuts onto the desktop. (This is for convenience only.) Also put a copy of "Start Apache" into the "Startup" folder under the Start menu.
  7. Start Apache.
  8. Bring up the home page and try running the "mod_perl_test.pl" script.


Some useful doc:

Ftp to host1 and get the following files from the directory "/usr/local/sford.nobackup":



The first seven regular perl packages. Unpack and install each of them in the order shown:

  gunzip -c <PACKAGE.tar.gz | tar xvf -
  perl Makefile.PL
  make test
  su                   <em>(enter root password)</em>
  make install
  exit                 <em>(exit root)</em>
  cd ..

Apache, mod_perl, and mod_perl_extras need to be done sort-of interleaved. First extract apache. Then build mod_perl according to "INSTALL.apaci":

  gunzip -c <apache_1.3.20.tar.gz | tar xvf -
  gunzip -c <mod_perl-1.26.tar.gz | tar xvf -
  cd mod_perl-1.26
  vi Makefile.PL       <em>(change "(RM)" to "(RM_F)")</em>
  perl Makefile.PL APACHE_SRC=../apache_1.3.20/src DO_HTTPD=1 USE_APACI=1 PREP_HTTPD=1 EVERYTHING=1
  make                 <em>(leave out "make test")</em>
  su                   <em>(enter root password)</em>
  make install
  exit                 <em>(exit root)</em>
  cd ..

Now finish apache:

  cd apache_1.3.20
  ./configure --prefix=/usr/local/apache --activate-module=src/modules/perl/libperl.a
  su                   <em>(enter root password)</em>
  make install
  gunzip -c <../mod_perl_extras.tar.gz | (cd /usr/local/apache;tar xvf -)
  chown nobody /usr/local/apache/logs/cgi.log
  chgrp nobody /usr/local/apache/logs/cgi.log
  vi /usr/local/apache/conf/httpd.conf
      <em>(update "Port", "ServerAdmin", "ServerName")</em>
      <em>(go to end and add 'Include "conf/mod_perl.conf"')</em>
  /usr/local/apache/bin/apachectl start
  telnet localhost 80
  GET /perl/sample     <em>(should print output of sample mod_perl program)</em>
  exit                 <em>(exit root)</em>
  cd ..

Be sure to look in the "htdocs" and "cgi-bin" direcories and remove anything you don't want.

To password-secure the site (all passwords set to "sissors"):

  su                   <em>(enter root password)</em>
  cd /usr/local/apache/
  vi conf/httpd.conf
      <em>(change most "AllowOverride" lines to "AllowOverride All")</em>
      <em>(go to the end and add 'Include "conf/auth.conf"')</em>
  echo "samsclub: sford sam chw ginzburg jmp" >conf/group
  cp /dev/null conf/passwd
  for F in sford sam chw ginzburg jmp tst;do bin/htpasswd -b conf/passwd $F sissors;done

Then add ".htaccess" files in the various directories. Some examples:

  echo "require valid-user" >htdocs/.htaccess
  echo "require group samsclub" >perl/.htaccess
  echo "require user sford" >cgi-bin/.htaccess

Note that given this setup, the "icons" directory is not protected.

C stuff I always forget

Perl stuff I always forget

Yes, I'll admit it, I STILL program perl like a C programmer. But I am getting better. This section is not just how to do C-isms in perl; it's also stuff I just haven't managed to memorize yet.

You don't need to use awk to do quick one-liners. Here's a one liner that makes a splits space-separated fields into multiple lines:

    echo $LONGLINE | perl -nlae 'foreach (@F) {print;}'

(-n=Loop, -l=Chomp&PrintNl -a=AutoSplit -e=Src) Just remember that (unlike awk) the array of fields (@F) is zero-based, not one-based. You can also include "-Fx" where "x" is a delim character.

To deal with binary files, invert each byte:

    open INP $ARGV[0] || die "open $ARGV[0]";
    my ($buf, $len);
    while ($len = read(INP, $buf, 2048)) {
        my @bytes = unpack("C*", $buf);
        foreach (@bytes) { $_ = ~ $_; }
        print pack("C*", @bytes);

More random stuff:</p>

Retrieved from "http://wiki.geeky-boy.com/w/index.php?title=Sford_cheat_sheets"