Created
August 25, 2020 04:28
-
-
Save HumanEquivalentUnit/8d8d465319c8fd9cbbd99c5aa3e0befd to your computer and use it in GitHub Desktop.
decode a TIO.run link in Dyalog APL / .Net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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