Monthly Archives: January 2010

Listing the contents on a web server without listing directories

I seem to require this snippet of code quite often.

This PHP code will list the contents of a web server’s directory. It will list only files, and not directories (so it’ll skip the parent directory link which shows up by default on most Apache Index files).

<?php
if ($handle = opendir('.')) {
	while (false !== ($file = readdir($handle))) {
		if ($file != "index.php" && strncmp($file, ".", 1) != 0) {
			echo "<li><a>" . $file . "</a></li>\n";
		}
	}
	closedir($handle);
}
?>
Advertisement

Putting a LaTeX header on top of your manuscript

If you’re like me, you’ll have a lot of draft versions of your documents that you print out, and then you lose track of which version is the latest one. Wouldn’t it be nice to have the date and time of your document on the top of each page?

Using LaTeX’s fancyhdr package, as well as the time package, it’s pretty easy to put in a header the date and time at which the document was generated at the top of every page. Use the code below at the top of your document.

Just make sure you comment out the appropriate lines (\pagestyle{fancy} and \thispagestyle{fancy} before you make a camera-ready version.

\usepackage{fancyhdr}
\usepackage{time}

%-------------------------------------------------------------------------
% take the % away on next line to produce the final camera-ready version
% Be sure to remove \thispagestyle{fancy} as well after the \maketitle.
%\pagestyle{empty}
\pagestyle{fancy}

\newcommand\myTime{\now}
\fancyhead{}
\fancyhead[CO, CE]{\texttt{-Manuscript Draft-}}
\fancyhead[RO, RE]{\texttt{\today, \myTime}}
\setlength{\headheight}{2\baselineskip}
\renewcommand{\headrulewidth}{0pt}
%-------------------------------------------------------------------------

\begin{document}
\title{My paper's title}
\author{Author's name}
\maketitle

% You need this here, or else the first page won't have a header.
\thispagestyle{fancy}

\begin{abstract}
Abstract goes here
\end{abstract}