Code I've written
Most of these are just me dinking around with date math. I started with C in the 90s, migrated to PERL in the 00s and am gradually switching to Python.
Most don't have comments since I was lazy. :)
CGI
- Run the Compound Interest Calculator or Download the code
- The ever-present environment checker: here.
- Show how many types of days; i.e. Sun, Mon, Tue; are between 2 dates: Number of Types or Download the code. The Calendar javascript came from OpenJS.
Perl
- Time Left - display a countdown clock, it requires month, day, hour and minute and takes an optional year
- Time Left - display a countdown clock but in a GUI window. Hardcoded time since I was using it to teach myself PERL TK for another project.
- XKCD Passwords - Inspired by the Password Strength XKCD comic. It should work on any Unix-like OS that has a dictionary installed.
- New Passwords - Generate a password based on a word in the dictionary and then change it to Leet Speak. It should work on any Unix-like OS that has a dictionary installed.
Python
- Time Left - display a countdown clock, it requires month, day, hour and minute and takes an optional year
- Add Days - Add days to today or another date
C
- Between tells you the number of work days, weekend days and total days between 2 dates.
- Time Left tells you how much time you have left in your day, it defaults to 4:30 pm since that was my shift at the time.
- Work Year tells you how many days of work, i.e. Monday - Friday, in the current year.
- Pay Days gives a listing of the pay day dates in a year. I used it to automate updating my calendar.
- Remember the rumor that shows up every few years that a month with 5 Fridays, 5 Saturdays and 5 Sundays or 5 Saturdays/Sundays/Mondays only happens every 800+ years? Five_Fss is code that show you months that it happens in the current year or a year that's passed in
Number formatting in the perl code came from the University of Winnipeg's CPAN repository .
The C code was written for GCC on Linux but I've compiled it using compilers on Solaris, AIX and HP-UX as well.
Stuart's Code by Stuart Jaskowiak is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
# First, lets get the URL so we can appropriately track it.
#$CounterFile="/hermes/bosweb/web066/b662/dot.sjaskowiak/public_html/data/index.dat";
#$CounterFile="/home/users/web/b662/dot.sjaskowiak/public_html/data/index.dat";
$CounterFile="/hermes/bosweb/web066/b662/dot.sjaskowiak/public_html/data/index.dat";
$ServerName = $_SERVER['SERVER_NAME'];
$DocumentURI = $_SERVER['PATH_TRANSLATED'];
$UniqueFileID = "$ServerName--$DocumentURI";
#print "
$UniqueFileID
";
# Then we'll make a unique hash...
$UniqueHash=bin2hex(md5($UniqueFileID));
#print "
$Unique_Hash
";
# now we'll lock the file.
$FilePointer=fopen($CounterFile,"r+");
flock($FilePointer,LOCK_EX);
# Now we'll read in the values in the counter file.
while ($FileCount = fscanf ($FilePointer, "%s\t%s\n"))
{
list($HashID,$Count)=$FileCount;
$CountHash[$HashID]=$Count;
}
# New we'll increment the number of accesses to the counter file.
$CountHash[$UniqueHash]=$CountHash[$UniqueHash]+1;
# now we'll rewind to the beginning of the file
rewind($FilePointer);
# now we'll go through each element of the hash and write it to the file.
# How? By dropping all the hashes into an array.
$CountKeys=array_keys($CountHash);
# The stepping through that array to write them to the file.
foreach($CountKeys as $TheKey)
{
fwrite($FilePointer,"$TheKey {$CountHash[$TheKey]}\n");
}
# now we unlock and close the file.
flock($FilePointer,LOCK_UN);
fclose($FilePointer);
# and print out the result.
#echo getcwd() . "\n";
print "
This page has been accessed {$CountHash[$UniqueHash]} times.
";
#
# Some other time we can do this with pretty graphic numbers, but I wanted to keep
# it simple for now.
?>