Skip to content

Instantly share code, notes, and snippets.

@lxynox
Last active December 20, 2021 00:17
Show Gist options
  • Save lxynox/05850487e633c51fc863a9ff1bd022a3 to your computer and use it in GitHub Desktop.
Save lxynox/05850487e633c51fc863a9ff1bd022a3 to your computer and use it in GitHub Desktop.
Query ASCII Art version octocat using github api

How about an ascii art version Octocat?

This can simply be achieved by the github api(https://api.github.com/octocat?s={query_string_value}), replace the {query_string_value} with the words you want the octocat to say.

As the browser trims empty space for display, the pattern might not render properly, i found 2 ways to preview:

  1. web inspector

If using Chrome, open Chrome Dev Tool and inspect the HTML elements, it's wrapped in a pair of <pre></pre> tag.

  1. command prompt

using curl command line utility: curl -L https://api.github.com/octocat?s={query_string_value}

Result:


               MMM.           .MMM
               MMMMMMMMMMMMMMMMMMM
               MMMMMMMMMMMMMMMMMMM      ________________________
              MMMMMMMMMMMMMMMMMMMMM    |                        |
             MMMMMMMMMMMMMMMMMMMMMMM   |  [query_string_value]  |
            MMMMMMMMMMMMMMMMMMMMMMMM   |_   ____________________|
            MMMM::- -:::::::- -::MMMM    |/
             MM~:~ 00~:::::~ 00~:~MM
        .. MMMMM::.00:::+:::.00::MMMMM ..
              .MM::::: ._. :::::MM.
                 MMMM;:::::;MMMM
          -MM        MMMMMMM
          ^  M+     MMMMMMMMM
              MMMMMMM MM MM MM
                   MM MM MM MM
                   MM MM MM MM
                .~~MM~MM~MM~MM~~.
             ~~~~MM:~MM~~~MM~:MM~~~~
            ~~~~~~==~==~~~==~==~~~~~~
             ~~~~~~==~==~==~==~~~~~~
                 :~==~==~==~==~~

Extra note

Question:

How to parse query string in JavaScript?

Answer:

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=');
        if (decodeURIComponent(pair[0]) == variable) {
            return decodeURIComponent(pair[1]);
        }
    }
    console.log('Query variable %s not found', variable);
}

Now make a request to page.html?x=Hello: console.log(getQueryVariable('x'))

Source: http://www.idealog.us/2006/06/javascript_to_p.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment