Skip to content

Instantly share code, notes, and snippets.

@HumanEquivalentUnit
Created August 25, 2020 04:28
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 HumanEquivalentUnit/8d8d465319c8fd9cbbd99c5aa3e0befd to your computer and use it in GitHub Desktop.
Save HumanEquivalentUnit/8d8d465319c8fd9cbbd99c5aa3e0befd to your computer and use it in GitHub Desktop.
decode a TIO.run link in Dyalog APL / .Net
tioCode←{
⍝ decodes a TIO.run link such as
⍝ tioCode 'https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtExSMFYwf9W551LvZkgsioq4OZSg86lzwqHcFkor//wE'
⍝ load dfns workspace to use base64 decoder
_←{(⍎⍵ ⎕NS ⍬).⎕CY ⍵}'dfns'
⎕USING←'System' 'System.Net,System.dll'
hash←('^https://tio\.run/##'⎕R'')⍵ ⍝ remove web address parts of the link
hash←('/'@{⍵='_'})('+'@{⍵∊'@-'})WebUtility.UrlDecode⊂hash
zBytes←dfns.base64 hash
inflatedStream←⎕NEW IO.MemoryStream
deflateStream←⎕NEW IO.Compression.DeflateStream((⎕NEW IO.MemoryStream(⊂zBytes)) IO.Compression.CompressionMode.Decompress)
_←{deflateStream.CopyTo inflatedStream} dfns.do ⍬
bytes←inflatedStream.ToArray
↑{'UTF-8'⎕UCS⍵}¨255(≠⊆⊢)bytes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment