Blog

Article Tags

Halloween Countdown Script

By William Jeffrey Rankin, Fri June 28 2024

A little diversion: a Halloween countdown script written in PowerShell (and Rexx).

Usage and Sample Output

jeffr@Europa: ~/Halloween $ powershell ./halloween.ps1
There are only 125 days until Halloween! This year, it falls on a Thursday.

The Code

# halloween - Display the number of days until Halloween and the day on which it falls

# $Author: jeffr $
# $Date: 2024-11-01 10:34:32 -0400 (Fri, 01 Nov 2024) $
# $Revision: 9 $

$c_date = Get-Date -Format 'MM/dd/yyyy'
$c_year = ($c_date.Split('/'))[2]
$c_month = ($c_date.Split('/'))[0]
if ($c_month -ge 11) { $c_year = [int]$c_year + 1 }
$h_date = "10/31/$c_year"

$days   = (((New-TimeSpan -Start $c_date -End $h_date).ToString()).Split('.'))[0]
$day    = (Get-Date $h_date).DayOfWeek
$day_l = 'days'
$are_is = 'are'

if ($days -eq 1) {
    $day_l = 'day'
    $are_is = 'is'
}

if ($days -eq '00:00:00') {
    Write-Host 'TODAY is Halloween!'
} else {
    Write-Host "There $are_is only $days $day_l until Halloween! This year, it falls on a $day."
}

The Same in Rexx

/* halloween - Display the number of days until Halloween and the day on which it falls

$Author: jeffr $
$Date: 2024-11-02 08:20:36 -0400 (Sat, 02 Nov 2024) $
$Revision: 10 $
*/

c_date = DATE('B')
parse value DATE('N', c_date, 'B') with dom ' ' month ' ' year
if month = 'Nov' | month = 'Dec' then year = year + 1
h = '31 Oct' year
h_date = DATE('B', h)

days = h_date - c_date
day = DATE('W', h, 'N')
day_l = 'days'
are_is = 'are'

if days = 1 then do
    day_l = 'day'
    are_is = 'is'
end

if days = 0 then
    say 'TODAY is Halloween!'
else
    say 'There' are_is 'only' days day_l 'until Halloween! This year, it falls on a' day'.'

    Article Tags

    Hua Feature Completion

    By William Jeffrey Rankin, Sat Apr 6 2024

    With the inclusion of paging for tagged-with-* files (revision 140), Hua is now feature complete. There's still work to do: for example, I want to simplify some of the code and I'm very interested in how well Hua performs with a large number of articles. But, for now, the tool does everything I want it to do while retaining the flexibility and simplicity I envisioned from the beginning.

    Related Articles

        Article Tags

        Hua Paging Support

        By William Jeffrey Rankin, Tue Mar 26 2024

        Revision 99 of Hua supports paging. The number of entries appearing on the index page(s) is controlled using the entries_pp variable in the config file. Index file(s) are named using the index_file config variable, as before. Pages following the first are named *-2.html, *-3.html, etc.

        I'm considering implementing this for the tagged-with files as well.

        Related Articles

            Article Tags

            Hua Meta-information Support

            By William Jeffrey Rankin, Sun Feb 11 2024

            As of revision 63, released on Feb 10, 2024, Hua (my PowerShell-based static content generator) supports meta-information (description, keywords, and author) for individual articles. Meta information is maintained in a separate delimited file. Meta-info isn't required (but is certainly desirable) and Hua will provide defaults (the 000000 record in the meta database) if an individual article isn't represented in the file.

            Initially, I considered simply using article tags for keywords. But I believe keywords to be finer-grained than tags and should therefore be separated. There will be, no doubt, some common entries in both lists.

            Related Articles

                Article Tags

                Generating Running Statistics

                By William Jeffrey Rankin, Tue Jan 30 2024

                About

                For the past several years, I've been recording my running data in a simple spreadsheet. Previously, I'd used services like Dailymile (now long defunct) and Strava (which moved many of its features to the premium version). Wanting to do something useful with the data, I wrote a set of scripts to answer the following questions:

                • For a given month or year, what do my running stats look like? For example, total number of runs, distance, time, as well as average time per run, distance, pace, etc.
                • What does the distance profile look like for the period, i.e., how many short runs? medium-length runs? long runs?
                • Were there any notable events (e.g., poor weather, injury, etc.)
                • How many miles do I have on my current shoes?
                • What's my best time for a particular route?

                The data look like this:

                22-Jan-24,Rest day
                23-Jan-24,Run,River Road,32.38,Saucony Cohesion TR15,3,Icy!
                24-Jan-24,Run,River Road,58.53,Saucony Cohesion TR15,6
                25-Jan-24,Run,River Road,38.83,Saucony Cohesion TR15,4
                

                With fields consisting of:

                date, activity, route title, time, shoes, distance, notes
                

                The scripts were written in the Rexx programming language. Initially, I was only going to prototype using that language, but I was so pleased with some of its text formatting capabilities that I stuck with it.

                Usage & Sample Output

                The script produces a report that includes basic statistics, distance profile, and notes. In the example below, a report is generated for January 2024 based upon data in data.csv. To output data for the entire year, pass - rather than a three-letter month name.

                jeffr@CALLISTO: D:\Documents\wo-data $ regina .\rs.rex .\data.csv 24 Jan
                
                ----------------------------Running Statistics-----------------------------
                
                Total entries:  31
                Total runs:     22
                Total time:     14.33 hours
                Avg. time:      39.09 minutes
                Total distance: 87 miles
                Avg. distance:  3.95 miles
                Avg. pace:      9.89 minutes per mile
                Min. distance:  3 miles
                Max. distance:  6 miles
                
                -----------------------------Distance Profile------------------------------
                
                <3
                3 to <6  *****************19
                6 to <9  **3
                9 to <12
                12+
                
                -----------------------------------Notes-----------------------------------
                
                02-Jan-24: First run of 2024!
                06-Jan-24: Snow run.
                19-Jan-24: Snow run.
                23-Jan-24: Icy!
                

                eq.rex outputs the number of miles on a pair of shoes:

                jeffr@CALLISTO: D:\Documents\wo-data $ regina .\eq.rex .\data.csv saucony cohesion tr15
                
                saucony cohesion tr15: 75 miles
                

                bt.rex shows the best time for a given route (in this case, route is a combination of route title and distance):

                jeffr@CALLISTO: D:\Documents\wo-data $ regina .\bt.rex .\data.csv 6 River Road
                
                17-Oct-21, Time: 48.00, 8.00 minutes per mile
                

                gd.rex outputs planned runned data (an empty dataset) so you aren't required to key in a new month manually. Route title, shoes, and rest day are configurable.

                jeffr@CALLISTO: D:\Documents\wo-data $ regina .\gd.rex 24 Feb 29
                01-Feb-24,Run (planned),River Road,,Saucony Cohesion TR15,
                02-Feb-24,Run (planned),River Road,,Saucony Cohesion TR15,
                03-Feb-24,Run (planned),River Road,,Saucony Cohesion TR15,
                ...
                

                Download

                wo-data.zip, 18K

                Future Plans

                • Standard deviation for time period (may require moving the scripts to PowerShell or Python)
                • HTML/Markdown output

                Related Articles

                    Newer Articles Older Articles