Skip to content

Instantly share code, notes, and snippets.

@yoshinari-nomura
Created June 27, 2018 08:43
Show Gist options
  • Save yoshinari-nomura/b390a1bebca19b5bba1dbc4ae6dd804e to your computer and use it in GitHub Desktop.
Save yoshinari-nomura/b390a1bebca19b5bba1dbc4ae6dd804e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "./event.rb"
def filter(events, &block)
filtered = EventCollection.new
events.each do |ev|
filtered << ev if yield(ev)
end
return filtered
end
seen = {}
while json = gets
events = EventCollection.from_json(json.chomp)
filtered = filter(events) do |ev|
unseen = !seen[ev.to_s]
seen[ev.to_s] = true
unseen
end
puts filtered.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment