Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TIO encoding
require 'zlib'
require 'base64'
FIELD_SEPARATOR = "\xff"
def deflate(str)
Zlib::Deflate.deflate(str,9)[2..-5]
end
def finalize(state_string)
compressed = deflate(state_string)
encoded = Base64.encode64 compressed
encoded.tr("+", "@").gsub(/=+/, "")
end
def tio_encode(program)
state_string = "attache#{FIELD_SEPARATOR * 2}#{program}#{FIELD_SEPARATOR * 2}"
url = finalize state_string
"tio.run/###{url}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment