Thursday, June 29, 2017

parkie redux

There's some old line about "I'd rather spend hours writing a program to figure something out than ten minutes with a pen and paper"...

Anyway, a while ago I wrote about Parkie, a micro-webpage I made to calculate which side of the street I should park on.

Recently I updated it to cope with my new parking circumstance, with rules like "first and third Wednesday park on even side, second and fourth Thursday park on odd side".  (This is more complex than the rules in Boston which at least always did it on the same day of the week) as well as making it sort of customizable... if one person writes me that it would be useful for them, I'd make it so its config block

    restricts: [
        {dayOfWeek: 3, nth: 1, avoid: 'odd/our side', gofor: 'even/other side'},
        {dayOfWeek: 3, nth: 3, avoid: 'odd/our side', gofor: 'even/other side'},
        {dayOfWeek: 4, nth: 2, avoid: 'even/other side', gofor: 'odd/our side'},
        {dayOfWeek: 4, nth: 4, avoid: 'even/other side', gofor: 'odd/our side'}
was readable from the URL, as URLencoded JSON.  Until then I have to assume this will only be useful to me and my girlfriend so I won't bother.

The code is, admittedly, kind of nightmare of side effects and general poorly structured bullcrap. (Which is too bad, date calculations are kind of an awesome candidate for unit testing). The general question "which closest upcoming date (inclusive of today) matches a '1st/3rd Wed, 2nd/4th Thu' kind of rule?" is tricky! My approach was to take all the rules as outlined in "restricts", calculate which day of the month each represented for the current month, then walk forward from today to see which one matched first. (And being willing to jump to next month if need be...critical for the end of a month that ends on a Tuesday, say...)

So it's Vanilla.js. Besides using console.write(), kind of a forgotten way of constructing a page, The CSS used vviewport percentage widths for the character size, which got me nice, screen-filling (if a bit brutalist) results without fiddling with viewport stuff. (In this case the unit is 1/100 of the screenwidth, so 6 or 7vw would get a nice number of characters in per line.)

No comments:

Post a Comment