Skip to content

Add baffling-birthdays#650

Merged
ryanplusplus merged 2 commits intomainfrom
baffling-birthdays
May 3, 2026
Merged

Add baffling-birthdays#650
ryanplusplus merged 2 commits intomainfrom
baffling-birthdays

Conversation

@ryanplusplus
Copy link
Copy Markdown
Member

I also extracted some commonly used helpers so that they can be reused across spec generators.

Comment thread bin/generate-spec
return s
end

package.loaded['utils'] = utils
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it so that they can be loaded via require 'utils' without creating a file to contain them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I might steal that for moonscript.

@ryanplusplus ryanplusplus force-pushed the baffling-birthdays branch from 9b164f2 to 8f6dc26 Compare May 3, 2026 15:02
Comment on lines +20 to +24
local start = os.time { year = non_leap_year, month = 1, day = 1, hour = 12 }
for i = 1, count do
local offset = math.random(0, 364)
local t = start + offset * seconds_per_day
table.insert(birthdates, os.date('%Y-%m-%d', t))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: os.time normalizes the month and day:

os.date('%c', os.time({year = 2005, month = 1, day = 365}))
-- Sat Dec 31 12:00:00 2005

Copy link
Copy Markdown
Member Author

@ryanplusplus ryanplusplus May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a great trick! Unfortunately, os.time is slow enough that the tests take 3x as long if I use this trick.

Comment thread bin/generate-spec
return s
end

package.loaded['utils'] = utils
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I might steal that for moonscript.

Comment thread bin/generate-spec Outdated
end

utils.stringify = function(x)
return ("'%s'"):format(x)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to test if x contains single quotes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. It turns out we already had a better stringify implementation in the word-count spec generator so I lifted that.

@ryanplusplus ryanplusplus merged commit b500815 into main May 3, 2026
5 checks passed
@ryanplusplus ryanplusplus deleted the baffling-birthdays branch May 3, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants