From anonymous, 5 Months ago, written in Ruby.
This paste will run down the curtain in 1 Second.
Embed
  1. #!/usr/bin/env ruby
  2. Signal.trap(:INT){ abort "\n(interrupted by SIGINT)" }
  3.  
  4. paste = ARGF.read
  5. $stdin = open "/dev/tty"
  6. puts "paste size: #{paste.size}"
  7. require_relative "../lib/paster"
  8. paster = Paster paste
  9.  
  10. require "tty-prompt"
  11. begin
  12.   services = {
  13.     "burn after reading": ["burn"],
  14.     "5 minutes": [5],
  15.     "1 hour": [60, 3600],
  16.     "1 day": [1440, 86400],
  17.     "3 days": [nil, 259200],
  18.     "1 week": [10080],
  19.     "1 month": [40320],
  20.     "3 months": [nil, 7776000],
  21.     "1 year": [483840],
  22.     "keep forever": [0, -1],
  23.   }.map{ |name, value|
  24.     paster = paster.dup
  25.     paster.expire = value
  26.     size = paster.services.size
  27.     size.zero? ?
  28.       [size, {name: "#{name}", value: paster, disabled: "(no pastebins)"}] :
  29.       [size, {name: "#{name} (#{size})", value: paster}]
  30.   }
  31.   abort "no pastebin for such size" if services.all?{ |__, _| _[:disabled] }   # TODO: better error message
  32.   # otherwise tty-prompt fails with an unhandled exception, lol
  33.   TTY::Prompt.new.select "expiration:", services.map(&:last),
  34.     default: services.max_by(&:first).last[:name],
  35.     filter: true, cycle: true, per_page: 100
  36. rescue TTY::Reader::InputInterrupt
  37.   abort ""  # we don't use TTY::Prompt.new(interrupt: :exit) because it does not finish the line
  38. end.paste
  39.