Skip to content

Instantly share code, notes, and snippets.

@wteuber
Last active July 23, 2025 16:04
Show Gist options
  • Save wteuber/4a823867f69fcb521ab11f4e9d514589 to your computer and use it in GitHub Desktop.
Save wteuber/4a823867f69fcb521ab11f4e9d514589 to your computer and use it in GitHub Desktop.
# gem install icalendar
require 'icalendar'
# Open a file or pass a string to the parser
cal_file = File.open("/path/to/my_large_calendar.ics")
# Parser returns an array of calendars because a single file
# can have multiple calendars.
cals = Icalendar::Calendar.parse(cal_file)
cal = cals.first
event_slices = cal.events.each_slice(500).to_a
event_slices.each_with_index do |event_slice, idx|
cal.events.replace(event_slice)
File.open("events#{idx}.ics","w") {|f| f.write cal.to_ical}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment