# home.cgimp
#   perl script to generate home web page for "Computer Science @ Marlboro"
#   Jim Mahoney, mahoney@marlboro.edu
#   code version history (the content changes more often)
#      3.2 Sep 2006  - changed float to position:absolute to handle IE bug
#      3.1 Aug 2006  - floated top right with embedded CSS
#      2.0 Mar 2006  - one liners http://www.ohek.co.uk/funnies/fun-quotes.htm
#      1.9 Sep 2005  - added more jokes
#      1.8 Apr 2005  - added link to nook
#      1.7 Jan 2005  - changed top-left logo to an image
#      1.6 Sep 2004  - went through W3 HTML Validator, just for kicks.
#      1.5 Aug 2004  - added $ENV{HTTPS} to SSL_logo_html for new server
#                      removed #!/usr/bin/perl - running in mod_perl
#      1.4 Jan 2004  - added a few more jokes and link to source
#      1.3 Oct 2003  - put html in its own subroutine
#      1.2 Jan 2003  - cleaned up joke generation
#      < 1.1         - prehistory
use strict;
use CGI qw(param header start_html end_html);
my $thisfile = '/var/www/cs/htdocs/home/home.cgimp';

print header();
print start_html( -title        => "computer science \@ marlboro.edu",
                  -alink        => "#000066",
                  -vlink        => "#000066",
                  -link         => "#000066",
                  -bgcolor      => "#FFFFFF",
		  -style        => "/home/home_style.css",
	  # -meta => {'google-site-verification' => "fMStMgKhiN8dl0OSuuS_cbIDyKgQl3d_c9IkSwOnfqM"},
print page_html(get_joke(), 
print end_html();
print "\n";

# ========================================================
# Usage: $lastmodifiedstring = lastmodified($filename);
sub get_lastmodified {
  my ($file) = @_;
  my @months = qw( Jan Feb Mar Apr May Jun July Aug Sep Oct Nov Dec );
  my ($day,$month,$year) = (localtime((stat($file))[9]))[3,4,5];
  my $text = 'last modified ' . sprintf("%s %02d %04d", $months[$month], $day, $year+1900 );
  $text =~ s/ /&nbsp;/g;
  return $text;

# ========================================================
# The following are from various online sources, most without attributions
# (eg Google "computer jokes one liners").
# See the files in the jokes/ directory for some of the sources.
# To see the N'th joke, visit this page with the URL index.cgimp?joke=N
sub get_joke {
  # / or /index.cgimp is a random joke;
  # index.cgimp?joke=1 is the first joke; 
  # index.cgimp?joke=-1 is the last
  my @jokes = ( q{A balanced diet is chocolate in both hands.},
                q{Weeks of coding can save you hours of planning. -<i>Dave Newman</i>},
                q{Error: 132 - Windows not found: (C)heer (P)arty (D)ance},
		q{Pieces of seven! Pieces of seven! Grawk! (Parroty error)},
		q{Any sufficiently complicated C or Fortran program contains an ad-hoc,<br/> informally-specified bug-ridden slow implementation of half of Common Lisp.<br/><i>Philip Greenspun</i>},
		q{There's no place like},
		q{SELECT * FROM users WHERE clue >0.<br/>
                                    Uh oh, zero rows returned.},
		q{If TCP/IP handshaking was less formal,<br/>
		  		  perhaps SYN/ACK would be YO!/SUP!},
		q{/* No Comment */},
		q{How many people can read hex<br/>if only you and dead people can?<br/><i>A ThinkGeek T-shirt</i><br/>(57006)},
		q{Is the glass half empty, half full, or twice as large as it needs to be?},
		q{Never attribute to malice what can be adequately explained by stupidity.},
		q{No one expects the Spammish repetition! Spam, spam, spam, spam, spam, spam... },
		q{That's OK. I don't remember my name either.},
		q{The number you have dialed is imaginary.<br/>Please rotate your phone 90 degrees and try again.},
		q{Time flies like an arrow. Fruit flies like a banana.},
		q{Why didn't you bring that book I wanted to be read to out of up for?<br/>a.k.a. a preposition is a fine thing to end a sentence with)},
		q{When John Glenn returns to earth, everybody dress like apes.},
		q{Women who seek to be equal with men lack ambition.<br/> - <i>Timothy Leary</i>},
		q{-0.017641668 - the sine of the beast},
		q{29A - the hexadecimal of the beast},
		q{Abandon hope, all yet who press "ENTER" here.},
		q{All those who believe in psychokinesis, raise my hand. },
		q{American Non-Sequitur Society -- We don't make sense but we do like pizza!},
		q{Artificial intelligence is no match for natural stupidity.},
		q{As a computer, I find your faith in technology amusing.},
		q{Beware of geeks bearing grifts.},
		q{Does the noise in my head bother you?<br/> - <i>woman in "The Gods Must Be Crazy"</i>},
		q{No matter where you go, there you are.<br/> - <i>Buckaroo Banzai<i/>},
		q{I just became one with my browser software.<br/> - <i>Zippy the Pinhead</i>},
		q{Scientists abandon AI project after seing <i>The Matrix</i>.<br/> - <i>headline from <a href="http://www.theonion.com">the ONION</a>, Jan 21 2004</i>},
		q{You can only be young once.  But you can always be immature.<br /> - <i>Dave Barry</i>},
		q{Everything should be made as simple as possible, but not simpler.<br /> - <i>A. Einstein</i>},
		q{Nobody cares if you can't dance well.  Just get up and dance.<br /> - <i>Dave Barry</i>},
		q{I am not the only person who uses his computer mainly for the purpose of diddling with his computer.  <br /> - <i>Dave Barry</i>},
		q{Buying the right computer and getting it to work properly is no more complicated than building a nuclear reactor from wristwatch parts in a darkened room using only your teeth. <br /> - <i>Dave Barry</i>},
		q{Computer Science is no more about computers<br />than astronomy is about telescopes.<br /> - <i>Edsger Dijkstra</i>},
                q{Documentation is like sex -<br />when it's good, it's very good,<br />and when it's bad, it's still better than nothing.},
                q{Daddy, what does FORMATTING DRIVE C mean?},
                q{Plagiarism is the sincerest form of flattery. <br /> - <i>Anon</i>},
                q{Enter any 11-digit prime number to continue.},
                q{No keyboard present.<br />Hit F1 to continue.<br />Zen engineering?},
                q{The Tao that is seen<br />is not the true Tao, until<br />you bring fresh toner.},
                q{Computers are not intelligent.  They only think they are.},
                q{I haven't lost my mind.  It's backed up on tape somewhere.},
                q{Failure is not an option.  It comes bundled with the software.},
                q{It said "Insert disk 3."  But only two fit.},
                q{Math problems? Call 1-800-[(10x)(ln(0.1))]-[sin(xy)/2.362x] },
                q{Press any key...no, no, NOT THAT ONE!},
                q{...File not found. Should I fake it? (Y/N) },
                q{My sister opened a computer store in Hawaii. She sells C shells by the seashore.},
                q{To define recursion, we must first define recursion.},
                q{Emacs is a nice operating system, but I prefer UNIX. <br />  - <i>Tom Christiansen</i>},
                q{My computer NEVER cras},
                q{My Go  this  amn keyboar   oesn't have any  's.},
                q{Backups?  We don't *NEED* no steenking baX%^~,VbKx     NO CARRIER},
                q{The determined programmer can write a FORTRAN program in any language.},
                q{What do computerists use for birth control?  Their personalities.},
                q{AAAAAA - American Association Against Acronym Abuse Anonymous.},
                q{You have junk mail.},
                q{Asking whether machines can think is like asking whether submarines can swim. <br /> - <i>E.W. Dijkstra</i>},
                q{Ethernet (n): something used to catch the etherbunny.},
                q{Access denied - nah nah na nah nah...},
                q{Your password is pitifully obvious.},
                q{I suppose when it gets to that point, we shan't know how it does it. <br /> - <i>Turing</i>},
                q{Never underestimate the bandwidth of a station wagon full of tapes.  <br /> - <i>Jackson</i>},
                q{Base 8 is just like base 10, really .. if you're missing two fingers. <br /> - <i>Tom Lehrer</i>},
                q{The number of UNIX installations has grown to 10, with more expected.  (6/72)},
                q{#define QUESTION ((bb) || !(bb))  - <i>W. Shakespeare</i>},
                q{C:\DOS C:\DOS\RUN RUN\DOS\RUN},
                q{May the bugs of many programs find a home on your hard drive.},
                q{This message transmitted with 100% recycled electrons.},
                q{Email from a friend: "CanYouFixTheSpaceBarOnMyKeyboard?"},
                q{Nice computers don't go down.},
                q{Use the source, Luke.},
                q{Windows 95: n.<br />32 bit extensions and a graphical shell<br />for a 16 bit patch to an 8 bit operating system<br />originally coded for a 4 bit microprocessor<br />written by a 2 bit company that can't stand 1 bit of competition.},
                q{If a packet hits a pocket on a socket on a port,<br />And the bus is interrupted as a very last resort,<br />And the address of the memory makes your DVD abort,<br />Then the socket packet pocket has an error to report.},
                q{A life? Cool! Where can I download one of those?},
                q{Bad or missing mouse driver.  Spank the cat? [Y/N]?},
                q{Email returned to sender - insufficient voltage.},
 # perl -e"print pack('H*','5975702c206974277320415343494920656e636f64696e672e').$/"
                q{There are only 10 types of people in this world: <br /> those who understand binary, and those who don't.},
                q{When in doubt, use brute force. <br /> - <i>Ken Thompson</i>},
                q{The fastest algorithm can frequently be replaced <br /> by one that is almost as fast and much easier to understand. <br /> - <i>Douglas W. Jones</i>},
                q{Furious activity is no substitute for understanding. <br /> - <i>H.H.Williams</i>},
                q{Plagiarism is the sincerest form of flattery. <br /> - <i>Anon</i>},
                q[perl -e'while($.++<99){$_.=1;print$..$/if!/^1?$|^(11+?)\1+$/}' <br /> <i> - Abigail</i>],
                q[ruby -e'99.times{|_|/^_?$|^(__+?)\1+$/=~"_"*_ or p _}' <br /> <i> - Sam (eight strokes shorter then <a href="?joke=85">Abigail's</a> in ruby)</i>],
                q{Cogito cogito, ergo cogito sum.<br />(I think I think, therefore I think I am.) },
                q{<table><tr><td align='left'>Top 10 reasons to procrastinate:<br />1.<br /></td></tr></table>},
		q{If Bill Gates had a nickel for every time Windows crashed...<br /> Oh wait, he does.},
		q{More good code has been written in languages denounced as "bad"<br /> than in languages proclaimed "wonderful" -- much more.<br /> -- Bjarne Stroustrup, "The Design and Evolution of C++"},
                q{<code>double value;&nbsp;&nbsp;/* or your money back! */&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>short changed;&nbsp;/* so triple your money back! */</code><br/> -- Larry Wall in cons.c from the perl source code},
		q{Designing pages in HTML is like having sex in a bathtub.<br/> If you don't know anything about sex,<br/> it won't do you any good to know a lot about bathtubs.<br /> -- vagabond&#64mcgurkus.circus.com},
		q{<code>echo "Your stdio isn't very std."</code><br/> -- Larry Wall in Configure from the perl distribution},
		q{I have yet to see any problem, however complicated,<br/> which, when you looked at it in the right way,<br/> did not become still more complicated.<br/> -- Paul Anderson},
		q{Sentences long extremely and notation Polish reverse<br/>in writing about wrong is what? -- Jarkko Hietaniemi},
		q{The lyf so short, the craft so long to lerne.<br/> -- Geoffrey Chaucer},

              ); #);     # make the syntax checker happy.
  my $which = defined(param('joke')) ? param('joke') % scalar(@jokes) : rand(@jokes);
  return $jokes[$which];

sub get_next_joke_link { return '' }
# sub get_next_joke_link {
#   return '' unless defined(param('next'));
#   my $joke_number = defined(param('joke')) ? param('joke') : 0;
#   my $n_jokes = scalar(@jokes);
#   my $next_number = ($joke_number+1) % $how_many;
#   return qq(joke $joke_number of $n_jokes) . 
#          qq(<a href="?next=1&joke=$next_number">next</a><p>&nbsp;</p>);
# }

# ========================================================
sub SSL_logo_html {
    return q{<br/><small>ssl</small>}
    # return q{
    # <p /><a href="http://certs.ipsca.com/">
    #  <img border=0 src="/images/ipsCASecuredLogoSmallLock.gif" alt="ipsCS" />
    # </a>
    # }
# -- more detailed version with clickable cs.marlboro.edu verification link.
#    return q{
#<p />
#<a href="https://certs.ipsca.com/sslcheck/servidorseguro.asp?numeroserie=46:51:04:33:48:1D:9E:8C:7F:F2:CE:4E:18:5D:E5:9C:73:0F:15:48">
# <img border=0 src="/images/ipsCASecuredLogoSmallLock.gif">
#</a><br />
#<a href="http://certs.ipsca.com">http://certs.ipsca.com</a>
#    }

  else {
    return ''

# ========================================================
sub page_html {
  my ($joke, $next_joke_link, $lastmodified, $ipsCA_stuff) = @_;
  return <<"END_QUOTE";
<div style="min-width:600px">
<div style="position:absolute; left:510px; top:20px;"><a 
 ><img src="/images/mc-logo.gif" border="0" alt="Marlboro College" 
<div style="display:inline"><table width="100%">
<tr><td colspan="2">
   <a href="/"><img 
     alt="computer science @ marlboro" border="0" /></a>

            <li><b>Fall 2017</b> <br>
            <small>(Eric Scace is teaching two course while Jim is on sabbatical.)</small><br/>
		 <li>Introduction to Programming with Python</li>
		 <li>Web Development and the Development of the Web</li>

            <li><a href="/term/previous.html">Previous semesters</a></li>
            <li><a href="/term/next.html">Next semesters</a></li>
	    <li><small><a href="https://nook.marlboro.edu/public/academics/courses/2017/Fall/Computer%20Science">CS courses this term</a></small></li>
            <li><small><a href="http://www.marlboro.edu/academics/undergraduate/courses">
              All college courses </a></small></li>
        <form method="get" target="_other" 
          <li><a href="mailto:mahoney\@marlboro.edu"
                 >Jim&nbsp;Mahoney</a> | computer science faculty |
          <a href="courses/spring2017/jims_schedule.html">schedule</a> |
          <a href="http://www.marlboro.edu/academics/faculty/mahoney_jim">bio</a>
             <a href="/on-campus/people/students.html">students</a>
           | <a href="http://www.marlboro.edu/resources/directory/faculty">faculty</a>
           | <a href="http://www.marlboro.edu/resources/directory/staff">staff</a>
           | <a href="http://www.marlboro.edu/offices">offices</a>
           | <a href="/on-campus/people/lookup.cgi">search</a> : 
             <input type="text" name="users" value="" 
              size="12" maxlength="48" />

        <ul style="list-style-type:none">
          <a href="https://nook.marlboro.edu/public/academics/study/computer_science">About Computer Science @ Marlboro</a> |
              <a href="/home/studentwork.html">student work</a> |
              <a href="/courses/marlboro_wiki/tools">tools</a> |
              <a href="/courses/marlboro_wiki/rights">plagiarism</a>

           recent work: 
           <a href="http://pivotstep.org">pivotstep.org</a> (dance scripting) |
           <a href="/wikiacademia">wikiacademia</a> (course software)

           <a href="http://www.marlboro.edu/resources/handbook/">handbook</a> |
           <a href="http://www.marlboro.edu/resources/handbook/constitution"
              >constitution</a> | 
           <a href="http://www.marlboro.edu/resources/info/campus_forms/"
              >forms</a> |
           <a href="http://www.marlboro.edu/resources/calendars/">calendars</a> |
           <a href="http://www.marlboro.edu/resources/library/">library</a> | 
           <a href="http://cs.marlboro.edu/courses/sci202/home">Sci202</a>
           <!-- <a href="http://docs.marlboro.edu">docs.m'boro</a> |
           <a href="http://www.marlboro.edu/communities/staff/records">records</a> -->

             <a href="/on-campus/">on-campus</a> | 
  <!-- <a href="/on-campus/Arabic_English_News">Arabic/English News</a> | -->
  <!-- <a href="wiki">wiki</a> | -->
              <a href="http://courses.marlboro.edu">courses.m'boro</a> |
              <a href="/docs/">docs</a> | 
              <a href="/code/">code</a> |
  <!-- <a href="https://cs.marlboro.edu/green-river/">green-river</a> | -->
  <!-- <a href="http://bob.marlboro.edu/wiki08">MSIE '08</a> | -->
            <a href="/courses/marlboro_wiki/home">m'boro wiki</a> |
  <!--      <a href="/home/links.html">links</a> | -->
           <a href="http://nook.marlboro.edu">nook</a>

             wikipedia :
           <a href="http://en.wikipedia.org/wiki/Portal:Computer_science"
                >Computer_science</a> | 
           <a href="http://en.wikipedia.org/wiki/Portal:Information_technology"
               </small></li> -->

	   <a href="/tools/baseConvert.cgi">base convert</a> |
	   <a href="/calc/plan_calculator.html">plan calculator</a> |
	   <a href="https://www.overleaf.com/6872023nrphzqqswjxx#/23452448/">latex plan template</a>

<tr><td colspan="2" align="right">
   <font color="#660000" face="arial,helvetica"><small>
    $next_joke_link $joke 
<td colspan="2">
  <hr style="height:1px; border:0; margin:0; 
             color:darkgreen; background-color:darkgreen" />

  <form method="get" action="http://www.google.com/search" 
        name="goofoo" target="_blank">
   <a href="http://www.google.com/">
   <img border="0" align="middle" alt="Google" src="/images/google25.gif" />
   <input name="q" size="24" maxlength="800" value="" />
   <input style="border:0;margin:0;padding:0;" type="image" 
          src="/images/lucky.gif" name="btnI" value="I'm Feeling Lucky" />

<td align="right" valign="top">
  <small>$lastmodified<br />
  <a href="index.cgimp_html">source</a></small>

syntax highlighted by Perl::Tidy 20060719