Skip to content

Instantly share code, notes, and snippets.

@nogweii
Created January 8, 2009 20:08
Show Gist options
  • Save nogweii/44859 to your computer and use it in GitHub Desktop.
Save nogweii/44859 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Sample code to take a file formatted similarly to event.template and create an iCalendar VEVENT (using the Icalendar library)
require 'rubygems'
require 'icalendar'
require 'chronic'
require 'fileutils'
require 'lib/yaml'
require 'tempfile'
# Copy the template to a tmp file & have the user edit it
#tmp_file = File.join(ENV['TMP'] || ENV['TEMP'] || "/tmp", "ical.event.#{$$}")
#FileUtils.cp File.config_path('template'), tmp_file
tmp_file = Tempfile.open("pipcal")
tmp_file.print "#{File.readlines(File.config_path('template'))\n}"
tmp_file.fsync # Flush Ruby's buffer to disk
tmp_file.close
system("#{ENV['EDITOR'] || 'vim'} #{tmp_file}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment