Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
XKCD's StackSort Implemented in a Vim Regex (robertelder.org)
116 points by robertelder on March 18, 2016 | hide | past | favorite | 23 comments



Wow... that's actually pretty great


It doesn't seem particularly "random," every time I run it it searches the same list of SO threads.


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.


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


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

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...), 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.


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


CC0 falls back to a very permissive license in countries without a concept of the "public domain". It's like BSD 0-clause. My only concern with CC0 is that it makes explicit that patent grants are not given to anybody who gets the work.


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/


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

[1] https://blogs.msdn.microsoft.com/visualstudio/2014/02/17/int...


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.


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)


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.


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


What could possibly go wrong?


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.


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

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


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


Could do FizzBuzz this way too!


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


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')\")"


What error did you get?


This is hilarious.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: