Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created July 12, 2020 01:47
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 ayosec/7e40f7e4f2790a3890e57f50a5169cfb to your computer and use it in GitHub Desktop.
Save ayosec/7e40f7e4f2790a3890e57f50a5169cfb to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "erb"
require "etc"
if ARGV.empty?
puts "Usage: #$0 files... > output.html"
exit 1
end
Job = Struct.new(:file, :child)
MAX_JOBS = Etc.nprocessors
JOBS = []
puts <<~HEAD
<!DOCTYPE html>
<meta charset="utf-8">
HEAD
def wait_job(job)
puts "<h1><tt>#{ERB::Util.h job.file}</tt></h1>"
while data = job.child.read(1024)
print data
end
Process.waitpid(job.child.pid)
end
while file = ARGV.shift
while JOBS.size >= MAX_JOBS
wait_job(JOBS.shift)
end
child = IO.popen(%W(
pygmentize
-f html
-O nobackground,noclasses,linenos=inline
#{file}
))
JOBS << Job.new(file, child)
end
while job = JOBS.shift
wait_job(job)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment