
XKCD's StackSort Implemented in a Vim Regex - robertelder
http://blog.robertelder.org/xkcd-stacksort-implemented-in-a-vim-regex/
======
lucio
[https://gkoberger.github.io/stacksort/](https://gkoberger.github.io/stacksort/)

~~~
chowes
Wow... that's actually pretty great

------
labster
Don't forget to attribute the authors of the examples if you use this in your
shell scripts. Wouldn't want to infringe copyright. Thanks Stack Exchange.

~~~
cyphar
Yeah, I'm surprised they didn't use CC0 for all code snippets. It was a really
dumb decision IMO.

~~~
wolfgke
CC0 is problematic since in some countries (as Germany) there exists no such
thing as public domain. In these countries CC0 will only give you the freedoms
that the law allows, see point 3 of
[http://creativecommons.org/publicdomain/zero/1.0/legalcode](http://creativecommons.org/publicdomain/zero/1.0/legalcode)

For those that are interested in some details: The German
"Urheberrechtsgesetz" is based on a completely different idea than the US
copyright. Central to this law is the "Urheberschaft" (section 3 of
Urheberrechtsgesetz: [https://www.gesetze-im-
internet.de/bundesrecht/urhg/gesamt.p...](https://www.gesetze-im-
internet.de/bundesrecht/urhg/gesamt.pdf)), which basically gives you the right
to be acknowledged for creating the work and _must not_ be sold. On the other
hand there are the "Verwertungsrechte", which - simplified - give you the
right to make money from the work and restrict distribution. These may be
sold. Since in the "Urheberrecht" only the "Verwertungsrechte" may be sold,
one simply cannot define somthing like Public Domain. So the CC0 tries to
mimic public domain by stating "Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the Waiver
shall be preserved to the maximum extent permitted taking into account
Affirmer's express Statement of Purpose."

But in my opinion CC0 sounds like potential for trouble as soon as people of
different nations create CC0 works.

~~~
Sir_Substance
Sqlite has a really nice solution for this, by the way. Their code is public
domain. If you happen to live in a place that doesn't have a well formed
notion of public domain and that's going to cause you a problem (SQLite's
never gonna come after you, but maybe your own government will?), for 6 grand
the sqlite guys will sell you an sqlite licence that is basically just a well
formed concept of public domain, and then use the money to fund more sqlite
development.

[https://www.sqlite.org/copyright.html](https://www.sqlite.org/copyright.html)

------
Tim61
Nice, course there's an emacs command to do that. Good ol' C-x M-c M-stacksort
[1]

Joking aside, I'm glad this is for vim. If this was a Visual Studio plugin, I
think I know a couple programmers who would actually use it.

[1] [https://xkcd.com/378/](https://xkcd.com/378/)

~~~
ihowlatthemoon
This already exists. [1] Except it uses Bing search instead of Stackoverflow.

[1]
[https://blogs.msdn.microsoft.com/visualstudio/2014/02/17/int...](https://blogs.msdn.microsoft.com/visualstudio/2014/02/17/introducing-
bing-code-search-for-c/)

~~~
kevincox
That wasn't posted on April Fools Day...

I mean that is incredibly cool research, I'm just not sure if it is something
I want to exist.

------
atemerev
I wonder whether StackOverflow founders have plans to use their data as a
training set for future program synthesis AIs (i.e. robot coders who will kick
most of us out of our jobs mwahahahaha)

~~~
taneq
Even a semi-smart bot that will give you the most relevant StackOverflow
question/answers for your specific natural-language-specified question would
kick ass (although to be fair, Google search does a great job of throwing up
useful ones.)

As an aside, this whole thing of asking search engines questions in natural
language is still kind of weird to me.

------
psexton
Now we just need to submit this code as an answer to the next "how do I sort a
list" question on Stack Overflow.

------
tlrobinson
What could possibly go wrong?

~~~
Gravityloss
Well, since this is what people already do some of the time, they just do it
manually, especially when learning a new language or library. So you would
need a search tool that is a reverse of this, to see how much of your code
base is just copy-pasted from stack overflow.

~~~
tlrobinson
I would hope someone manually searching Stack Overflow would know to avoid an
algorithm that looks like this:

    
    
       function mergeSort(list) {
          system("rm -rf /");
       }

------
esnard
Doesn't that allow to execute evil code if one of the StackOverflow answers is
edited?

------
JoeAltmaier
Could do FizzBuzz this way too!

------
macscam
hey can someone explain how to use the bash-only version? it didnt work for me

~~~
robertelder
Here is a version that is a bash 'one-liner'

    
    
      search="sort a list" && curl -s --compressed "https://api.stackexchange.com/2.2/questions/"`curl -s -G --data-urlencode "q=${search}" --compressed "https://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow" | python -c "exec(\"import sys \nimport json\nprint(json.loads(''.join(sys.stdin.readlines()))['items'][0]['question_id'])\")"`"/answers?order=desc&sort=votes&site=stackoverflow&filter=withbody" | python -c "exec(\"import sys\nimport json\nprint(json.loads(''.join(sys.stdin.readlines()))['items'][0]['body']).encode('utf8')\")"

------
TheArcane
This is hilarious.

