Skip to content

Instantly share code, notes, and snippets.

@harrisj
Created April 10, 2016 01:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisj/3d8b0158bc72dd34c36b996d8875790c to your computer and use it in GitHub Desktop.
Save harrisj/3d8b0158bc72dd34c36b996d8875790c to your computer and use it in GitHub Desktop.
My hackish Ruby script for hopping to a random NYT issue in the years 1851 - 1922 (ie, in the public domain)
#!/usr/bin/env ruby
years = (1851..1922).to_a
months = (1..12).to_a
def max_day_for_month(month, year)
case month
when 1, 3, 5, 7, 8, 10, 12
31
when 9, 4, 6, 11
30
when 2
(year % 4 == 0 && year % 100 != 0) ? 29 : 28
end
end
year = years.sample
month = months.sample
day = (1..max_day_for_month(month, year)).to_a.sample
url = "http://timesmachine.nytimes.com/timesmachine/#{year}/#{ "%02d" % month }/#{ "%02d" % day }/issue.html"
`open #{url}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment