Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Writeup for:
- https://github.com/binarygolf/BGGP/issues/151
- After a couple of false starts I decided to create an entry that would be cover both BGGP's (1) palindrome and (5) download past challenges.
- To get a code palindrome, I settled on writing a Shell script which mirrored code to the right side of a # comment character, ie:
- echo 1#1 ohce
- I chose Shell as it's a powerful language I'm familiar with and you could do a lot with few bytes, so felt there was lots of
- opportunity to keep the number of bytes low. I built on this idea, by having a Shell script which was simply:
- $@#@$
- If in a file, this would expand all arguments passed to it on each $@, where not in a comment. ie, if this content was in a 6.sh file, then you would get the following response:
- ./6-chrome.sh echo 1 2 3
- 1 2 3#@$
- (Notice that the 1 2 3 arguments are expanded where we have the $@ to the left of the comment character, but they're not expanded in the same way within the comment itself. This was crucial and usage explained towards the end, below).
- Now I could replace the "echo 1 2 3" to perhaps open Chrome and each argument I gave it would open as a tab with that value as the address bar value. However, I simply wanted to have 1 tab to show the number 6 plus download the content for challenge 5, so after a little crafting, came up with:
- ./6.sh google-chrome "data:text/html,6<script>setTimeout(window.location='https://t.ly/3jGrK',5000)</script>"
- This opens Chrome, with a single tab with the address bar value:
- data:text/html,6<script>setTimeout(window.location='https://t.ly/3jGrK',5000)</script>#@$
- Firstly, it has the "data" protocol and identifies the content type as "text/html", so now I can add my own HTML into this empty page. The first thing I added was 6, so the page would be an HTML page simply with the number 6. Next, I added a <script> tag to be able to inject JavaScript code into the HTML page and have it run. But I wanted to show 6 and then after a short pause show challenge 5's content, so a setTimeout of 5000ms was added.
- To get the content for challenge 5, I remember back to what I did for my challenge 5 entry - using the https://t.ly/3jGrK short URL, which resolves to https://www.w3.org/services/html2txt?url=https://binary.golf/5/5 - a W3C service which turns HTML into text and outputs it. This was a perfect way to recycle an old challenge entry!
- Now we had something that would show 6 for 5 seconds, then following that download the challenge 5 contents using the W3C service & output the contents.
- As for the #@$ part of the address bar value? This is ignored, as anything from a # character onwards in a URL is seen as a fragment and as there's no matching fragment in the HTML page we have, no action is taken and it also never appears in the webpage either.
- Hope you like the entry, all makes sense and thanks for reading. :)
Add Comment
Please, Sign In to add comment