Skip to content

Instantly share code, notes, and snippets.

@jrun
Last active April 21, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrun/34460f8d0fcb105898359563335e533f to your computer and use it in GitHub Desktop.
Save jrun/34460f8d0fcb105898359563335e533f to your computer and use it in GitHub Desktop.
Quick and dirty script to merge asciicast files
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'pathname'
cast_files = ARGV.map { |cast| Pathname cast }
#
# Merge files
#
master_cast = cast_files.shift.readlines.map { |line| JSON.parse line }
cast_files.each do |cast|
last_time = Float master_cast.last.first
cast.readlines[1..-1].each do |line|
new_line = JSON.parse(line)
#
# Adjust time
#
new_line[0] = Float(new_line.first) + last_time
master_cast << new_line
end
end
puts master_cast.map { |line| JSON.dump line }.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment